Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c7165a

Browse files
Improve documentation of validation rules (graphql#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,

0 commit comments

Comments
 (0)