@@ -511,9 +511,14 @@ export function getNamedType(type) {
511
511
* Used while defining GraphQL types to allow for circular references in
512
512
* otherwise immutable type definitions.
513
513
*/
514
- export type Thunk < + T : ObjMap < any > | Array < any >> = ( ( ) => T ) | T ;
514
+ export type ThunkArray < T > = ( ( ) => Array < T > ) | Array < T > ;
515
+ export type ThunkObjMap < T > = ( ( ) => ObjMap < T > ) | ObjMap < T > ;
515
516
516
- function resolveThunk < + T : ObjMap < any > | Array < any >> ( thunk : Thunk < T > ) : T {
517
+ function resolveArrayThunk < T > (thunk: ThunkArray< T > ): Array< T > {
518
+ return typeof thunk === 'function' ? thunk ( ) : thunk ;
519
+ }
520
+
521
+ function resolveObjMapThunk< T > (thunk: ThunkObjMap< T > ): ObjMap< T > {
517
522
return typeof thunk === 'function' ? thunk ( ) : thunk ;
518
523
}
519
524
@@ -703,8 +708,8 @@ export class GraphQLObjectType {
703
708
astNode: ?ObjectTypeDefinitionNode;
704
709
extensionASTNodes: ?$ReadOnlyArray<ObjectTypeExtensionNode>;
705
710
706
- _fields : Thunk < GraphQLFieldMap < any , any > > ;
707
- _interfaces : Thunk < Array < GraphQLInterfaceType > > ;
711
+ _fields: ThunkObjMap<GraphQLField <any, any>>;
712
+ _interfaces: ThunkArray< GraphQLInterfaceType>;
708
713
709
714
constructor(config: $ReadOnly<GraphQLObjectTypeConfig<any, any>>) {
710
715
this.name = config.name;
@@ -771,7 +776,7 @@ function defineInterfaces(
771
776
| GraphQLInterfaceTypeConfig < mixed , mixed > ,
772
777
> ,
773
778
) : Array < GraphQLInterfaceType > {
774
- const interfaces = resolveThunk ( config . interfaces ?? [ ] ) ;
779
+ const interfaces = resolveArrayThunk ( config . interfaces ?? [ ] ) ;
775
780
devAssert (
776
781
Array . isArray ( interfaces ) ,
777
782
`${ config . name } interfaces must be an Array or a function which returns an Array.` ,
@@ -785,7 +790,7 @@ function defineFieldMap<TSource, TContext>(
785
790
| GraphQLInterfaceTypeConfig < TSource , TContext > ,
786
791
> ,
787
792
) : GraphQLFieldMap < TSource , TContext > {
788
- const fieldMap = resolveThunk ( config . fields ) ;
793
+ const fieldMap = resolveObjMapThunk ( config . fields ) ;
789
794
devAssert (
790
795
isPlainObj ( fieldMap ) ,
791
796
`${ config . name } fields must be an object with field names as keys or a function which returns such an object.` ,
@@ -874,8 +879,8 @@ export function argsToArgsConfig(
874
879
export type GraphQLObjectTypeConfig< TSource , TContext > = { |
875
880
name : string ,
876
881
description ?: ?string ,
877
- interfaces ?: Thunk < Array < GraphQLInterfaceType > >,
878
- fields : Thunk < GraphQLFieldConfigMap < TSource , TContext >> ,
882
+ interfaces ?: ThunkArray < GraphQLInterfaceType > ,
883
+ fields : ThunkObjMap < GraphQLFieldConfig < TSource , TContext >> ,
879
884
isTypeOf ?: ?GraphQLIsTypeOfFn < TSource , TContext > ,
880
885
extensions ?: ?ReadOnlyObjMapLike < mixed > ,
881
886
astNode ?: ?ObjectTypeDefinitionNode ,
@@ -1020,8 +1025,8 @@ export class GraphQLInterfaceType {
1020
1025
astNode : ?InterfaceTypeDefinitionNode ;
1021
1026
extensionASTNodes : ?$ReadOnlyArray < InterfaceTypeExtensionNode > ;
1022
1027
1023
- _fields : Thunk < GraphQLFieldMap < any , any > > ;
1024
- _interfaces : Thunk < Array < GraphQLInterfaceType > >;
1028
+ _fields : ThunkObjMap < GraphQLField < any , any > > ;
1029
+ _interfaces : ThunkArray < GraphQLInterfaceType > ;
1025
1030
1026
1031
constructor ( config : $ReadOnly < GraphQLInterfaceTypeConfig < any , any >> ) {
1027
1032
this. name = config . name ;
@@ -1085,8 +1090,8 @@ export class GraphQLInterfaceType {
1085
1090
export type GraphQLInterfaceTypeConfig < TSource , TContext > = { |
1086
1091
name : string ,
1087
1092
description ?: ?string ,
1088
- interfaces ?: Thunk < Array < GraphQLInterfaceType > >,
1089
- fields : Thunk < GraphQLFieldConfigMap < TSource , TContext> > ,
1093
+ interfaces ?: ThunkArray < GraphQLInterfaceType > ,
1094
+ fields : ThunkObjMap < GraphQLFieldConfig < TSource , TContext> > ,
1090
1095
/**
1091
1096
* Optionally provide a custom type resolver function. If one is not provided,
1092
1097
* the default implementation will call `isTypeOf` on each implementing
@@ -1137,7 +1142,7 @@ export class GraphQLUnionType {
1137
1142
astNode : ?UnionTypeDefinitionNode ;
1138
1143
extensionASTNodes : ?$ReadOnlyArray < UnionTypeExtensionNode > ;
1139
1144
1140
- _types : Thunk < Array < GraphQLObjectType > > ;
1145
+ _types : ThunkArray < GraphQLObjectType > ;
1141
1146
1142
1147
constructor ( config : $ReadOnly < GraphQLUnionTypeConfig < any , any >> ) {
1143
1148
this . name = config . name ;
@@ -1192,7 +1197,7 @@ export class GraphQLUnionType {
1192
1197
function defineTypes (
1193
1198
config : $ReadOnly < GraphQLUnionTypeConfig < mixed , mixed >> ,
1194
1199
) : Array < GraphQLObjectType > {
1195
- const types = resolveThunk ( config . types ) ;
1200
+ const types = resolveArrayThunk ( config . types ) ;
1196
1201
devAssert (
1197
1202
Array . isArray ( types ) ,
1198
1203
`Must provide Array of types or a function which returns such an array for Union ${ config . name } .` ,
@@ -1203,7 +1208,7 @@ function defineTypes(
1203
1208
export type GraphQLUnionTypeConfig < TSource , TContext > = { |
1204
1209
name : string ,
1205
1210
description ?: ?string ,
1206
- types : Thunk < Array < GraphQLObjectType > >,
1211
+ types : ThunkArray < GraphQLObjectType > ,
1207
1212
/**
1208
1213
* Optionally provide a custom type resolver function. If one is not provided,
1209
1214
* the default implementation will call `isTypeOf` on each implementing
@@ -1463,7 +1468,7 @@ export class GraphQLInputObjectType {
1463
1468
astNode : ?InputObjectTypeDefinitionNode ;
1464
1469
extensionASTNodes : ?$ReadOnlyArray < InputObjectTypeExtensionNode > ;
1465
1470
1466
- _fields : Thunk < GraphQLInputFieldMap > ;
1471
+ _fields : ThunkObjMap < GraphQLInputField > ;
1467
1472
1468
1473
constructor ( config : $ReadOnly < GraphQLInputObjectTypeConfig > ) {
1469
1474
this . name = config . name ;
@@ -1519,7 +1524,7 @@ export class GraphQLInputObjectType {
1519
1524
function defineInputFieldMap (
1520
1525
config : $ReadOnly < GraphQLInputObjectTypeConfig > ,
1521
1526
) : GraphQLInputFieldMap {
1522
- const fieldMap = resolveThunk ( config . fields ) ;
1527
+ const fieldMap = resolveObjMapThunk ( config . fields ) ;
1523
1528
devAssert (
1524
1529
isPlainObj ( fieldMap ) ,
1525
1530
`${ config . name } fields must be an object with field names as keys or a function which returns such an object.` ,
@@ -1545,7 +1550,7 @@ function defineInputFieldMap(
1545
1550
export type GraphQLInputObjectTypeConfig = { |
1546
1551
name : string ,
1547
1552
description ?: ?string ,
1548
- fields : Thunk < GraphQLInputFieldConfigMap > ,
1553
+ fields : ThunkObjMap < GraphQLInputFieldConfig > ,
1549
1554
extensions ?: ?ReadOnlyObjMapLike < mixed > ,
1550
1555
astNode ?: ?InputObjectTypeDefinitionNode ,
1551
1556
extensionASTNodes ?: ?$ReadOnlyArray < InputObjectTypeExtensionNode > ,
0 commit comments