From 3fbc1a1e3dc6d3103b8636b611cecd3a962264db Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sat, 23 Oct 2021 15:17:58 +0300 Subject: [PATCH] GraphQLField: relax default value of TArgs to `any` Fixes #2152 Fixes #2829 --- integrationTests/ts/basic-test.ts | 11 +++++++---- src/type/definition.ts | 20 ++++---------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/integrationTests/ts/basic-test.ts b/integrationTests/ts/basic-test.ts index 76b92a0c0a1..49fbbe33982 100644 --- a/integrationTests/ts/basic-test.ts +++ b/integrationTests/ts/basic-test.ts @@ -9,10 +9,13 @@ const queryType: GraphQLObjectType = new GraphQLObjectType({ sayHi: { type: GraphQLString, args: { - who: { type: GraphQLString }, + who: { + type: GraphQLString, + defaultValue: 'World', + }, }, - resolve(_root, args) { - return 'Hello ' + (args.who ?? 'World'); + resolve(_root: any, args: { who: string }) { + return 'Hello ' + args.who; }, }, }), @@ -23,7 +26,7 @@ const schema: GraphQLSchema = new GraphQLSchema({ query: queryType }); const result: ExecutionResult = graphqlSync({ schema, source: ` - query helloWho($who: String){ + query helloWho($who: String!){ test(who: $who) } `, diff --git a/src/type/definition.ts b/src/type/definition.ts index b7ca3ce36cf..ed658a8fc78 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -962,7 +962,7 @@ export type GraphQLIsTypeOfFn = ( export type GraphQLFieldResolver< TSource, TContext, - TArgs = { [argument: string]: any }, + TArgs = any, TResult = unknown, > = ( source: TSource, @@ -996,19 +996,11 @@ export interface GraphQLResolveInfo { * We've provided these template arguments because this is an open type and * you may find them useful. */ -export interface GraphQLFieldExtensions< - _TSource, - _TContext, - _TArgs = { [argName: string]: any }, -> { +export interface GraphQLFieldExtensions<_TSource, _TContext, _TArgs = any> { [attributeName: string]: unknown; } -export interface GraphQLFieldConfig< - TSource, - TContext, - TArgs = { [argument: string]: any }, -> { +export interface GraphQLFieldConfig { description?: Maybe; type: GraphQLOutputType; args?: GraphQLFieldConfigArgumentMap; @@ -1049,11 +1041,7 @@ export type GraphQLFieldConfigMap = ObjMap< GraphQLFieldConfig >; -export interface GraphQLField< - TSource, - TContext, - TArgs = { [argument: string]: any }, -> { +export interface GraphQLField { name: string; description: Maybe; type: GraphQLOutputType;