Skip to content

Commit fa23fe3

Browse files
committed
Improve documentation of validation rules
Add links to the specification for GraphQL Replicates graphql/graphql-js@0c7165a
1 parent cf2f10f commit fa23fe3

22 files changed

+55
-2
lines changed

src/graphql/validation/rules/executable_definitions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ExecutableDefinitionsRule(ASTValidationRule):
2121
2222
A GraphQL document is only valid for execution if all definitions are either
2323
operation or fragment definitions.
24+
25+
See https://spec.graphql.org/draft/#sec-Executable-Definitions
2426
"""
2527

2628
def enter_document(self, node: DocumentNode, *_args: Any) -> VisitorAction:

src/graphql/validation/rules/fields_on_correct_type.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class FieldsOnCorrectTypeRule(ValidationRule):
2525
2626
A GraphQL document is only valid if all fields selected are defined by the parent
2727
type, or are an allowed meta field such as ``__typename``.
28+
29+
See https://spec.graphql.org/draft/#sec-Field-Selections
2830
"""
2931

3032
def enter_field(self, node: FieldNode, *_args: Any) -> None:

src/graphql/validation/rules/fragments_on_composite_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class FragmentsOnCompositeTypesRule(ValidationRule):
1919
Fragments use a type condition to determine if they apply, since fragments can only
2020
be spread into a composite type (object, interface, or union), the type condition
2121
must also be a composite type.
22+
23+
See https://spec.graphql.org/draft/#sec-Fragments-On-Composite-Types
2224
"""
2325

2426
def enter_inline_fragment(self, node: InlineFragmentNode, *_args: Any) -> None:

src/graphql/validation/rules/known_argument_names.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class KnownArgumentNamesRule(KnownArgumentNamesOnDirectivesRule):
6868
"""Known argument names
6969
7070
A GraphQL field is only valid if all supplied arguments are defined by that field.
71+
72+
See https://spec.graphql.org/draft/#sec-Argument-Names
73+
See https://spec.graphql.org/draft/#sec-Directives-Are-In-Valid-Locations
7174
"""
7275

7376
context: ValidationContext

src/graphql/validation/rules/known_directives.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class KnownDirectivesRule(ASTValidationRule):
1919
2020
A GraphQL document is only valid if all ``@directives`` are known by the schema and
2121
legally positioned.
22+
23+
See https://spec.graphql.org/draft/#sec-Directives-Are-Defined
2224
"""
2325

2426
context: Union[ValidationContext, SDLValidationContext]

src/graphql/validation/rules/known_fragment_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class KnownFragmentNamesRule(ValidationRule):
1212
1313
A GraphQL document is only valid if all ``...Fragment`` fragment spreads refer to
1414
fragments defined in the same document.
15+
16+
See https://spec.graphql.org/draft/#sec-Fragment-spread-target-defined
1517
"""
1618

1719
def enter_fragment_spread(self, node: FragmentSpreadNode, *_args: Any) -> None:

src/graphql/validation/rules/known_type_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class KnownTypeNamesRule(ASTValidationRule):
2121
2222
A GraphQL document is only valid if referenced types (specifically variable
2323
definitions and fragment conditions) are defined by the type schema.
24+
25+
See https://spec.graphql.org/draft/#sec-Fragment-Spread-Type-Existence
2426
"""
2527

2628
def __init__(self, context: Union[ValidationContext, SDLValidationContext]):

src/graphql/validation/rules/lone_anonymous_operation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class LoneAnonymousOperationRule(ASTValidationRule):
1212
1313
A GraphQL document is only valid if when it contains an anonymous operation
1414
(the query short-hand) that it contains only that one operation definition.
15+
16+
See https://spec.graphql.org/draft/#sec-Lone-Anonymous-Operation
1517
"""
1618

1719
def __init__(self, context: ASTValidationContext):

src/graphql/validation/rules/no_fragment_cycles.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99

1010
class NoFragmentCyclesRule(ASTValidationRule):
11-
"""No fragment cycles"""
11+
"""No fragment cycles
12+
13+
The graph of fragment spreads must not form any cycles including spreading itself.
14+
Otherwise an operation could infinitely spread or infinitely execute on cycles in
15+
the underlying data.
16+
17+
See https://spec.graphql.org/draft/#sec-Fragment-spreads-must-not-form-cycles
18+
"""
1219

1320
def __init__(self, context: ASTValidationContext):
1421
super().__init__(context)

src/graphql/validation/rules/no_undefined_variables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class NoUndefinedVariablesRule(ValidationRule):
1212
1313
A GraphQL operation is only valid if all variables encountered, both directly and
1414
via fragment spreads, are defined by that operation.
15+
16+
See https://spec.graphql.org/draft/#sec-All-Variable-Uses-Defined
1517
"""
1618

1719
def __init__(self, context: ValidationContext):

0 commit comments

Comments
 (0)