Skip to content

Commit

Permalink
Restrict Thunks to support only ObjMap and Array (#2952)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 11, 2021
1 parent 3869211 commit fe5f91e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions integrationTests/ts/index.ts
Expand Up @@ -31,7 +31,7 @@ declare module 'graphql' {

const queryType: GraphQLObjectType = new GraphQLObjectType({
name: 'Query',
fields: {
fields: () => ({
sayHi: {
type: GraphQLString,
args: {
Expand All @@ -47,7 +47,7 @@ const queryType: GraphQLObjectType = new GraphQLObjectType({
someFieldExtension: example,
},
},
},
}),
extensions: {
someObjectExtension: example,
},
Expand Down
4 changes: 3 additions & 1 deletion src/type/definition.d.ts
Expand Up @@ -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) | T;
export type Thunk<T extends { [key: string]: any } | Array<any>> =
| (() => T)
| T;

/**
* Custom extensions
Expand Down
5 changes: 2 additions & 3 deletions src/type/definition.js
Expand Up @@ -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<any> | Array<any>> = (() => T) | T;

function resolveThunk<+T>(thunk: Thunk<T>): T {
// $FlowFixMe[incompatible-use]
function resolveThunk<+T: ObjMap<any> | Array<any>>(thunk: Thunk<T>): T {
return typeof thunk === 'function' ? thunk() : thunk;
}

Expand Down

0 comments on commit fe5f91e

Please sign in to comment.