Skip to content

Commit b076d8a

Browse files
committed
integrate logic from graphql#4519
1 parent ed5a382 commit b076d8a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/validation/rules/ValuesOfCorrectTypeRule.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ export function ValuesOfCorrectTypeRule(
116116
EnumValue: (node) => isValidValueNode(context, node),
117117
IntValue: (node) => isValidValueNode(context, node),
118118
FloatValue: (node) => isValidValueNode(context, node),
119-
StringValue: (node, key) => key !== 'description' && isValidValueNode(context, node),
119+
// Descriptions are string values that would not validate according
120+
// to the below logic, but since (per the specification) descriptions must
121+
// not affect validation, they are ignored entirely when visiting the AST
122+
// and do not require special handling.
123+
// See https://spec.graphql.org/draft/#sec-Descriptions
124+
StringValue: (node) => isValidValueNode(context, node),
120125
BooleanValue: (node) => isValidValueNode(context, node),
121126
};
122127
}

src/validation/validate.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { devAssert } from '../jsutils/devAssert';
2+
import { mapValue } from '../jsutils/mapValue';
23
import type { Maybe } from '../jsutils/Maybe';
34

45
import { GraphQLError } from '../error/GraphQLError';
56

6-
import type { DocumentNode } from '../language/ast';
7+
import { type DocumentNode, QueryDocumentKeys } from '../language/ast';
78
import { visit, visitInParallel } from '../language/visitor';
89

910
import type { GraphQLSchema } from '../type/schema';
@@ -15,6 +16,13 @@ import { specifiedRules, specifiedSDLRules } from './specifiedRules';
1516
import type { SDLValidationRule, ValidationRule } from './ValidationContext';
1617
import { SDLValidationContext, ValidationContext } from './ValidationContext';
1718

19+
// Per the specification, descriptions must not affect validation.
20+
// See https://spec.graphql.org/draft/#sec-Descriptions
21+
const QueryDocumentKeysToValidate = mapValue(
22+
QueryDocumentKeys,
23+
(keys: ReadonlyArray<string>) => keys.filter((key) => key !== 'description'),
24+
);
25+
1826
/**
1927
* Implements the "Validation" section of the spec.
2028
*
@@ -76,7 +84,11 @@ export function validate(
7684

7785
// Visit the whole document with each instance of all provided rules.
7886
try {
79-
visit(documentAST, visitWithTypeInfo(typeInfo, visitor));
87+
visit(
88+
documentAST,
89+
visitWithTypeInfo(typeInfo, visitor),
90+
QueryDocumentKeysToValidate,
91+
);
8092
} catch (e) {
8193
if (e !== abortObj) {
8294
throw e;

0 commit comments

Comments
 (0)