graphql 16.14.2 → 16.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/error/GraphQLError.d.ts +5 -1
- package/error/GraphQLError.js +12 -7
- package/error/GraphQLError.mjs +13 -6
- package/error/locatedError.d.ts +6 -4
- package/error/locatedError.js +6 -4
- package/error/locatedError.mjs +6 -4
- package/execution/collectFields.d.ts +1 -0
- package/execution/collectFields.js +9 -0
- package/execution/collectFields.mjs +9 -0
- package/execution/execute.d.ts +9 -10
- package/execution/execute.js +44 -29
- package/execution/execute.mjs +44 -29
- package/execution/mapAsyncIterator.js +12 -11
- package/execution/mapAsyncIterator.mjs +12 -11
- package/execution/subscribe.d.ts +5 -2
- package/execution/subscribe.js +5 -2
- package/execution/subscribe.mjs +5 -2
- package/execution/values.d.ts +43 -21
- package/execution/values.js +52 -24
- package/execution/values.mjs +51 -23
- package/graphql.d.ts +8 -14
- package/graphql.js +16 -15
- package/graphql.mjs +11 -15
- package/jsutils/SetMap.d.ts +14 -0
- package/jsutils/SetMap.js +48 -0
- package/jsutils/SetMap.mjs +39 -0
- package/jsutils/isIterableObject.d.ts +2 -0
- package/jsutils/isIterableObject.js +2 -0
- package/jsutils/isIterableObject.mjs +2 -0
- package/jsutils/keyMap.d.ts +2 -0
- package/jsutils/keyMap.js +2 -0
- package/jsutils/keyMap.mjs +2 -0
- package/jsutils/keyValMap.d.ts +3 -3
- package/jsutils/keyValMap.js +3 -3
- package/jsutils/keyValMap.mjs +3 -3
- package/language/ast.d.ts +2 -6
- package/language/ast.js +2 -6
- package/language/ast.mjs +2 -6
- package/language/lexer.d.ts +6 -0
- package/language/lexer.js +22 -0
- package/language/lexer.mjs +22 -0
- package/language/location.d.ts +8 -3
- package/language/location.js +57 -17
- package/language/location.mjs +56 -16
- package/language/parser.d.ts +27 -13
- package/language/parser.js +31 -9
- package/language/parser.mjs +31 -9
- package/language/predicates.d.ts +10 -3
- package/language/predicates.js +10 -3
- package/language/predicates.mjs +10 -3
- package/language/printLocation.d.ts +2 -6
- package/language/printLocation.js +2 -6
- package/language/printLocation.mjs +2 -6
- package/language/printer.d.ts +22 -3
- package/language/printer.js +394 -308
- package/language/printer.mjs +394 -308
- package/language/reducer.d.ts +32 -0
- package/language/reducer.js +95 -0
- package/language/reducer.mjs +86 -0
- package/language/source.d.ts +4 -5
- package/language/source.js +4 -5
- package/language/source.mjs +4 -5
- package/language/visitor.d.ts +16 -10
- package/language/visitor.js +15 -7
- package/language/visitor.mjs +15 -7
- package/package.json +1 -4
- package/type/definition.d.ts +170 -102
- package/type/definition.js +169 -96
- package/type/definition.mjs +168 -95
- package/type/directives.d.ts +12 -6
- package/type/directives.js +12 -6
- package/type/directives.mjs +12 -6
- package/type/scalars.js +8 -11
- package/type/scalars.mjs +1 -1
- package/type/schema.d.ts +36 -11
- package/type/schema.js +35 -10
- package/type/schema.mjs +35 -10
- package/type/validate.d.ts +1 -3
- package/type/validate.js +1 -3
- package/type/validate.mjs +1 -3
- package/utilities/TypeInfo.d.ts +15 -11
- package/utilities/TypeInfo.js +15 -11
- package/utilities/TypeInfo.mjs +15 -11
- package/utilities/assertValidName.d.ts +1 -1
- package/utilities/assertValidName.js +1 -1
- package/utilities/assertValidName.mjs +1 -1
- package/utilities/astFromValue.d.ts +3 -1
- package/utilities/astFromValue.js +3 -1
- package/utilities/astFromValue.mjs +3 -1
- package/utilities/buildASTSchema.d.ts +8 -8
- package/utilities/buildASTSchema.js +9 -20
- package/utilities/buildASTSchema.mjs +9 -20
- package/utilities/buildClientSchema.d.ts +6 -2
- package/utilities/buildClientSchema.js +6 -2
- package/utilities/buildClientSchema.mjs +6 -2
- package/utilities/coerceInputValue.d.ts +9 -3
- package/utilities/coerceInputValue.js +60 -13
- package/utilities/coerceInputValue.mjs +58 -13
- package/utilities/concatAST.d.ts +4 -1
- package/utilities/concatAST.js +4 -1
- package/utilities/concatAST.mjs +4 -1
- package/utilities/extendSchema.d.ts +7 -4
- package/utilities/extendSchema.js +7 -4
- package/utilities/extendSchema.mjs +7 -4
- package/utilities/findBreakingChanges.d.ts +2 -2
- package/utilities/findBreakingChanges.js +2 -2
- package/utilities/findBreakingChanges.mjs +2 -2
- package/utilities/getIntrospectionQuery.d.ts +9 -9
- package/utilities/getIntrospectionQuery.js +8 -8
- package/utilities/getIntrospectionQuery.mjs +8 -8
- package/utilities/getOperationAST.d.ts +2 -2
- package/utilities/getOperationAST.js +2 -2
- package/utilities/getOperationAST.mjs +2 -2
- package/utilities/getOperationRootType.d.ts +3 -1
- package/utilities/getOperationRootType.js +3 -1
- package/utilities/getOperationRootType.mjs +3 -1
- package/utilities/introspectionFromSchema.d.ts +12 -4
- package/utilities/introspectionFromSchema.js +12 -4
- package/utilities/introspectionFromSchema.mjs +12 -4
- package/utilities/lexicographicSortSchema.d.ts +17 -13
- package/utilities/lexicographicSortSchema.js +17 -13
- package/utilities/lexicographicSortSchema.mjs +17 -13
- package/utilities/printSchema.d.ts +7 -4
- package/utilities/printSchema.js +7 -4
- package/utilities/printSchema.mjs +7 -4
- package/utilities/resolveSchemaCoordinate.d.ts +9 -8
- package/utilities/resolveSchemaCoordinate.js +9 -8
- package/utilities/resolveSchemaCoordinate.mjs +9 -8
- package/utilities/separateOperations.d.ts +2 -2
- package/utilities/separateOperations.js +2 -2
- package/utilities/separateOperations.mjs +2 -2
- package/utilities/stripIgnoredCharacters.d.ts +19 -5
- package/utilities/stripIgnoredCharacters.js +19 -5
- package/utilities/stripIgnoredCharacters.mjs +19 -5
- package/utilities/typeComparators.d.ts +1 -5
- package/utilities/typeComparators.js +1 -5
- package/utilities/typeComparators.mjs +1 -5
- package/utilities/valueFromAST.js +4 -4
- package/utilities/valueFromAST.mjs +4 -4
- package/utilities/valueFromASTUntyped.d.ts +1 -3
- package/utilities/valueFromASTUntyped.js +1 -3
- package/utilities/valueFromASTUntyped.mjs +1 -3
- package/validation/ValidationContext.d.ts +22 -3
- package/validation/ValidationContext.js +84 -27
- package/validation/ValidationContext.mjs +82 -27
- package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -4
- package/validation/rules/ExecutableDefinitionsRule.js +6 -4
- package/validation/rules/ExecutableDefinitionsRule.mjs +6 -4
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +4 -4
- package/validation/rules/FieldsOnCorrectTypeRule.js +10 -6
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +12 -6
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.js +6 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs +6 -4
- package/validation/rules/KnownArgumentNamesRule.d.ts +4 -4
- package/validation/rules/KnownArgumentNamesRule.js +26 -17
- package/validation/rules/KnownArgumentNamesRule.mjs +21 -11
- package/validation/rules/KnownDirectivesRule.d.ts +1 -3
- package/validation/rules/KnownDirectivesRule.js +1 -3
- package/validation/rules/KnownDirectivesRule.mjs +1 -3
- package/validation/rules/KnownFragmentNamesRule.d.ts +4 -4
- package/validation/rules/KnownFragmentNamesRule.js +4 -4
- package/validation/rules/KnownFragmentNamesRule.mjs +4 -4
- package/validation/rules/KnownTypeNamesRule.d.ts +1 -3
- package/validation/rules/KnownTypeNamesRule.js +7 -7
- package/validation/rules/KnownTypeNamesRule.mjs +7 -7
- package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -4
- package/validation/rules/LoneAnonymousOperationRule.js +6 -4
- package/validation/rules/LoneAnonymousOperationRule.mjs +6 -4
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -4
- package/validation/rules/MaxIntrospectionDepthRule.js +44 -19
- package/validation/rules/MaxIntrospectionDepthRule.mjs +44 -19
- package/validation/rules/NoFragmentCyclesRule.d.ts +1 -3
- package/validation/rules/NoFragmentCyclesRule.js +1 -3
- package/validation/rules/NoFragmentCyclesRule.mjs +1 -3
- package/validation/rules/NoUndefinedVariablesRule.d.ts +4 -4
- package/validation/rules/NoUndefinedVariablesRule.js +4 -4
- package/validation/rules/NoUndefinedVariablesRule.mjs +4 -4
- package/validation/rules/NoUnusedFragmentsRule.d.ts +4 -4
- package/validation/rules/NoUnusedFragmentsRule.js +10 -14
- package/validation/rules/NoUnusedFragmentsRule.mjs +10 -14
- package/validation/rules/NoUnusedVariablesRule.d.ts +4 -4
- package/validation/rules/NoUnusedVariablesRule.js +4 -4
- package/validation/rules/NoUnusedVariablesRule.mjs +4 -4
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +8 -6
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +552 -354
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +545 -352
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -4
- package/validation/rules/PossibleFragmentSpreadsRule.js +6 -4
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.js +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +6 -4
- package/validation/rules/ScalarLeafsRule.d.ts +1 -3
- package/validation/rules/ScalarLeafsRule.js +1 -3
- package/validation/rules/ScalarLeafsRule.mjs +1 -3
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -4
- package/validation/rules/SingleFieldSubscriptionsRule.js +50 -9
- package/validation/rules/SingleFieldSubscriptionsRule.mjs +50 -9
- package/validation/rules/UniqueArgumentNamesRule.d.ts +4 -4
- package/validation/rules/UniqueArgumentNamesRule.js +4 -4
- package/validation/rules/UniqueArgumentNamesRule.mjs +4 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.js +6 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs +6 -4
- package/validation/rules/UniqueFragmentNamesRule.d.ts +4 -4
- package/validation/rules/UniqueFragmentNamesRule.js +4 -4
- package/validation/rules/UniqueFragmentNamesRule.mjs +4 -4
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -4
- package/validation/rules/UniqueInputFieldNamesRule.js +6 -4
- package/validation/rules/UniqueInputFieldNamesRule.mjs +6 -4
- package/validation/rules/UniqueOperationNamesRule.d.ts +4 -4
- package/validation/rules/UniqueOperationNamesRule.js +4 -4
- package/validation/rules/UniqueOperationNamesRule.mjs +4 -4
- package/validation/rules/UniqueVariableNamesRule.d.ts +4 -4
- package/validation/rules/UniqueVariableNamesRule.js +4 -4
- package/validation/rules/UniqueVariableNamesRule.mjs +4 -4
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +4 -4
- package/validation/rules/ValuesOfCorrectTypeRule.js +29 -23
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +24 -14
- package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -4
- package/validation/rules/VariablesAreInputTypesRule.js +6 -4
- package/validation/rules/VariablesAreInputTypesRule.mjs +6 -4
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -4
- package/validation/rules/VariablesInAllowedPositionRule.js +6 -4
- package/validation/rules/VariablesInAllowedPositionRule.mjs +6 -4
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +4 -4
- package/validation/rules/custom/NoDeprecatedCustomRule.js +4 -4
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +4 -4
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +7 -5
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +7 -5
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +7 -5
- package/validation/validate.d.ts +2 -0
- package/validation/validate.js +14 -2
- package/validation/validate.mjs +13 -2
- package/validation/validationAbortedError.d.ts +3 -0
- package/validation/validationAbortedError.js +14 -0
- package/validation/validationAbortedError.mjs +4 -0
- package/version.js +3 -3
- package/version.mjs +3 -3
package/type/definition.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { suggestionList } from '../jsutils/suggestionList.mjs';
|
|
|
12
12
|
import { toObjMap } from '../jsutils/toObjMap.mjs';
|
|
13
13
|
import { GraphQLError } from '../error/GraphQLError.mjs';
|
|
14
14
|
import { Kind } from '../language/kinds.mjs';
|
|
15
|
-
import { print } from '../language/printer.mjs';
|
|
15
|
+
import { printForError as print } from '../language/printer.mjs';
|
|
16
16
|
import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped.mjs';
|
|
17
17
|
import { assertEnumValueName, assertName } from './assertName.mjs';
|
|
18
18
|
|
|
@@ -955,13 +955,15 @@ export function assertAbstractType(type) {
|
|
|
955
955
|
* @typeParam T - The GraphQL type wrapped by this list type.
|
|
956
956
|
* @example
|
|
957
957
|
* ```ts
|
|
958
|
-
*
|
|
958
|
+
* import { GraphQLList, GraphQLObjectType } from 'graphql';
|
|
959
|
+
*
|
|
960
|
+
* const PersonType: GraphQLObjectType = new GraphQLObjectType({
|
|
959
961
|
* name: 'Person',
|
|
960
962
|
* fields: () => ({
|
|
961
963
|
* parents: { type: new GraphQLList(PersonType) },
|
|
962
964
|
* children: { type: new GraphQLList(PersonType) },
|
|
963
|
-
* })
|
|
964
|
-
* })
|
|
965
|
+
* }),
|
|
966
|
+
* });
|
|
965
967
|
* ```
|
|
966
968
|
*/
|
|
967
969
|
|
|
@@ -1041,12 +1043,14 @@ export class GraphQLList {
|
|
|
1041
1043
|
* @typeParam T - The nullable GraphQL type wrapped by this non-null type.
|
|
1042
1044
|
* @example
|
|
1043
1045
|
* ```ts
|
|
1046
|
+
* import { GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql';
|
|
1047
|
+
*
|
|
1044
1048
|
* const RowType = new GraphQLObjectType({
|
|
1045
1049
|
* name: 'Row',
|
|
1046
1050
|
* fields: () => ({
|
|
1047
1051
|
* id: { type: new GraphQLNonNull(GraphQLString) },
|
|
1048
|
-
* })
|
|
1049
|
-
* })
|
|
1052
|
+
* }),
|
|
1053
|
+
* });
|
|
1050
1054
|
* ```
|
|
1051
1055
|
*
|
|
1052
1056
|
* Note: the enforcement of non-nullability occurs within the executor.
|
|
@@ -1092,9 +1096,7 @@ export class GraphQLNonNull {
|
|
|
1092
1096
|
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
1093
1097
|
*
|
|
1094
1098
|
* const requiredString = new GraphQLNonNull(GraphQLString);
|
|
1095
|
-
* const requiredStringList = new GraphQLNonNull(
|
|
1096
|
-
* new GraphQLList(GraphQLString),
|
|
1097
|
-
* );
|
|
1099
|
+
* const requiredStringList = new GraphQLNonNull(new GraphQLList(GraphQLString));
|
|
1098
1100
|
*
|
|
1099
1101
|
* requiredString.toString(); // => 'String!'
|
|
1100
1102
|
* requiredStringList.toString(); // => '[String]!'
|
|
@@ -1197,9 +1199,7 @@ export function isNullableType(type) {
|
|
|
1197
1199
|
* assertNullableType,
|
|
1198
1200
|
* } from 'graphql/type';
|
|
1199
1201
|
*
|
|
1200
|
-
* const nullableType = assertNullableType(GraphQLString);
|
|
1201
|
-
*
|
|
1202
|
-
* nullableType; // => GraphQLString
|
|
1202
|
+
* const nullableType = assertNullableType(GraphQLString); // => GraphQLString
|
|
1203
1203
|
* assertNullableType(new GraphQLNonNull(GraphQLString)); // throws an error
|
|
1204
1204
|
* ```
|
|
1205
1205
|
*/
|
|
@@ -1317,11 +1317,8 @@ export function getNamedType(type) {
|
|
|
1317
1317
|
* ```ts
|
|
1318
1318
|
* import { GraphQLString, resolveReadonlyArrayThunk } from 'graphql/type';
|
|
1319
1319
|
*
|
|
1320
|
-
* const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]);
|
|
1321
|
-
* const fields = resolveReadonlyArrayThunk([GraphQLString]);
|
|
1322
|
-
*
|
|
1323
|
-
* lazyFields; // => [GraphQLString]
|
|
1324
|
-
* fields; // => [GraphQLString]
|
|
1320
|
+
* const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]); // => [GraphQLString]
|
|
1321
|
+
* const fields = resolveReadonlyArrayThunk([GraphQLString]); // => [GraphQLString]
|
|
1325
1322
|
* ```
|
|
1326
1323
|
*/
|
|
1327
1324
|
export function resolveReadonlyArrayThunk(thunk) {
|
|
@@ -1372,21 +1369,29 @@ export function resolveObjMapThunk(thunk) {
|
|
|
1372
1369
|
* @typeParam TExternal - The serialized representation exposed in GraphQL results.
|
|
1373
1370
|
* @example
|
|
1374
1371
|
* ```ts
|
|
1372
|
+
* import { GraphQLScalarType } from 'graphql/type';
|
|
1373
|
+
*
|
|
1375
1374
|
* const OddType = new GraphQLScalarType({
|
|
1376
1375
|
* name: 'Odd',
|
|
1377
1376
|
* serialize: (value) => {
|
|
1378
|
-
* if (!Number.
|
|
1377
|
+
* if (typeof value !== 'number' || !Number.isInteger(value)) {
|
|
1379
1378
|
* throw new Error(
|
|
1380
|
-
* `Scalar "Odd" cannot represent "${value}" since it is not
|
|
1379
|
+
* `Scalar "Odd" cannot represent "${value}" since it is not an integer.`,
|
|
1381
1380
|
* );
|
|
1382
1381
|
* }
|
|
1383
1382
|
*
|
|
1384
1383
|
* if (value % 2 === 0) {
|
|
1385
|
-
* throw new Error(
|
|
1384
|
+
* throw new Error(
|
|
1385
|
+
* `Scalar "Odd" cannot represent "${value}" since it is even.`,
|
|
1386
|
+
* );
|
|
1386
1387
|
* }
|
|
1387
1388
|
* return value;
|
|
1388
|
-
* }
|
|
1389
|
+
* },
|
|
1389
1390
|
* });
|
|
1391
|
+
*
|
|
1392
|
+
* OddType.serialize(3); // => 3
|
|
1393
|
+
* OddType.serialize(2); // throws an error
|
|
1394
|
+
* OddType.serialize(1.5); // throws an error
|
|
1390
1395
|
* ```
|
|
1391
1396
|
*/
|
|
1392
1397
|
export class GraphQLScalarType {
|
|
@@ -1413,6 +1418,7 @@ export class GraphQLScalarType {
|
|
|
1413
1418
|
* @param config - Configuration describing this object.
|
|
1414
1419
|
* @example
|
|
1415
1420
|
* ```ts
|
|
1421
|
+
* import assert from 'node:assert/strict';
|
|
1416
1422
|
* import { Kind, parse } from 'graphql/language';
|
|
1417
1423
|
* import { GraphQLScalarType } from 'graphql/type';
|
|
1418
1424
|
*
|
|
@@ -1422,42 +1428,43 @@ export class GraphQLScalarType {
|
|
|
1422
1428
|
*
|
|
1423
1429
|
* extend scalar Odd @specifiedBy(url: "https://example.com/odd-v2")
|
|
1424
1430
|
* `);
|
|
1431
|
+
* assert(document.definitions[0].kind === Kind.SCALAR_TYPE_DEFINITION);
|
|
1432
|
+
* assert(document.definitions[1].kind === Kind.SCALAR_TYPE_EXTENSION);
|
|
1433
|
+
*
|
|
1434
|
+
* const ensureOdd = (value: unknown) => {
|
|
1435
|
+
* if (
|
|
1436
|
+
* typeof value !== 'number' ||
|
|
1437
|
+
* !Number.isInteger(value) ||
|
|
1438
|
+
* value % 2 === 0
|
|
1439
|
+
* ) {
|
|
1440
|
+
* throw new TypeError('Odd can only accept odd integers.');
|
|
1441
|
+
* }
|
|
1442
|
+
* return value;
|
|
1443
|
+
* };
|
|
1425
1444
|
*
|
|
1426
1445
|
* const Odd = new GraphQLScalarType({
|
|
1427
1446
|
* name: 'Odd',
|
|
1428
1447
|
* description: 'Odd integer values.',
|
|
1429
1448
|
* specifiedByURL: 'https://example.com/odd',
|
|
1430
|
-
* serialize:
|
|
1431
|
-
*
|
|
1432
|
-
* throw new TypeError('Odd can only serialize odd numbers.');
|
|
1433
|
-
* }
|
|
1434
|
-
* return value;
|
|
1435
|
-
* },
|
|
1436
|
-
* parseValue: (value) => {
|
|
1437
|
-
* if (typeof value !== 'number' || value % 2 === 0) {
|
|
1438
|
-
* throw new TypeError('Odd can only parse odd numbers.');
|
|
1439
|
-
* }
|
|
1440
|
-
* return value;
|
|
1441
|
-
* },
|
|
1449
|
+
* serialize: ensureOdd,
|
|
1450
|
+
* parseValue: ensureOdd,
|
|
1442
1451
|
* parseLiteral: (ast) => {
|
|
1443
1452
|
* if (ast.kind !== Kind.INT) {
|
|
1444
1453
|
* throw new TypeError('Odd can only parse integer literals.');
|
|
1445
1454
|
* }
|
|
1446
|
-
*
|
|
1447
|
-
* if (value % 2 === 0) {
|
|
1448
|
-
* throw new TypeError('Odd can only parse odd integer literals.');
|
|
1449
|
-
* }
|
|
1450
|
-
* return value;
|
|
1455
|
+
* return ensureOdd(Number(ast.value));
|
|
1451
1456
|
* },
|
|
1452
1457
|
* extensions: { numeric: true },
|
|
1453
1458
|
* astNode: document.definitions[0],
|
|
1454
|
-
* extensionASTNodes: [
|
|
1459
|
+
* extensionASTNodes: [document.definitions[1]],
|
|
1455
1460
|
* });
|
|
1456
1461
|
*
|
|
1457
1462
|
* Odd.description; // => 'Odd integer values.'
|
|
1458
1463
|
* Odd.specifiedByURL; // => 'https://example.com/odd'
|
|
1459
1464
|
* Odd.serialize(3); // => 3
|
|
1460
1465
|
* Odd.parseValue(5); // => 5
|
|
1466
|
+
* Odd.parseValue(2); // throws an error
|
|
1467
|
+
* Odd.parseValue(1.5); // throws an error
|
|
1461
1468
|
* Odd.extensions; // => { numeric: true }
|
|
1462
1469
|
* ```
|
|
1463
1470
|
*/
|
|
@@ -1608,6 +1615,8 @@ export class GraphQLScalarType {
|
|
|
1608
1615
|
* @typeParam TContext - Context object type passed to resolvers.
|
|
1609
1616
|
* @example
|
|
1610
1617
|
* ```ts
|
|
1618
|
+
* import { GraphQLInt, GraphQLObjectType, GraphQLString } from 'graphql';
|
|
1619
|
+
*
|
|
1611
1620
|
* const AddressType = new GraphQLObjectType({
|
|
1612
1621
|
* name: 'Address',
|
|
1613
1622
|
* fields: {
|
|
@@ -1616,10 +1625,10 @@ export class GraphQLScalarType {
|
|
|
1616
1625
|
* formatted: {
|
|
1617
1626
|
* type: GraphQLString,
|
|
1618
1627
|
* resolve: (obj) => {
|
|
1619
|
-
* return obj.number + ' ' + obj.street
|
|
1620
|
-
* }
|
|
1621
|
-
* }
|
|
1622
|
-
* }
|
|
1628
|
+
* return obj.number + ' ' + obj.street;
|
|
1629
|
+
* },
|
|
1630
|
+
* },
|
|
1631
|
+
* },
|
|
1623
1632
|
* });
|
|
1624
1633
|
* ```
|
|
1625
1634
|
* @example
|
|
@@ -1628,12 +1637,14 @@ export class GraphQLScalarType {
|
|
|
1628
1637
|
* thunk) to supply the fields lazily.
|
|
1629
1638
|
*
|
|
1630
1639
|
* ```ts
|
|
1631
|
-
*
|
|
1640
|
+
* import { GraphQLObjectType, GraphQLString } from 'graphql';
|
|
1641
|
+
*
|
|
1642
|
+
* const PersonType: GraphQLObjectType = new GraphQLObjectType({
|
|
1632
1643
|
* name: 'Person',
|
|
1633
1644
|
* fields: () => ({
|
|
1634
1645
|
* name: { type: GraphQLString },
|
|
1635
1646
|
* bestFriend: { type: PersonType },
|
|
1636
|
-
* })
|
|
1647
|
+
* }),
|
|
1637
1648
|
* });
|
|
1638
1649
|
* ```
|
|
1639
1650
|
*/
|
|
@@ -1655,8 +1666,9 @@ export class GraphQLObjectType {
|
|
|
1655
1666
|
* @param config - Configuration describing this object.
|
|
1656
1667
|
* @example
|
|
1657
1668
|
* ```ts
|
|
1669
|
+
* import assert from 'node:assert/strict';
|
|
1658
1670
|
* // Configure an object type with interfaces, fields, arguments, and metadata.
|
|
1659
|
-
* import { parse } from 'graphql/language';
|
|
1671
|
+
* import { parse, Kind } from 'graphql/language';
|
|
1660
1672
|
* import {
|
|
1661
1673
|
* GraphQLID,
|
|
1662
1674
|
* GraphQLInterfaceType,
|
|
@@ -1675,9 +1687,11 @@ export class GraphQLObjectType {
|
|
|
1675
1687
|
* displayName: String
|
|
1676
1688
|
* }
|
|
1677
1689
|
* `);
|
|
1690
|
+
* assert(document.definitions[0].kind === Kind.OBJECT_TYPE_DEFINITION);
|
|
1691
|
+
* assert(document.definitions[1].kind === Kind.OBJECT_TYPE_EXTENSION);
|
|
1678
1692
|
* const definition = document.definitions[0];
|
|
1679
|
-
* const nameField = definition.fields[1];
|
|
1680
|
-
* const formatArg = nameField
|
|
1693
|
+
* const nameField = definition.fields?.[1];
|
|
1694
|
+
* const formatArg = nameField?.arguments?.[0];
|
|
1681
1695
|
*
|
|
1682
1696
|
* const Node = new GraphQLInterfaceType({
|
|
1683
1697
|
* name: 'Node',
|
|
@@ -1718,7 +1732,7 @@ export class GraphQLObjectType {
|
|
|
1718
1732
|
* },
|
|
1719
1733
|
* extensions: { entity: 'User' },
|
|
1720
1734
|
* astNode: definition,
|
|
1721
|
-
* extensionASTNodes: [
|
|
1735
|
+
* extensionASTNodes: [document.definitions[1]],
|
|
1722
1736
|
* });
|
|
1723
1737
|
*
|
|
1724
1738
|
* User.name; // => 'User'
|
|
@@ -2059,17 +2073,26 @@ export function argsToArgsConfig(args) {
|
|
|
2059
2073
|
* import {
|
|
2060
2074
|
* GraphQLInt,
|
|
2061
2075
|
* GraphQLNonNull,
|
|
2076
|
+
* GraphQLObjectType,
|
|
2062
2077
|
* GraphQLString,
|
|
2063
2078
|
* isRequiredArgument,
|
|
2064
2079
|
* } from 'graphql/type';
|
|
2065
2080
|
*
|
|
2066
|
-
* const
|
|
2067
|
-
*
|
|
2068
|
-
*
|
|
2069
|
-
*
|
|
2070
|
-
*
|
|
2071
|
-
*
|
|
2072
|
-
* }
|
|
2081
|
+
* const Query = new GraphQLObjectType({
|
|
2082
|
+
* name: 'Query',
|
|
2083
|
+
* fields: {
|
|
2084
|
+
* greeting: {
|
|
2085
|
+
* type: GraphQLString,
|
|
2086
|
+
* args: {
|
|
2087
|
+
* id: { type: new GraphQLNonNull(GraphQLInt) },
|
|
2088
|
+
* name: { type: GraphQLString },
|
|
2089
|
+
* limit: { type: new GraphQLNonNull(GraphQLInt), defaultValue: 10 },
|
|
2090
|
+
* },
|
|
2091
|
+
* },
|
|
2092
|
+
* },
|
|
2093
|
+
* });
|
|
2094
|
+
* const [requiredArgument, optionalArgument, argumentWithDefault] =
|
|
2095
|
+
* Query.getFields().greeting.args;
|
|
2073
2096
|
*
|
|
2074
2097
|
* isRequiredArgument(requiredArgument); // => true
|
|
2075
2098
|
* isRequiredArgument(optionalArgument); // => false
|
|
@@ -2094,11 +2117,13 @@ export function isRequiredArgument(arg) {
|
|
|
2094
2117
|
* when the field is resolved.
|
|
2095
2118
|
* @example
|
|
2096
2119
|
* ```ts
|
|
2120
|
+
* import { GraphQLInterfaceType, GraphQLString } from 'graphql';
|
|
2121
|
+
*
|
|
2097
2122
|
* const EntityType = new GraphQLInterfaceType({
|
|
2098
2123
|
* name: 'Entity',
|
|
2099
2124
|
* fields: {
|
|
2100
|
-
* name: { type: GraphQLString }
|
|
2101
|
-
* }
|
|
2125
|
+
* name: { type: GraphQLString },
|
|
2126
|
+
* },
|
|
2102
2127
|
* });
|
|
2103
2128
|
* ```
|
|
2104
2129
|
*/
|
|
@@ -2120,7 +2145,8 @@ export class GraphQLInterfaceType {
|
|
|
2120
2145
|
* @param config - Configuration describing this object.
|
|
2121
2146
|
* @example
|
|
2122
2147
|
* ```ts
|
|
2123
|
-
* import
|
|
2148
|
+
* import assert from 'node:assert/strict';
|
|
2149
|
+
* import { parse, Kind } from 'graphql/language';
|
|
2124
2150
|
* import { GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from 'graphql/type';
|
|
2125
2151
|
*
|
|
2126
2152
|
* const document = parse(`
|
|
@@ -2136,6 +2162,8 @@ export class GraphQLInterfaceType {
|
|
|
2136
2162
|
* url: String
|
|
2137
2163
|
* }
|
|
2138
2164
|
* `);
|
|
2165
|
+
* assert(document.definitions[1].kind === Kind.INTERFACE_TYPE_DEFINITION);
|
|
2166
|
+
* assert(document.definitions[2].kind === Kind.INTERFACE_TYPE_EXTENSION);
|
|
2139
2167
|
*
|
|
2140
2168
|
* const Node = new GraphQLInterfaceType({
|
|
2141
2169
|
* name: 'Node',
|
|
@@ -2154,11 +2182,11 @@ export class GraphQLInterfaceType {
|
|
|
2154
2182
|
* resolveType: (value) => {
|
|
2155
2183
|
* return typeof value === 'object' && value != null && 'url' in value
|
|
2156
2184
|
* ? 'WebPage'
|
|
2157
|
-
* :
|
|
2185
|
+
* : undefined;
|
|
2158
2186
|
* },
|
|
2159
2187
|
* extensions: { abstract: true },
|
|
2160
2188
|
* astNode: document.definitions[1],
|
|
2161
|
-
* extensionASTNodes: [
|
|
2189
|
+
* extensionASTNodes: [document.definitions[2]],
|
|
2162
2190
|
* });
|
|
2163
2191
|
*
|
|
2164
2192
|
* Resource.name; // => 'Resource'
|
|
@@ -2376,17 +2404,30 @@ export class GraphQLInterfaceType {
|
|
|
2376
2404
|
* to determine which type is actually used when the field is resolved.
|
|
2377
2405
|
* @example
|
|
2378
2406
|
* ```ts
|
|
2407
|
+
* import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql';
|
|
2408
|
+
*
|
|
2409
|
+
* class Dog {}
|
|
2410
|
+
* class Cat {}
|
|
2411
|
+
* const DogType = new GraphQLObjectType({
|
|
2412
|
+
* name: 'Dog',
|
|
2413
|
+
* fields: { name: { type: GraphQLString } },
|
|
2414
|
+
* });
|
|
2415
|
+
* const CatType = new GraphQLObjectType({
|
|
2416
|
+
* name: 'Cat',
|
|
2417
|
+
* fields: { name: { type: GraphQLString } },
|
|
2418
|
+
* });
|
|
2419
|
+
*
|
|
2379
2420
|
* const PetType = new GraphQLUnionType({
|
|
2380
2421
|
* name: 'Pet',
|
|
2381
2422
|
* types: [DogType, CatType],
|
|
2382
2423
|
* resolveType: (value) => {
|
|
2383
2424
|
* if (value instanceof Dog) {
|
|
2384
|
-
* return
|
|
2425
|
+
* return 'Dog';
|
|
2385
2426
|
* }
|
|
2386
2427
|
* if (value instanceof Cat) {
|
|
2387
|
-
* return
|
|
2428
|
+
* return 'Cat';
|
|
2388
2429
|
* }
|
|
2389
|
-
* }
|
|
2430
|
+
* },
|
|
2390
2431
|
* });
|
|
2391
2432
|
* ```
|
|
2392
2433
|
*/
|
|
@@ -2408,14 +2449,21 @@ export class GraphQLUnionType {
|
|
|
2408
2449
|
* @param config - Configuration describing this object.
|
|
2409
2450
|
* @example
|
|
2410
2451
|
* ```ts
|
|
2411
|
-
* import
|
|
2412
|
-
* import {
|
|
2452
|
+
* import assert from 'node:assert/strict';
|
|
2453
|
+
* import { parse, Kind } from 'graphql/language';
|
|
2454
|
+
* import {
|
|
2455
|
+
* GraphQLObjectType,
|
|
2456
|
+
* GraphQLString,
|
|
2457
|
+
* GraphQLUnionType,
|
|
2458
|
+
* } from 'graphql/type';
|
|
2413
2459
|
*
|
|
2414
2460
|
* const document = parse(`
|
|
2415
2461
|
* union Media = Photo | Video
|
|
2416
2462
|
*
|
|
2417
2463
|
* extend union Media = Audio
|
|
2418
2464
|
* `);
|
|
2465
|
+
* assert(document.definitions[0].kind === Kind.UNION_TYPE_DEFINITION);
|
|
2466
|
+
* assert(document.definitions[1].kind === Kind.UNION_TYPE_EXTENSION);
|
|
2419
2467
|
*
|
|
2420
2468
|
* const Photo = new GraphQLObjectType({
|
|
2421
2469
|
* name: 'Photo',
|
|
@@ -2437,7 +2485,7 @@ export class GraphQLUnionType {
|
|
|
2437
2485
|
* },
|
|
2438
2486
|
* extensions: { searchable: true },
|
|
2439
2487
|
* astNode: document.definitions[0],
|
|
2440
|
-
* extensionASTNodes: [
|
|
2488
|
+
* extensionASTNodes: [document.definitions[1]],
|
|
2441
2489
|
* });
|
|
2442
2490
|
*
|
|
2443
2491
|
* Media.description; // => 'Media that can appear in a search result.'
|
|
@@ -2517,7 +2565,11 @@ export class GraphQLUnionType {
|
|
|
2517
2565
|
* @returns A configuration object that can be used to recreate this object.
|
|
2518
2566
|
* @example
|
|
2519
2567
|
* ```ts
|
|
2520
|
-
* import {
|
|
2568
|
+
* import {
|
|
2569
|
+
* GraphQLObjectType,
|
|
2570
|
+
* GraphQLString,
|
|
2571
|
+
* GraphQLUnionType,
|
|
2572
|
+
* } from 'graphql/type';
|
|
2521
2573
|
*
|
|
2522
2574
|
* const Photo = new GraphQLObjectType({
|
|
2523
2575
|
* name: 'Photo',
|
|
@@ -2584,7 +2636,11 @@ export class GraphQLUnionType {
|
|
|
2584
2636
|
* @returns The JSON-serializable representation.
|
|
2585
2637
|
* @example
|
|
2586
2638
|
* ```ts
|
|
2587
|
-
* import {
|
|
2639
|
+
* import {
|
|
2640
|
+
* GraphQLObjectType,
|
|
2641
|
+
* GraphQLString,
|
|
2642
|
+
* GraphQLUnionType,
|
|
2643
|
+
* } from 'graphql/type';
|
|
2588
2644
|
*
|
|
2589
2645
|
* const Photo = new GraphQLObjectType({
|
|
2590
2646
|
* name: 'Photo',
|
|
@@ -2662,7 +2718,8 @@ export class GraphQLEnumType {
|
|
|
2662
2718
|
* @param config - Configuration describing this object.
|
|
2663
2719
|
* @example
|
|
2664
2720
|
* ```ts
|
|
2665
|
-
* import
|
|
2721
|
+
* import assert from 'node:assert/strict';
|
|
2722
|
+
* import { parse, Kind } from 'graphql/language';
|
|
2666
2723
|
* import { GraphQLEnumType } from 'graphql/type';
|
|
2667
2724
|
*
|
|
2668
2725
|
* const document = parse(`
|
|
@@ -2676,6 +2733,8 @@ export class GraphQLEnumType {
|
|
|
2676
2733
|
* FORCE_AWAKENS
|
|
2677
2734
|
* }
|
|
2678
2735
|
* `);
|
|
2736
|
+
* assert(document.definitions[0].kind === Kind.ENUM_TYPE_DEFINITION);
|
|
2737
|
+
* assert(document.definitions[1].kind === Kind.ENUM_TYPE_EXTENSION);
|
|
2679
2738
|
* const definition = document.definitions[0];
|
|
2680
2739
|
*
|
|
2681
2740
|
* const Episode = new GraphQLEnumType({
|
|
@@ -2686,24 +2745,24 @@ export class GraphQLEnumType {
|
|
|
2686
2745
|
* value: 4,
|
|
2687
2746
|
* description: 'Released in 1977.',
|
|
2688
2747
|
* extensions: { trilogy: 'original' },
|
|
2689
|
-
* astNode: definition.values[0],
|
|
2748
|
+
* astNode: definition.values?.[0],
|
|
2690
2749
|
* },
|
|
2691
|
-
* EMPIRE: { value: 5, astNode: definition.values[1] },
|
|
2750
|
+
* EMPIRE: { value: 5, astNode: definition.values?.[1] },
|
|
2692
2751
|
* JEDI: {
|
|
2693
2752
|
* value: 6,
|
|
2694
2753
|
* deprecationReason: 'Use RETURN_OF_THE_JEDI.',
|
|
2695
|
-
* astNode: definition.values[2],
|
|
2754
|
+
* astNode: definition.values?.[2],
|
|
2696
2755
|
* },
|
|
2697
2756
|
* },
|
|
2698
2757
|
* extensions: { catalog: 'films' },
|
|
2699
2758
|
* astNode: definition,
|
|
2700
|
-
* extensionASTNodes: [
|
|
2759
|
+
* extensionASTNodes: [document.definitions[1]],
|
|
2701
2760
|
* });
|
|
2702
2761
|
*
|
|
2703
2762
|
* Episode.description; // => 'A Star Wars film episode.'
|
|
2704
2763
|
* Episode.serialize(5); // => 'EMPIRE'
|
|
2705
2764
|
* Episode.parseValue('JEDI'); // => 6
|
|
2706
|
-
* Episode.getValue('JEDI')
|
|
2765
|
+
* Episode.getValue('JEDI')?.deprecationReason; // => 'Use RETURN_OF_THE_JEDI.'
|
|
2707
2766
|
* Episode.extensions; // => { catalog: 'films' }
|
|
2708
2767
|
* ```
|
|
2709
2768
|
*/
|
|
@@ -2843,6 +2902,7 @@ export class GraphQLEnumType {
|
|
|
2843
2902
|
/**
|
|
2844
2903
|
* Parses a GraphQL enum name from variable input.
|
|
2845
2904
|
* @param inputValue - Runtime input value to parse.
|
|
2905
|
+
* @param hideSuggestions - Omit suggestions from error messages.
|
|
2846
2906
|
* @returns The internal enum value represented by the input name.
|
|
2847
2907
|
* @example
|
|
2848
2908
|
* ```ts
|
|
@@ -2863,13 +2923,13 @@ export class GraphQLEnumType {
|
|
|
2863
2923
|
* ```
|
|
2864
2924
|
*/
|
|
2865
2925
|
|
|
2866
|
-
parseValue(inputValue) /* T */
|
|
2926
|
+
parseValue(inputValue, hideSuggestions) /* T */
|
|
2867
2927
|
{
|
|
2868
2928
|
if (typeof inputValue !== 'string') {
|
|
2869
2929
|
const valueStr = inspect(inputValue);
|
|
2870
2930
|
throw new GraphQLError(
|
|
2871
2931
|
`Enum "${this.name}" cannot represent non-string value: ${valueStr}.` +
|
|
2872
|
-
didYouMeanEnumValue(this, valueStr),
|
|
2932
|
+
(hideSuggestions ? '' : didYouMeanEnumValue(this, valueStr)),
|
|
2873
2933
|
);
|
|
2874
2934
|
}
|
|
2875
2935
|
|
|
@@ -2878,7 +2938,7 @@ export class GraphQLEnumType {
|
|
|
2878
2938
|
if (enumValue == null) {
|
|
2879
2939
|
throw new GraphQLError(
|
|
2880
2940
|
`Value "${inputValue}" does not exist in "${this.name}" enum.` +
|
|
2881
|
-
didYouMeanEnumValue(this, inputValue),
|
|
2941
|
+
(hideSuggestions ? '' : didYouMeanEnumValue(this, inputValue)),
|
|
2882
2942
|
);
|
|
2883
2943
|
}
|
|
2884
2944
|
|
|
@@ -2888,6 +2948,7 @@ export class GraphQLEnumType {
|
|
|
2888
2948
|
* Parses a GraphQL enum name from an AST value literal.
|
|
2889
2949
|
* @param valueNode - AST value literal to parse.
|
|
2890
2950
|
* @param _variables - Runtime variable values; ignored because enum literals cannot contain variables.
|
|
2951
|
+
* @param hideSuggestions - Omit suggestions from error messages.
|
|
2891
2952
|
* @returns The internal enum value represented by the literal.
|
|
2892
2953
|
* @example
|
|
2893
2954
|
* ```ts
|
|
@@ -2903,19 +2964,19 @@ export class GraphQLEnumType {
|
|
|
2903
2964
|
* },
|
|
2904
2965
|
* });
|
|
2905
2966
|
*
|
|
2906
|
-
* RGB.parseLiteral(parseValue('RED')); // => 0
|
|
2907
|
-
* RGB.parseLiteral(parseValue('"RED"')); // throws an error
|
|
2967
|
+
* RGB.parseLiteral(parseValue('RED'), undefined); // => 0
|
|
2968
|
+
* RGB.parseLiteral(parseValue('"RED"'), undefined); // throws an error
|
|
2908
2969
|
* ```
|
|
2909
2970
|
*/
|
|
2910
2971
|
|
|
2911
|
-
parseLiteral(valueNode, _variables) /* T */
|
|
2972
|
+
parseLiteral(valueNode, _variables, hideSuggestions) /* T */
|
|
2912
2973
|
{
|
|
2913
2974
|
// Note: variables will be resolved to a value before calling this function.
|
|
2914
2975
|
if (valueNode.kind !== Kind.ENUM) {
|
|
2915
2976
|
const valueStr = print(valueNode);
|
|
2916
2977
|
throw new GraphQLError(
|
|
2917
2978
|
`Enum "${this.name}" cannot represent non-enum value: ${valueStr}.` +
|
|
2918
|
-
didYouMeanEnumValue(this, valueStr),
|
|
2979
|
+
(hideSuggestions ? '' : didYouMeanEnumValue(this, valueStr)),
|
|
2919
2980
|
{
|
|
2920
2981
|
nodes: valueNode,
|
|
2921
2982
|
},
|
|
@@ -2928,7 +2989,7 @@ export class GraphQLEnumType {
|
|
|
2928
2989
|
const valueStr = print(valueNode);
|
|
2929
2990
|
throw new GraphQLError(
|
|
2930
2991
|
`Value "${valueStr}" does not exist in "${this.name}" enum.` +
|
|
2931
|
-
didYouMeanEnumValue(this, valueStr),
|
|
2992
|
+
(hideSuggestions ? '' : didYouMeanEnumValue(this, valueStr)),
|
|
2932
2993
|
{
|
|
2933
2994
|
nodes: valueNode,
|
|
2934
2995
|
},
|
|
@@ -3073,13 +3134,15 @@ function defineEnumValues(typeName, valueMap) {
|
|
|
3073
3134
|
* Using `NonNull` will ensure that a value must be provided by the query
|
|
3074
3135
|
* @example
|
|
3075
3136
|
* ```ts
|
|
3137
|
+
* import { GraphQLFloat, GraphQLInputObjectType, GraphQLNonNull } from 'graphql';
|
|
3138
|
+
*
|
|
3076
3139
|
* const GeoPoint = new GraphQLInputObjectType({
|
|
3077
3140
|
* name: 'GeoPoint',
|
|
3078
3141
|
* fields: {
|
|
3079
3142
|
* lat: { type: new GraphQLNonNull(GraphQLFloat) },
|
|
3080
3143
|
* lon: { type: new GraphQLNonNull(GraphQLFloat) },
|
|
3081
3144
|
* alt: { type: GraphQLFloat, defaultValue: 0 },
|
|
3082
|
-
* }
|
|
3145
|
+
* },
|
|
3083
3146
|
* });
|
|
3084
3147
|
* ```
|
|
3085
3148
|
*/
|
|
@@ -3101,7 +3164,8 @@ export class GraphQLInputObjectType {
|
|
|
3101
3164
|
* @param config - Configuration describing this object.
|
|
3102
3165
|
* @example
|
|
3103
3166
|
* ```ts
|
|
3104
|
-
* import
|
|
3167
|
+
* import assert from 'node:assert/strict';
|
|
3168
|
+
* import { parse, Kind } from 'graphql/language';
|
|
3105
3169
|
* import {
|
|
3106
3170
|
* GraphQLID,
|
|
3107
3171
|
* GraphQLInputObjectType,
|
|
@@ -3120,6 +3184,8 @@ export class GraphQLInputObjectType {
|
|
|
3120
3184
|
* body: String
|
|
3121
3185
|
* }
|
|
3122
3186
|
* `);
|
|
3187
|
+
* assert(document.definitions[0].kind === Kind.INPUT_OBJECT_TYPE_DEFINITION);
|
|
3188
|
+
* assert(document.definitions[1].kind === Kind.INPUT_OBJECT_TYPE_EXTENSION);
|
|
3123
3189
|
* const definition = document.definitions[0];
|
|
3124
3190
|
*
|
|
3125
3191
|
* const ReviewInput = new GraphQLInputObjectType({
|
|
@@ -3130,18 +3196,18 @@ export class GraphQLInputObjectType {
|
|
|
3130
3196
|
* description: 'Star rating from one to five.',
|
|
3131
3197
|
* type: new GraphQLNonNull(GraphQLInt),
|
|
3132
3198
|
* extensions: { min: 1, max: 5 },
|
|
3133
|
-
* astNode: definition.fields[0],
|
|
3199
|
+
* astNode: definition.fields?.[0],
|
|
3134
3200
|
* },
|
|
3135
3201
|
* commentary: {
|
|
3136
3202
|
* type: GraphQLString,
|
|
3137
3203
|
* defaultValue: '',
|
|
3138
3204
|
* deprecationReason: 'Use body.',
|
|
3139
|
-
* astNode: definition.fields[1],
|
|
3205
|
+
* astNode: definition.fields?.[1],
|
|
3140
3206
|
* },
|
|
3141
3207
|
* },
|
|
3142
3208
|
* extensions: { form: 'review' },
|
|
3143
3209
|
* astNode: definition,
|
|
3144
|
-
* extensionASTNodes: [
|
|
3210
|
+
* extensionASTNodes: [document.definitions[1]],
|
|
3145
3211
|
* isOneOf: false,
|
|
3146
3212
|
* });
|
|
3147
3213
|
* const SearchBy = new GraphQLInputObjectType({
|
|
@@ -3353,19 +3419,26 @@ function defineInputFieldMap(config) {
|
|
|
3353
3419
|
* @example
|
|
3354
3420
|
* ```ts
|
|
3355
3421
|
* import {
|
|
3422
|
+
* GraphQLInputObjectType,
|
|
3356
3423
|
* GraphQLInt,
|
|
3357
3424
|
* GraphQLNonNull,
|
|
3358
3425
|
* GraphQLString,
|
|
3359
3426
|
* isRequiredInputField,
|
|
3360
3427
|
* } from 'graphql/type';
|
|
3361
3428
|
*
|
|
3362
|
-
* const
|
|
3363
|
-
*
|
|
3364
|
-
*
|
|
3365
|
-
*
|
|
3366
|
-
*
|
|
3367
|
-
*
|
|
3368
|
-
*
|
|
3429
|
+
* const Input = new GraphQLInputObjectType({
|
|
3430
|
+
* name: 'Input',
|
|
3431
|
+
* fields: {
|
|
3432
|
+
* id: { type: new GraphQLNonNull(GraphQLInt) },
|
|
3433
|
+
* name: { type: GraphQLString },
|
|
3434
|
+
* limit: { type: new GraphQLNonNull(GraphQLInt), defaultValue: 10 },
|
|
3435
|
+
* },
|
|
3436
|
+
* });
|
|
3437
|
+
* const {
|
|
3438
|
+
* id: requiredField,
|
|
3439
|
+
* name: optionalField,
|
|
3440
|
+
* limit: fieldWithDefault,
|
|
3441
|
+
* } = Input.getFields();
|
|
3369
3442
|
*
|
|
3370
3443
|
* isRequiredInputField(requiredField); // => true
|
|
3371
3444
|
* isRequiredInputField(optionalField); // => false
|
package/type/directives.d.ts
CHANGED
|
@@ -88,7 +88,8 @@ export declare class GraphQLDirective {
|
|
|
88
88
|
* @param config - Configuration describing this object.
|
|
89
89
|
* @example
|
|
90
90
|
* ```ts
|
|
91
|
-
* import
|
|
91
|
+
* import assert from 'node:assert/strict';
|
|
92
|
+
* import { DirectiveLocation, parse, Kind } from 'graphql/language';
|
|
92
93
|
* import {
|
|
93
94
|
* GraphQLBoolean,
|
|
94
95
|
* GraphQLDirective,
|
|
@@ -96,10 +97,15 @@ export declare class GraphQLDirective {
|
|
|
96
97
|
* GraphQLNonNull,
|
|
97
98
|
* } from 'graphql/type';
|
|
98
99
|
*
|
|
99
|
-
* const document = parse(
|
|
100
|
+
* const document = parse(
|
|
101
|
+
* `
|
|
100
102
|
* directive @cacheControl(maxAge: Int) repeatable on FIELD_DEFINITION
|
|
101
|
-
* extend directive @cacheControl
|
|
102
|
-
*
|
|
103
|
+
* extend directive @cacheControl @tag
|
|
104
|
+
* `,
|
|
105
|
+
* { experimentalDirectivesOnDirectiveDefinitions: true },
|
|
106
|
+
* );
|
|
107
|
+
* assert(document.definitions[0].kind === Kind.DIRECTIVE_DEFINITION);
|
|
108
|
+
* assert(document.definitions[1].kind === Kind.DIRECTIVE_EXTENSION);
|
|
103
109
|
* const definition = document.definitions[0];
|
|
104
110
|
*
|
|
105
111
|
* const cacheControl = new GraphQLDirective({
|
|
@@ -116,14 +122,14 @@ export declare class GraphQLDirective {
|
|
|
116
122
|
* },
|
|
117
123
|
* maxAge: {
|
|
118
124
|
* type: GraphQLInt,
|
|
119
|
-
* astNode: definition.arguments[0],
|
|
125
|
+
* astNode: definition.arguments?.[0],
|
|
120
126
|
* },
|
|
121
127
|
* },
|
|
122
128
|
* isRepeatable: true,
|
|
123
129
|
* deprecationReason: 'Use @cache instead.',
|
|
124
130
|
* extensions: { scope: 'cache' },
|
|
125
131
|
* astNode: definition,
|
|
126
|
-
* extensionASTNodes: [
|
|
132
|
+
* extensionASTNodes: [document.definitions[1]],
|
|
127
133
|
* });
|
|
128
134
|
*
|
|
129
135
|
* cacheControl.name; // => 'cacheControl'
|