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

Restrict Thunks to support only ObjMap and Array #2952

Merged
merged 1 commit into from Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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