Skip to content

Commit

Permalink
Change type of extensions from anonymous Record to named interfaces (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Jun 28, 2020
1 parent b489677 commit 7ee63b0
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 34 deletions.
43 changes: 42 additions & 1 deletion integrationTests/ts/index.ts
Expand Up @@ -2,17 +2,58 @@ import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
import { ExecutionResult } from 'graphql/execution';
import { graphqlSync } from 'graphql';

interface SomeExtension {
number: number;
string: string;
}

const example: SomeExtension = {
number: 42,
string: 'Meaning of life',
};

// FIXME: The following code block requires a version of TypeScript >= 3.2
/*
declare module 'graphql' {
interface GraphQLObjectTypeExtensions<TSource = any, TContext = any> {
someObjectExtension?: SomeExtension;
}
interface GraphQLFieldExtensions<
TSource,
TContext,
TArgs = { [argName: string]: any }
> {
someFieldExtension?: SomeExtension;
}
interface GraphQLArgumentExtensions {
someArgumentExtension?: SomeExtension;
}
}
*/

const queryType: GraphQLObjectType = new GraphQLObjectType({
name: 'Query',
fields: {
sayHi: {
type: GraphQLString,
args: {
who: { type: GraphQLString },
who: {
type: GraphQLString,
extensions: {
someArgumentExtension: example,
},
},
},
resolve: (_root, args) => 'Hello ' + (args.who || 'World'),
extensions: {
someFieldExtension: example,
},
},
},
extensions: {
someObjectExtension: example,
},
});

const schema: GraphQLSchema = new GraphQLSchema({
Expand Down
12 changes: 12 additions & 0 deletions src/index.d.ts
Expand Up @@ -139,32 +139,44 @@ export {
GraphQLNamedType,
Thunk,
GraphQLSchemaConfig,
GraphQLSchemaExtensions,
GraphQLDirectiveConfig,
GraphQLDirectiveExtensions,
GraphQLArgument,
GraphQLArgumentConfig,
GraphQLArgumentExtensions,
GraphQLEnumTypeConfig,
GraphQLEnumTypeExtensions,
GraphQLEnumValue,
GraphQLEnumValueConfig,
GraphQLEnumValueExtensions,
GraphQLEnumValueConfigMap,
GraphQLField,
GraphQLFieldConfig,
GraphQLFieldExtensions,
GraphQLFieldConfigArgumentMap,
GraphQLFieldConfigMap,
GraphQLFieldMap,
GraphQLFieldResolver,
GraphQLInputField,
GraphQLInputFieldConfig,
GraphQLInputFieldExtensions,
GraphQLInputFieldConfigMap,
GraphQLInputFieldMap,
GraphQLInputObjectTypeConfig,
GraphQLInputObjectTypeExtensions,
GraphQLInterfaceTypeConfig,
GraphQLInterfaceTypeExtensions,
GraphQLIsTypeOfFn,
GraphQLObjectTypeConfig,
GraphQLObjectTypeExtensions,
GraphQLResolveInfo,
ResponsePath,
GraphQLScalarTypeConfig,
GraphQLScalarTypeExtensions,
GraphQLTypeResolver,
GraphQLUnionTypeConfig,
GraphQLUnionTypeExtensions,
GraphQLScalarSerializer,
GraphQLScalarValueParser,
GraphQLScalarLiteralParser,
Expand Down

0 comments on commit 7ee63b0

Please sign in to comment.