Skip to content

Commit 0740bef

Browse files
committed
wrapList memoises
1 parent 778f2bb commit 0740bef

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/type/definition.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export class GraphQLScalarType {
309309
astNode: ?ScalarTypeDefinitionNode;
310310

311311
_scalarConfig: GraphQLScalarTypeConfig<*, *>;
312+
_wrappedList: ?GraphQLList<*>;
312313

313314
constructor(config: GraphQLScalarTypeConfig<*, *>): void {
314315
assertValidName(config.name);
@@ -367,7 +368,7 @@ export class GraphQLScalarType {
367368
}
368369

369370
wrapList(): GraphQLList<*> {
370-
return new GraphQLList(this);
371+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
371372
}
372373

373374
toJSON: () => string;
@@ -437,6 +438,7 @@ export class GraphQLObjectType {
437438
_typeConfig: GraphQLObjectTypeConfig<*, *>;
438439
_fields: GraphQLFieldMap<*, *>;
439440
_interfaces: Array<GraphQLInterfaceType>;
441+
_wrappedList: ?GraphQLList<*>;
440442

441443
constructor(config: GraphQLObjectTypeConfig<*, *>): void {
442444
assertValidName(config.name, config.isIntrospection);
@@ -471,7 +473,7 @@ export class GraphQLObjectType {
471473
}
472474

473475
wrapList(): GraphQLList<*> {
474-
return new GraphQLList(this);
476+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
475477
}
476478

477479
toJSON: () => string;
@@ -726,6 +728,7 @@ export class GraphQLInterfaceType {
726728

727729
_typeConfig: GraphQLInterfaceTypeConfig<*, *>;
728730
_fields: GraphQLFieldMap<*, *>;
731+
_wrappedList: ?GraphQLList<*>;
729732

730733
constructor(config: GraphQLInterfaceTypeConfig<*, *>): void {
731734
assertValidName(config.name);
@@ -752,7 +755,7 @@ export class GraphQLInterfaceType {
752755
}
753756

754757
wrapList(): GraphQLList<*> {
755-
return new GraphQLList(this);
758+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
756759
}
757760

758761
toJSON: () => string;
@@ -810,6 +813,7 @@ export class GraphQLUnionType {
810813

811814
_typeConfig: GraphQLUnionTypeConfig<*, *>;
812815
_types: Array<GraphQLObjectType>;
816+
_wrappedList: ?GraphQLList<*>;
813817

814818
constructor(config: GraphQLUnionTypeConfig<*, *>): void {
815819
assertValidName(config.name);
@@ -837,7 +841,7 @@ export class GraphQLUnionType {
837841
}
838842

839843
wrapList(): GraphQLList<*> {
840-
return new GraphQLList(this);
844+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
841845
}
842846

843847
toJSON: () => string;
@@ -931,6 +935,7 @@ export class GraphQLEnumType/* <T> */ {
931935
_values: Array<GraphQLEnumValue/* <T> */>;
932936
_valueLookup: Map<any/* T */, GraphQLEnumValue>;
933937
_nameLookup: ObjMap<GraphQLEnumValue>;
938+
_wrappedList: ?GraphQLList<*>;
934939

935940
constructor(config: GraphQLEnumTypeConfig/* <T> */): void {
936941
this.name = config.name;
@@ -1009,7 +1014,7 @@ export class GraphQLEnumType/* <T> */ {
10091014
}
10101015

10111016
wrapList(): GraphQLList<*> {
1012-
return new GraphQLList(this);
1017+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
10131018
}
10141019

10151020
toJSON: () => string;
@@ -1119,6 +1124,7 @@ export class GraphQLInputObjectType {
11191124

11201125
_typeConfig: GraphQLInputObjectTypeConfig;
11211126
_fields: GraphQLInputFieldMap;
1127+
_wrappedList: ?GraphQLList<*>;
11221128

11231129
constructor(config: GraphQLInputObjectTypeConfig): void {
11241130
assertValidName(config.name);
@@ -1172,7 +1178,7 @@ export class GraphQLInputObjectType {
11721178
}
11731179

11741180
wrapList(): GraphQLList<*> {
1175-
return new GraphQLList(this);
1181+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
11761182
}
11771183

11781184
toJSON: () => string;
@@ -1226,14 +1232,15 @@ export type GraphQLInputFieldMap =
12261232
* const PersonType = new GraphQLObjectType({
12271233
* name: 'Person',
12281234
* fields: () => ({
1229-
* parents: { type: new GraphQLList(Person) },
1230-
* children: { type: new GraphQLList(Person) },
1235+
* parents: { type: Person.wrapList() },
1236+
* children: { type: Person.wrapList() },
12311237
* })
12321238
* })
12331239
*
12341240
*/
12351241
export class GraphQLList<T: GraphQLType> {
12361242
ofType: T;
1243+
_wrappedList: ?GraphQLList<*>;
12371244

12381245
constructor(type: T): void {
12391246
invariant(
@@ -1248,7 +1255,7 @@ export class GraphQLList<T: GraphQLType> {
12481255
}
12491256

12501257
wrapList(): GraphQLList<*> {
1251-
return new GraphQLList(this);
1258+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
12521259
}
12531260

12541261
toJSON: () => string;
@@ -1283,6 +1290,7 @@ GraphQLList.prototype.toJSON =
12831290
*/
12841291
export class GraphQLNonNull<T: GraphQLNullableType> {
12851292
ofType: T;
1293+
_wrappedList: ?GraphQLList<*>;
12861294

12871295
constructor(type: T): void {
12881296
invariant(
@@ -1298,7 +1306,7 @@ export class GraphQLNonNull<T: GraphQLNullableType> {
12981306
}
12991307

13001308
wrapList(): GraphQLList<*> {
1301-
return new GraphQLList(this);
1309+
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
13021310
}
13031311

13041312
toJSON: () => string;

0 commit comments

Comments
 (0)