From 259decb4dbbdf62890225466cdcae54d6fcaf139 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 10 Mar 2021 18:39:54 +0200 Subject: [PATCH] Restrict Thunks to support only ObjMap and Array --- integrationTests/ts/index.ts | 4 ++-- src/type/definition.d.ts | 4 +++- src/type/definition.js | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/integrationTests/ts/index.ts b/integrationTests/ts/index.ts index 23402f543a..f746614c8b 100644 --- a/integrationTests/ts/index.ts +++ b/integrationTests/ts/index.ts @@ -31,7 +31,7 @@ declare module 'graphql' { const queryType: GraphQLObjectType = new GraphQLObjectType({ name: 'Query', - fields: { + fields: () => ({ sayHi: { type: GraphQLString, args: { @@ -47,7 +47,7 @@ const queryType: GraphQLObjectType = new GraphQLObjectType({ someFieldExtension: example, }, }, - }, + }), extensions: { someObjectExtension: example, }, diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index decfda65a1..69150e727f 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -263,7 +263,9 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; * Used while defining GraphQL types to allow for circular references in * otherwise immutable type definitions. */ -export type Thunk = (() => T) | T; +export type Thunk> = + | (() => T) + | T; /** * Custom extensions diff --git a/src/type/definition.js b/src/type/definition.js index 347b1dca14..ed24c7f57a 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -511,10 +511,9 @@ export function getNamedType(type) { * Used while defining GraphQL types to allow for circular references in * otherwise immutable type definitions. */ -export type Thunk<+T> = (() => T) | T; +export type Thunk<+T: ObjMap | Array> = (() => T) | T; -function resolveThunk<+T>(thunk: Thunk): T { - // $FlowFixMe[incompatible-use] +function resolveThunk<+T: ObjMap | Array>(thunk: Thunk): T { return typeof thunk === 'function' ? thunk() : thunk; }