Skip to content

Commit f33ba9d

Browse files
JoviDeCroockn1ru4l
andcommitted
Support symbol properties on extension objects
Co-Authored-By: n1ru4l <[email protected]>
1 parent 0254e5f commit f33ba9d

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

src/jsutils/ObjMap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export interface ObjMap<T> {
2-
[key: string]: T;
2+
[key: string | symbol]: T;
33
}
44

5-
export type ObjMapLike<T> = ObjMap<T> | { [key: string]: T };
5+
export type ObjMapLike<T> = ObjMap<T> | { [key: string | symbol]: T };
66

77
export interface ReadOnlyObjMap<T> {
8-
readonly [key: string]: T;
8+
readonly [key: string | symbol]: T;
99
}
1010

1111
export type ReadOnlyObjMapLike<T> =
1212
| ReadOnlyObjMap<T>
13-
| { readonly [key: string]: T };
13+
| { readonly [key: string | symbol]: T };

src/jsutils/toObjMap.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ export function toObjMap<T>(
1616
for (const [key, value] of Object.entries(obj)) {
1717
map[key] = value;
1818
}
19+
20+
for (const key of Object.getOwnPropertySymbols(obj)) {
21+
map[key] = obj[key];
22+
}
23+
1924
return map;
2025
}

src/type/__tests__/definition-test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ describe('Type System: Scalars', () => {
8686
expect(someScalar.toConfig()).to.deep.equal(someScalarConfig);
8787
});
8888

89+
it('supports symbol extensions', () => {
90+
const test = Symbol.for('test');
91+
const someScalarConfig: GraphQLScalarTypeConfig<unknown, unknown> = {
92+
name: 'SomeScalar',
93+
description: 'SomeScalar description.',
94+
specifiedByURL: 'https://example.com/foo_spec',
95+
serialize: passThroughFunc,
96+
parseValue: passThroughFunc,
97+
parseLiteral: passThroughFunc,
98+
coerceInputLiteral: passThroughFunc,
99+
valueToLiteral: passThroughFunc,
100+
extensions: { [test]: 'extension' },
101+
astNode: dummyAny,
102+
extensionASTNodes: [dummyAny],
103+
};
104+
const someScalar = new GraphQLScalarType(someScalarConfig);
105+
expect(someScalar.toConfig()).to.deep.equal(someScalarConfig);
106+
});
107+
89108
it('provides default methods if omitted', () => {
90109
const scalar = new GraphQLScalarType({ name: 'Foo' });
91110

src/type/definition.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export function resolveObjMapThunk<T>(thunk: ThunkObjMap<T>): ObjMap<T> {
511511
* an object which can contain all the values you need.
512512
*/
513513
export interface GraphQLScalarTypeExtensions {
514-
[attributeName: string]: unknown;
514+
[attributeName: string | symbol]: unknown;
515515
}
516516

517517
/**
@@ -725,7 +725,7 @@ interface GraphQLScalarTypeNormalizedConfig<TInternal, TExternal>
725725
* you may find them useful.
726726
*/
727727
export interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
728-
[attributeName: string]: unknown;
728+
[attributeName: string | symbol]: unknown;
729729
}
730730

731731
/**
@@ -980,7 +980,7 @@ export interface GraphQLResolveInfo {
980980
* you may find them useful.
981981
*/
982982
export interface GraphQLFieldExtensions<_TSource, _TContext, _TArgs = any> {
983-
[attributeName: string]: unknown;
983+
[attributeName: string | symbol]: unknown;
984984
}
985985

986986
export interface GraphQLFieldConfig<TSource, TContext, TArgs = any> {
@@ -1008,7 +1008,7 @@ export type GraphQLFieldConfigArgumentMap = ObjMap<GraphQLArgumentConfig>;
10081008
* an object which can contain all the values you need.
10091009
*/
10101010
export interface GraphQLArgumentExtensions {
1011-
[attributeName: string]: unknown;
1011+
[attributeName: string | symbol]: unknown;
10121012
}
10131013

10141014
export interface GraphQLArgumentConfig {
@@ -1085,7 +1085,7 @@ export function defineDefaultValue(
10851085
* an object which can contain all the values you need.
10861086
*/
10871087
export interface GraphQLInterfaceTypeExtensions {
1088-
[attributeName: string]: unknown;
1088+
[attributeName: string | symbol]: unknown;
10891089
}
10901090

10911091
/**
@@ -1206,7 +1206,7 @@ interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
12061206
* an object which can contain all the values you need.
12071207
*/
12081208
export interface GraphQLUnionTypeExtensions {
1209-
[attributeName: string]: unknown;
1209+
[attributeName: string | symbol]: unknown;
12101210
}
12111211

12121212
/**
@@ -1324,7 +1324,7 @@ interface GraphQLUnionTypeNormalizedConfig
13241324
* an object which can contain all the values you need.
13251325
*/
13261326
export interface GraphQLEnumTypeExtensions {
1327-
[attributeName: string]: unknown;
1327+
[attributeName: string | symbol]: unknown;
13281328
}
13291329

13301330
function enumValuesFromConfig(values: GraphQLEnumValueConfigMap) {
@@ -1559,7 +1559,7 @@ export type GraphQLEnumValueConfigMap /* <T> */ =
15591559
* an object which can contain all the values you need.
15601560
*/
15611561
export interface GraphQLEnumValueExtensions {
1562-
[attributeName: string]: unknown;
1562+
[attributeName: string | symbol]: unknown;
15631563
}
15641564

15651565
export interface GraphQLEnumValueConfig {
@@ -1589,7 +1589,7 @@ export interface GraphQLEnumValue {
15891589
* an object which can contain all the values you need.
15901590
*/
15911591
export interface GraphQLInputObjectTypeExtensions {
1592-
[attributeName: string]: unknown;
1592+
[attributeName: string | symbol]: unknown;
15931593
}
15941594

15951595
/**
@@ -1718,7 +1718,7 @@ interface GraphQLInputObjectTypeNormalizedConfig
17181718
* an object which can contain all the values you need.
17191719
*/
17201720
export interface GraphQLInputFieldExtensions {
1721-
[attributeName: string]: unknown;
1721+
[attributeName: string | symbol]: unknown;
17221722
}
17231723

17241724
export interface GraphQLInputFieldConfig {

src/type/directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function assertDirective(directive: unknown): GraphQLDirective {
4444
* an object which can contain all the values you need.
4545
*/
4646
export interface GraphQLDirectiveExtensions {
47-
[attributeName: string]: unknown;
47+
[attributeName: string | symbol]: unknown;
4848
}
4949

5050
/**

src/type/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function assertSchema(schema: unknown): GraphQLSchema {
6161
* an object which can contain all the values you need.
6262
*/
6363
export interface GraphQLSchemaExtensions {
64-
[attributeName: string]: unknown;
64+
[attributeName: string | symbol]: unknown;
6565
}
6666

6767
/**

0 commit comments

Comments
 (0)