@@ -526,10 +526,12 @@ export function getNamedType(
526
526
* Used while defining GraphQL types to allow for circular references in
527
527
* otherwise immutable type definitions.
528
528
*/
529
- export type ThunkArray < T > = ( ( ) => Array < T > ) | Array < T > ;
529
+ export type ThunkReadonlyArray < T > = ( ( ) => ReadonlyArray < T > ) | ReadonlyArray < T > ;
530
530
export type ThunkObjMap < T > = ( ( ) => ObjMap < T > ) | ObjMap < T > ;
531
531
532
- function resolveArrayThunk < T > ( thunk : ThunkArray < T > ) : Array < T > {
532
+ function resolveReadonlyArrayThunk < T > (
533
+ thunk : ThunkReadonlyArray < T > ,
534
+ ) : ReadonlyArray < T > {
533
535
return typeof thunk === 'function' ? thunk ( ) : thunk ;
534
536
}
535
537
@@ -748,7 +750,7 @@ export class GraphQLObjectType<TSource = any, TContext = any> {
748
750
extensionASTNodes : ReadonlyArray < ObjectTypeExtensionNode > ;
749
751
750
752
private _fields : ThunkObjMap < GraphQLField < TSource , TContext > > ;
751
- private _interfaces : ThunkArray < GraphQLInterfaceType > ;
753
+ private _interfaces : ThunkReadonlyArray < GraphQLInterfaceType > ;
752
754
753
755
constructor ( config : Readonly < GraphQLObjectTypeConfig < TSource , TContext > > ) {
754
756
this . name = config . name ;
@@ -775,7 +777,7 @@ export class GraphQLObjectType<TSource = any, TContext = any> {
775
777
return this . _fields ;
776
778
}
777
779
778
- getInterfaces ( ) : Array < GraphQLInterfaceType > {
780
+ getInterfaces ( ) : ReadonlyArray < GraphQLInterfaceType > {
779
781
if ( typeof this . _interfaces === 'function' ) {
780
782
this . _interfaces = this . _interfaces ( ) ;
781
783
}
@@ -812,8 +814,8 @@ function defineInterfaces(
812
814
config : Readonly <
813
815
GraphQLObjectTypeConfig < any , any > | GraphQLInterfaceTypeConfig < any , any >
814
816
> ,
815
- ) : Array < GraphQLInterfaceType > {
816
- const interfaces = resolveArrayThunk ( config . interfaces ?? [ ] ) ;
817
+ ) : ReadonlyArray < GraphQLInterfaceType > {
818
+ const interfaces = resolveReadonlyArrayThunk ( config . interfaces ?? [ ] ) ;
817
819
devAssert (
818
820
Array . isArray ( interfaces ) ,
819
821
`${ config . name } interfaces must be an Array or a function which returns an Array.` ,
@@ -920,7 +922,7 @@ export function argsToArgsConfig(
920
922
export interface GraphQLObjectTypeConfig < TSource , TContext > {
921
923
name : string ;
922
924
description ?: Maybe < string > ;
923
- interfaces ?: ThunkArray < GraphQLInterfaceType > ;
925
+ interfaces ?: ThunkReadonlyArray < GraphQLInterfaceType > ;
924
926
fields : ThunkObjMap < GraphQLFieldConfig < TSource , TContext > > ;
925
927
isTypeOf ?: Maybe < GraphQLIsTypeOfFn < TSource , TContext > > ;
926
928
extensions ?: Maybe < Readonly < GraphQLObjectTypeExtensions < TSource , TContext > > > ;
@@ -930,7 +932,7 @@ export interface GraphQLObjectTypeConfig<TSource, TContext> {
930
932
931
933
interface GraphQLObjectTypeNormalizedConfig < TSource , TContext >
932
934
extends GraphQLObjectTypeConfig < any , any > {
933
- interfaces : Array < GraphQLInterfaceType > ;
935
+ interfaces : ReadonlyArray < GraphQLInterfaceType > ;
934
936
fields : GraphQLFieldConfigMap < any , any > ;
935
937
extensions : Maybe < Readonly < GraphQLObjectTypeExtensions < TSource , TContext > > > ;
936
938
extensionASTNodes : ReadonlyArray < ObjectTypeExtensionNode > ;
@@ -1112,7 +1114,7 @@ export class GraphQLInterfaceType {
1112
1114
extensionASTNodes : ReadonlyArray < InterfaceTypeExtensionNode > ;
1113
1115
1114
1116
private _fields : ThunkObjMap < GraphQLField < any , any > > ;
1115
- private _interfaces : ThunkArray < GraphQLInterfaceType > ;
1117
+ private _interfaces : ThunkReadonlyArray < GraphQLInterfaceType > ;
1116
1118
1117
1119
constructor ( config : Readonly < GraphQLInterfaceTypeConfig < any , any > > ) {
1118
1120
this . name = config . name ;
@@ -1139,7 +1141,7 @@ export class GraphQLInterfaceType {
1139
1141
return this . _fields ;
1140
1142
}
1141
1143
1142
- getInterfaces ( ) : Array < GraphQLInterfaceType > {
1144
+ getInterfaces ( ) : ReadonlyArray < GraphQLInterfaceType > {
1143
1145
if ( typeof this . _interfaces === 'function' ) {
1144
1146
this . _interfaces = this . _interfaces ( ) ;
1145
1147
}
@@ -1175,7 +1177,7 @@ export class GraphQLInterfaceType {
1175
1177
export interface GraphQLInterfaceTypeConfig < TSource , TContext > {
1176
1178
name : string ;
1177
1179
description ?: Maybe < string > ;
1178
- interfaces ?: ThunkArray < GraphQLInterfaceType > ;
1180
+ interfaces ?: ThunkReadonlyArray < GraphQLInterfaceType > ;
1179
1181
fields : ThunkObjMap < GraphQLFieldConfig < TSource , TContext > > ;
1180
1182
/**
1181
1183
* Optionally provide a custom type resolver function. If one is not provided,
@@ -1190,7 +1192,7 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
1190
1192
1191
1193
export interface GraphQLInterfaceTypeNormalizedConfig
1192
1194
extends GraphQLInterfaceTypeConfig < any , any > {
1193
- interfaces : Array < GraphQLInterfaceType > ;
1195
+ interfaces : ReadonlyArray < GraphQLInterfaceType > ;
1194
1196
fields : GraphQLFieldConfigMap < any , any > ;
1195
1197
extensions : Maybe < Readonly < GraphQLInterfaceTypeExtensions > > ;
1196
1198
extensionASTNodes : ReadonlyArray < InterfaceTypeExtensionNode > ;
@@ -1240,7 +1242,7 @@ export class GraphQLUnionType {
1240
1242
astNode : Maybe < UnionTypeDefinitionNode > ;
1241
1243
extensionASTNodes : ReadonlyArray < UnionTypeExtensionNode > ;
1242
1244
1243
- private _types : ThunkArray < GraphQLObjectType > ;
1245
+ private _types : ThunkReadonlyArray < GraphQLObjectType > ;
1244
1246
1245
1247
constructor ( config : Readonly < GraphQLUnionTypeConfig < any , any > > ) {
1246
1248
this . name = config . name ;
@@ -1259,7 +1261,7 @@ export class GraphQLUnionType {
1259
1261
) ;
1260
1262
}
1261
1263
1262
- getTypes ( ) : Array < GraphQLObjectType > {
1264
+ getTypes ( ) : ReadonlyArray < GraphQLObjectType > {
1263
1265
if ( typeof this . _types === 'function' ) {
1264
1266
this . _types = this . _types ( ) ;
1265
1267
}
@@ -1293,8 +1295,8 @@ export class GraphQLUnionType {
1293
1295
1294
1296
function defineTypes (
1295
1297
config : Readonly < GraphQLUnionTypeConfig < unknown , unknown > > ,
1296
- ) : Array < GraphQLObjectType > {
1297
- const types = resolveArrayThunk ( config . types ) ;
1298
+ ) : ReadonlyArray < GraphQLObjectType > {
1299
+ const types = resolveReadonlyArrayThunk ( config . types ) ;
1298
1300
devAssert (
1299
1301
Array . isArray ( types ) ,
1300
1302
`Must provide Array of types or a function which returns such an array for Union ${ config . name } .` ,
@@ -1305,7 +1307,7 @@ function defineTypes(
1305
1307
export interface GraphQLUnionTypeConfig < TSource , TContext > {
1306
1308
name : string ;
1307
1309
description ?: Maybe < string > ;
1308
- types : ThunkArray < GraphQLObjectType > ;
1310
+ types : ThunkReadonlyArray < GraphQLObjectType > ;
1309
1311
/**
1310
1312
* Optionally provide a custom type resolver function. If one is not provided,
1311
1313
* the default implementation will call `isTypeOf` on each implementing
@@ -1319,7 +1321,7 @@ export interface GraphQLUnionTypeConfig<TSource, TContext> {
1319
1321
1320
1322
interface GraphQLUnionTypeNormalizedConfig
1321
1323
extends GraphQLUnionTypeConfig < any , any > {
1322
- types : Array < GraphQLObjectType > ;
1324
+ types : ReadonlyArray < GraphQLObjectType > ;
1323
1325
extensions : Maybe < Readonly < GraphQLUnionTypeExtensions > > ;
1324
1326
extensionASTNodes : ReadonlyArray < UnionTypeExtensionNode > ;
1325
1327
}
@@ -1365,8 +1367,8 @@ export class GraphQLEnumType /* <T> */ {
1365
1367
astNode : Maybe < EnumTypeDefinitionNode > ;
1366
1368
extensionASTNodes : ReadonlyArray < EnumTypeExtensionNode > ;
1367
1369
1368
- private _values : Array < GraphQLEnumValue /* <T> */ > ;
1369
- private _valueLookup : Map < any /* T */ , GraphQLEnumValue > ;
1370
+ private _values : ReadonlyArray < GraphQLEnumValue /* <T> */ > ;
1371
+ private _valueLookup : ReadonlyMap < any /* T */ , GraphQLEnumValue > ;
1370
1372
private _nameLookup : ObjMap < GraphQLEnumValue > ;
1371
1373
1372
1374
constructor ( config : Readonly < GraphQLEnumTypeConfig /* <T> */ > ) {
@@ -1385,7 +1387,7 @@ export class GraphQLEnumType /* <T> */ {
1385
1387
devAssert ( typeof config . name === 'string' , 'Must provide name.' ) ;
1386
1388
}
1387
1389
1388
- getValues ( ) : Array < GraphQLEnumValue /* <T> */ > {
1390
+ getValues ( ) : ReadonlyArray < GraphQLEnumValue /* <T> */ > {
1389
1391
return this . _values ;
1390
1392
}
1391
1393
@@ -1497,7 +1499,7 @@ function didYouMeanEnumValue(
1497
1499
function defineEnumValues (
1498
1500
typeName : string ,
1499
1501
valueMap : GraphQLEnumValueConfigMap /* <T> */ ,
1500
- ) : Array < GraphQLEnumValue /* <T> */ > {
1502
+ ) : ReadonlyArray < GraphQLEnumValue /* <T> */ > {
1501
1503
devAssert (
1502
1504
isPlainObj ( valueMap ) ,
1503
1505
`${ typeName } values must be an object with value names as keys.` ,
0 commit comments