Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change type of extensions from anonymous Record to named interfaces #2465

Merged
merged 16 commits into from Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
};

// The following code block requires a newer 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;
}
}
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how best to selectively enable this for TypeScript 3.2 and above only.

Further, the types themselves are not concretely tested, pointing to an example in the GraphQL source where this takes place would be helpful.


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