Skip to content

Commit fe5f91e

Browse files
Restrict Thunks to support only ObjMap and Array (#2952)
1 parent 3869211 commit fe5f91e

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

integrationTests/ts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare module 'graphql' {
3131

3232
const queryType: GraphQLObjectType = new GraphQLObjectType({
3333
name: 'Query',
34-
fields: {
34+
fields: () => ({
3535
sayHi: {
3636
type: GraphQLString,
3737
args: {
@@ -47,7 +47,7 @@ const queryType: GraphQLObjectType = new GraphQLObjectType({
4747
someFieldExtension: example,
4848
},
4949
},
50-
},
50+
}),
5151
extensions: {
5252
someObjectExtension: example,
5353
},

src/type/definition.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType;
263263
* Used while defining GraphQL types to allow for circular references in
264264
* otherwise immutable type definitions.
265265
*/
266-
export type Thunk<T> = (() => T) | T;
266+
export type Thunk<T extends { [key: string]: any } | Array<any>> =
267+
| (() => T)
268+
| T;
267269

268270
/**
269271
* Custom extensions

src/type/definition.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,9 @@ export function getNamedType(type) {
511511
* Used while defining GraphQL types to allow for circular references in
512512
* otherwise immutable type definitions.
513513
*/
514-
export type Thunk<+T> = (() => T) | T;
514+
export type Thunk<+T: ObjMap<any> | Array<any>> = (() => T) | T;
515515

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

0 commit comments

Comments
 (0)