Skip to content

Commit 0c7165a

Browse files
Improve documentation of validation rules (#3285)
* Added missing documentation * Added links to GraphQL spec
1 parent ac8f0c6 commit 0c7165a

22 files changed

+54
-1
lines changed

src/validation/rules/ExecutableDefinitionsRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type { ASTValidationContext } from '../ValidationContext';
1111
*
1212
* A GraphQL document is only valid for execution if all definitions are either
1313
* operation or fragment definitions.
14+
*
15+
* See https://spec.graphql.org/draft/#sec-Executable-Definitions
1416
*/
1517
export function ExecutableDefinitionsRule(
1618
context: ASTValidationContext,

src/validation/rules/FieldsOnCorrectTypeRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import type { ValidationContext } from '../ValidationContext';
2626
*
2727
* A GraphQL document is only valid if all fields selected are defined by the
2828
* parent type, or are an allowed meta field such as __typename.
29+
*
30+
* See https://spec.graphql.org/draft/#sec-Field-Selections
2931
*/
3032
export function FieldsOnCorrectTypeRule(
3133
context: ValidationContext,

src/validation/rules/FragmentsOnCompositeTypesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type { ValidationContext } from '../ValidationContext';
1515
* Fragments use a type condition to determine if they apply, since fragments
1616
* can only be spread into a composite type (object, interface, or union), the
1717
* type condition must also be a composite type.
18+
*
19+
* See https://spec.graphql.org/draft/#sec-Fragments-On-Composite-Types
1820
*/
1921
export function FragmentsOnCompositeTypesRule(
2022
context: ValidationContext,

src/validation/rules/KnownArgumentNamesRule.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import type {
1818
*
1919
* A GraphQL field is only valid if all supplied arguments are defined by
2020
* that field.
21+
*
22+
* See https://spec.graphql.org/draft/#sec-Argument-Names
23+
* See https://spec.graphql.org/draft/#sec-Directives-Are-In-Valid-Locations
2124
*/
2225
export function KnownArgumentNamesRule(context: ValidationContext): ASTVisitor {
2326
return {

src/validation/rules/KnownDirectivesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import type {
2121
*
2222
* A GraphQL document is only valid if all `@directives` are known by the
2323
* schema and legally positioned.
24+
*
25+
* See https://spec.graphql.org/draft/#sec-Directives-Are-Defined
2426
*/
2527
export function KnownDirectivesRule(
2628
context: ValidationContext | SDLValidationContext,

src/validation/rules/KnownFragmentNamesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { ValidationContext } from '../ValidationContext';
99
*
1010
* A GraphQL document is only valid if all `...Fragment` fragment spreads refer
1111
* to fragments defined in the same document.
12+
*
13+
* See https://spec.graphql.org/draft/#sec-Fragment-spread-target-defined
1214
*/
1315
export function KnownFragmentNamesRule(context: ValidationContext): ASTVisitor {
1416
return {

src/validation/rules/KnownTypeNamesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import type {
2424
*
2525
* A GraphQL document is only valid if referenced types (specifically
2626
* variable definitions and fragment conditions) are defined by the type schema.
27+
*
28+
* See https://spec.graphql.org/draft/#sec-Fragment-Spread-Type-Existence
2729
*/
2830
export function KnownTypeNamesRule(
2931
context: ValidationContext | SDLValidationContext,

src/validation/rules/LoneAnonymousOperationRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type { ASTValidationContext } from '../ValidationContext';
1010
*
1111
* A GraphQL document is only valid if when it contains an anonymous operation
1212
* (the query short-hand) that it contains only that one operation definition.
13+
*
14+
* See https://spec.graphql.org/draft/#sec-Lone-Anonymous-Operation
1315
*/
1416
export function LoneAnonymousOperationRule(
1517
context: ASTValidationContext,

src/validation/rules/NoFragmentCyclesRule.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import type { ASTVisitor } from '../../language/visitor';
1010

1111
import type { ASTValidationContext } from '../ValidationContext';
1212

13+
/**
14+
* No fragment cycles
15+
*
16+
* The graph of fragment spreads must not form any cycles including spreading itself.
17+
* Otherwise an operation could infinitely spread or infinitely execute on cycles in the underlying data.
18+
*
19+
* See https://spec.graphql.org/draft/#sec-Fragment-spreads-must-not-form-cycles
20+
*/
1321
export function NoFragmentCyclesRule(
1422
context: ASTValidationContext,
1523
): ASTVisitor {

src/validation/rules/NoUndefinedVariablesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { ValidationContext } from '../ValidationContext';
99
*
1010
* A GraphQL operation is only valid if all variables encountered, both directly
1111
* and via fragment spreads, are defined by that operation.
12+
*
13+
* See https://spec.graphql.org/draft/#sec-All-Variable-Uses-Defined
1214
*/
1315
export function NoUndefinedVariablesRule(
1416
context: ValidationContext,

src/validation/rules/NoUnusedFragmentsRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { ASTValidationContext } from '../ValidationContext';
1313
*
1414
* A GraphQL document is only valid if all fragment definitions are spread
1515
* within operations, or spread within other fragments spread within operations.
16+
*
17+
* See https://spec.graphql.org/draft/#sec-Fragments-Must-Be-Used
1618
*/
1719
export function NoUnusedFragmentsRule(
1820
context: ASTValidationContext,

src/validation/rules/NoUnusedVariablesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type { ValidationContext } from '../ValidationContext';
1010
*
1111
* A GraphQL operation is only valid if all variables defined by an operation
1212
* are used, either directly or within a spread fragment.
13+
*
14+
* See https://spec.graphql.org/draft/#sec-All-Variables-Used
1315
*/
1416
export function NoUnusedVariablesRule(context: ValidationContext): ASTVisitor {
1517
let variableDefs: Array<VariableDefinitionNode> = [];

src/validation/rules/OverlappingFieldsCanBeMergedRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function reasonMessage(reason: ConflictReasonMessage): string {
5353
* A selection set is only valid if all fields (including spreading any
5454
* fragments) either correspond to distinct response names or can be merged
5555
* without ambiguity.
56+
*
57+
* See https://spec.graphql.org/draft/#sec-Field-Selection-Merging
5658
*/
5759
export function OverlappingFieldsCanBeMergedRule(
5860
context: ValidationContext,

src/validation/rules/SingleFieldSubscriptionsRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { ValidationContext } from '../ValidationContext';
1717
*
1818
* A GraphQL subscription is valid only if it contains a single root field and
1919
* that root field is not an introspection field.
20+
*
21+
* See https://spec.graphql.org/draft/#sec-Single-root-field
2022
*/
2123
export function SingleFieldSubscriptionsRule(
2224
context: ValidationContext,

src/validation/rules/UniqueArgumentNamesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { ASTValidationContext } from '../ValidationContext';
88
*
99
* A GraphQL field or directive is only valid if all supplied arguments are
1010
* uniquely named.
11+
*
12+
* See https://spec.graphql.org/draft/#sec-Argument-Names
1113
*/
1214
export function UniqueArgumentNamesRule(
1315
context: ASTValidationContext,

src/validation/rules/UniqueDirectivesPerLocationRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import type {
1919
*
2020
* A GraphQL document is only valid if all non-repeatable directives at
2121
* a given location are uniquely named.
22+
*
23+
* See https://spec.graphql.org/draft/#sec-Directives-Are-Unique-Per-Location
2224
*/
2325
export function UniqueDirectivesPerLocationRule(
2426
context: ValidationContext | SDLValidationContext,

src/validation/rules/UniqueFragmentNamesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { ASTValidationContext } from '../ValidationContext';
88
* Unique fragment names
99
*
1010
* A GraphQL document is only valid if all defined fragments have unique names.
11+
*
12+
* See https://spec.graphql.org/draft/#sec-Fragment-Name-Uniqueness
1113
*/
1214
export function UniqueFragmentNamesRule(
1315
context: ASTValidationContext,

src/validation/rules/UniqueInputFieldNamesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { ASTValidationContext } from '../ValidationContext';
1313
*
1414
* A GraphQL input object value is only valid if all supplied fields are
1515
* uniquely named.
16+
*
17+
* See https://spec.graphql.org/draft/#sec-Input-Object-Field-Uniqueness
1618
*/
1719
export function UniqueInputFieldNamesRule(
1820
context: ASTValidationContext,

src/validation/rules/UniqueOperationNamesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { ASTValidationContext } from '../ValidationContext';
88
* Unique operation names
99
*
1010
* A GraphQL document is only valid if all defined operations have unique names.
11+
*
12+
* See https://spec.graphql.org/draft/#sec-Operation-Name-Uniqueness
1113
*/
1214
export function UniqueOperationNamesRule(
1315
context: ASTValidationContext,

src/validation/rules/ValuesOfCorrectTypeRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import type { ValidationContext } from '../ValidationContext';
2626
*
2727
* A GraphQL document is only valid if all value literals are of the type
2828
* expected at their position.
29+
*
30+
* See https://spec.graphql.org/draft/#sec-Values-of-Correct-Type
2931
*/
3032
export function ValuesOfCorrectTypeRule(
3133
context: ValidationContext,

src/validation/rules/VariablesAreInputTypesRule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type { ValidationContext } from '../ValidationContext';
1515
*
1616
* A GraphQL operation is only valid if all the variables it defines are of
1717
* input types (scalar, enum, or input object).
18+
*
19+
* See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types
1820
*/
1921
export function VariablesAreInputTypesRule(
2022
context: ValidationContext,

src/validation/rules/VariablesInAllowedPositionRule.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import { isTypeSubTypeOf } from '../../utilities/typeComparators';
1717
import type { ValidationContext } from '../ValidationContext';
1818

1919
/**
20-
* Variables passed to field arguments conform to type
20+
* Variables in allowed position
21+
*
22+
* Variable usages must be compatible with the arguments they are passed to.
23+
*
24+
* See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed
2125
*/
2226
export function VariablesInAllowedPositionRule(
2327
context: ValidationContext,

0 commit comments

Comments
 (0)