Skip to content

Commit 7ee63b0

Browse files
authored
Change type of extensions from anonymous Record to named interfaces (#2465)
1 parent b489677 commit 7ee63b0

File tree

6 files changed

+268
-34
lines changed

6 files changed

+268
-34
lines changed

integrationTests/ts/index.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,58 @@ import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
22
import { ExecutionResult } from 'graphql/execution';
33
import { graphqlSync } from 'graphql';
44

5+
interface SomeExtension {
6+
number: number;
7+
string: string;
8+
}
9+
10+
const example: SomeExtension = {
11+
number: 42,
12+
string: 'Meaning of life',
13+
};
14+
15+
// FIXME: The following code block requires a version of TypeScript >= 3.2
16+
/*
17+
18+
declare module 'graphql' {
19+
interface GraphQLObjectTypeExtensions<TSource = any, TContext = any> {
20+
someObjectExtension?: SomeExtension;
21+
}
22+
interface GraphQLFieldExtensions<
23+
TSource,
24+
TContext,
25+
TArgs = { [argName: string]: any }
26+
> {
27+
someFieldExtension?: SomeExtension;
28+
}
29+
interface GraphQLArgumentExtensions {
30+
someArgumentExtension?: SomeExtension;
31+
}
32+
}
33+
*/
34+
535
const queryType: GraphQLObjectType = new GraphQLObjectType({
636
name: 'Query',
737
fields: {
838
sayHi: {
939
type: GraphQLString,
1040
args: {
11-
who: { type: GraphQLString },
41+
who: {
42+
type: GraphQLString,
43+
extensions: {
44+
someArgumentExtension: example,
45+
},
46+
},
1247
},
1348
resolve: (_root, args) => 'Hello ' + (args.who || 'World'),
49+
extensions: {
50+
someFieldExtension: example,
51+
},
1452
},
1553
},
54+
extensions: {
55+
someObjectExtension: example,
56+
},
1657
});
1758

1859
const schema: GraphQLSchema = new GraphQLSchema({

src/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,44 @@ export {
139139
GraphQLNamedType,
140140
Thunk,
141141
GraphQLSchemaConfig,
142+
GraphQLSchemaExtensions,
142143
GraphQLDirectiveConfig,
144+
GraphQLDirectiveExtensions,
143145
GraphQLArgument,
144146
GraphQLArgumentConfig,
147+
GraphQLArgumentExtensions,
145148
GraphQLEnumTypeConfig,
149+
GraphQLEnumTypeExtensions,
146150
GraphQLEnumValue,
147151
GraphQLEnumValueConfig,
152+
GraphQLEnumValueExtensions,
148153
GraphQLEnumValueConfigMap,
149154
GraphQLField,
150155
GraphQLFieldConfig,
156+
GraphQLFieldExtensions,
151157
GraphQLFieldConfigArgumentMap,
152158
GraphQLFieldConfigMap,
153159
GraphQLFieldMap,
154160
GraphQLFieldResolver,
155161
GraphQLInputField,
156162
GraphQLInputFieldConfig,
163+
GraphQLInputFieldExtensions,
157164
GraphQLInputFieldConfigMap,
158165
GraphQLInputFieldMap,
159166
GraphQLInputObjectTypeConfig,
167+
GraphQLInputObjectTypeExtensions,
160168
GraphQLInterfaceTypeConfig,
169+
GraphQLInterfaceTypeExtensions,
161170
GraphQLIsTypeOfFn,
162171
GraphQLObjectTypeConfig,
172+
GraphQLObjectTypeExtensions,
163173
GraphQLResolveInfo,
164174
ResponsePath,
165175
GraphQLScalarTypeConfig,
176+
GraphQLScalarTypeExtensions,
166177
GraphQLTypeResolver,
167178
GraphQLUnionTypeConfig,
179+
GraphQLUnionTypeExtensions,
168180
GraphQLScalarSerializer,
169181
GraphQLScalarValueParser,
170182
GraphQLScalarLiteralParser,

0 commit comments

Comments
 (0)