|
7 | 7 | * @flow strict
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import applyToStringTag from '../jsutils/applyToStringTag'; |
| 10 | +import defineToJSON from '../jsutils/defineToJSON'; |
| 11 | +import defineToStringTag from '../jsutils/defineToStringTag'; |
11 | 12 | import instanceOf from '../jsutils/instanceOf';
|
12 | 13 | import inspect from '../jsutils/inspect';
|
13 | 14 | import invariant from '../jsutils/invariant';
|
@@ -349,11 +350,11 @@ export function GraphQLList(ofType) {
|
349 | 350 | }
|
350 | 351 | }
|
351 | 352 |
|
352 |
| -// Also provide toJSON and inspect aliases for toString. |
353 |
| -const listProto: any = GraphQLList.prototype; |
354 |
| -listProto.toString = listProto.toJSON = listProto.inspect = function toString() { |
| 353 | +// Need to cast through any to alter the prototype. |
| 354 | +(GraphQLList.prototype: any).toString = function toString() { |
355 | 355 | return '[' + String(this.ofType) + ']';
|
356 | 356 | };
|
| 357 | +defineToJSON(GraphQLList); |
357 | 358 |
|
358 | 359 | /**
|
359 | 360 | * Non-Null Type Wrapper
|
@@ -390,11 +391,11 @@ export function GraphQLNonNull(ofType) {
|
390 | 391 | }
|
391 | 392 | }
|
392 | 393 |
|
393 |
| -// Also provide toJSON and inspect aliases for toString. |
394 |
| -const nonNullProto: any = GraphQLNonNull.prototype; |
395 |
| -nonNullProto.toString = nonNullProto.toJSON = nonNullProto.inspect = function toString() { |
| 394 | +// Need to cast through any to alter the prototype. |
| 395 | +(GraphQLNonNull.prototype: any).toString = function toString() { |
396 | 396 | return String(this.ofType) + '!';
|
397 | 397 | };
|
| 398 | +defineToJSON(GraphQLNonNull); |
398 | 399 |
|
399 | 400 | /**
|
400 | 401 | * These types wrap and modify other types
|
@@ -579,17 +580,11 @@ export class GraphQLScalarType {
|
579 | 580 | toString(): string {
|
580 | 581 | return this.name;
|
581 | 582 | }
|
582 |
| - |
583 |
| - toJSON: () => string; |
584 |
| - inspect: () => string; |
585 | 583 | }
|
586 | 584 |
|
587 | 585 | // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
|
588 |
| -applyToStringTag(GraphQLScalarType); |
589 |
| - |
590 |
| -// Also provide toJSON and inspect aliases for toString. |
591 |
| -GraphQLScalarType.prototype.toJSON = GraphQLScalarType.prototype.inspect = |
592 |
| - GraphQLScalarType.prototype.toString; |
| 586 | +defineToStringTag(GraphQLScalarType); |
| 587 | +defineToJSON(GraphQLScalarType); |
593 | 588 |
|
594 | 589 | export type GraphQLScalarTypeConfig<TInternal, TExternal> = {
|
595 | 590 | name: string,
|
@@ -684,17 +679,11 @@ export class GraphQLObjectType {
|
684 | 679 | toString(): string {
|
685 | 680 | return this.name;
|
686 | 681 | }
|
687 |
| - |
688 |
| - toJSON: () => string; |
689 |
| - inspect: () => string; |
690 | 682 | }
|
691 | 683 |
|
692 | 684 | // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
|
693 |
| -applyToStringTag(GraphQLObjectType); |
694 |
| - |
695 |
| -// Also provide toJSON and inspect aliases for toString. |
696 |
| -GraphQLObjectType.prototype.toJSON = GraphQLObjectType.prototype.inspect = |
697 |
| - GraphQLObjectType.prototype.toString; |
| 685 | +defineToStringTag(GraphQLObjectType); |
| 686 | +defineToJSON(GraphQLObjectType); |
698 | 687 |
|
699 | 688 | function defineInterfaces(
|
700 | 689 | type: GraphQLObjectType,
|
@@ -936,17 +925,11 @@ export class GraphQLInterfaceType {
|
936 | 925 | toString(): string {
|
937 | 926 | return this.name;
|
938 | 927 | }
|
939 |
| - |
940 |
| - toJSON: () => string; |
941 |
| - inspect: () => string; |
942 | 928 | }
|
943 | 929 |
|
944 | 930 | // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
|
945 |
| -applyToStringTag(GraphQLInterfaceType); |
946 |
| - |
947 |
| -// Also provide toJSON and inspect aliases for toString. |
948 |
| -GraphQLInterfaceType.prototype.toJSON = GraphQLInterfaceType.prototype.inspect = |
949 |
| - GraphQLInterfaceType.prototype.toString; |
| 931 | +defineToStringTag(GraphQLInterfaceType); |
| 932 | +defineToJSON(GraphQLInterfaceType); |
950 | 933 |
|
951 | 934 | export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
|
952 | 935 | name: string,
|
@@ -1019,17 +1002,11 @@ export class GraphQLUnionType {
|
1019 | 1002 | toString(): string {
|
1020 | 1003 | return this.name;
|
1021 | 1004 | }
|
1022 |
| - |
1023 |
| - toJSON: () => string; |
1024 |
| - inspect: () => string; |
1025 | 1005 | }
|
1026 | 1006 |
|
1027 | 1007 | // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
|
1028 |
| -applyToStringTag(GraphQLUnionType); |
1029 |
| - |
1030 |
| -// Also provide toJSON and inspect aliases for toString. |
1031 |
| -GraphQLUnionType.prototype.toJSON = GraphQLUnionType.prototype.inspect = |
1032 |
| - GraphQLUnionType.prototype.toString; |
| 1008 | +defineToStringTag(GraphQLUnionType); |
| 1009 | +defineToJSON(GraphQLUnionType); |
1033 | 1010 |
|
1034 | 1011 | function defineTypes(
|
1035 | 1012 | unionType: GraphQLUnionType,
|
@@ -1138,17 +1115,11 @@ export class GraphQLEnumType /* <T> */ {
|
1138 | 1115 | toString(): string {
|
1139 | 1116 | return this.name;
|
1140 | 1117 | }
|
1141 |
| - |
1142 |
| - toJSON: () => string; |
1143 |
| - inspect: () => string; |
1144 | 1118 | }
|
1145 | 1119 |
|
1146 | 1120 | // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
|
1147 |
| -applyToStringTag(GraphQLEnumType); |
1148 |
| - |
1149 |
| -// Also provide toJSON and inspect aliases for toString. |
1150 |
| -GraphQLEnumType.prototype.toJSON = GraphQLEnumType.prototype.inspect = |
1151 |
| - GraphQLEnumType.prototype.toString; |
| 1121 | +defineToStringTag(GraphQLEnumType); |
| 1122 | +defineToJSON(GraphQLEnumType); |
1152 | 1123 |
|
1153 | 1124 | function defineEnumValues(
|
1154 | 1125 | type: GraphQLEnumType,
|
@@ -1275,19 +1246,11 @@ export class GraphQLInputObjectType {
|
1275 | 1246 | toString(): string {
|
1276 | 1247 | return this.name;
|
1277 | 1248 | }
|
1278 |
| - |
1279 |
| - toJSON: () => string; |
1280 |
| - inspect: () => string; |
1281 | 1249 | }
|
1282 | 1250 |
|
1283 | 1251 | // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
|
1284 |
| -applyToStringTag(GraphQLInputObjectType); |
1285 |
| - |
1286 |
| -// Also provide toJSON and inspect aliases for toString. |
1287 |
| -GraphQLInputObjectType.prototype.toJSON = |
1288 |
| - GraphQLInputObjectType.prototype.toString; |
1289 |
| -GraphQLInputObjectType.prototype.inspect = |
1290 |
| - GraphQLInputObjectType.prototype.toString; |
| 1252 | +defineToStringTag(GraphQLInputObjectType); |
| 1253 | +defineToJSON(GraphQLInputObjectType); |
1291 | 1254 |
|
1292 | 1255 | export type GraphQLInputObjectTypeConfig = {
|
1293 | 1256 | name: string,
|
|
0 commit comments