Skip to content

Commit 20d4f8d

Browse files
committed
Add extensions to typescript integration test
1 parent 2dbc5ca commit 20d4f8d

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
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+
// The following code block requires a newer version of TypeScript
16+
/*! >=3.2
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({

0 commit comments

Comments
 (0)