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):

src/graphql/validation/rules/no_unused_fragments.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class NoUnusedFragmentsRule(ASTValidationRule):
1717
1818
A GraphQL document is only valid if all fragment definitions are spread within
1919
operations, or spread within other fragments spread within operations.
20+
21+
See https://spec.graphql.org/draft/#sec-Fragments-Must-Be-Used
2022
"""
2123

2224
def __init__(self, context: ASTValidationContext):

src/graphql/validation/rules/no_unused_variables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class NoUnusedVariablesRule(ValidationRule):
1212
1313
A GraphQL operation is only valid if all variables defined by an operation are used,
1414
either directly or within a spread fragment.
15+
16+
See https://spec.graphql.org/draft/#sec-All-Variables-Used
1517
"""
1618

1719
def __init__(self, context: ValidationContext):

src/graphql/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class OverlappingFieldsCanBeMergedRule(ValidationRule):
4949
5050
A selection set is only valid if all fields (including spreading any fragments)
5151
either correspond to distinct response names or can be merged without ambiguity.
52+
53+
See https://spec.graphql.org/draft/#sec-Field-Selection-Mergin
5254
"""
5355

5456
def __init__(self, context: ValidationContext):

src/graphql/validation/rules/single_field_subscriptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class SingleFieldSubscriptionsRule(ValidationRule):
1818
1919
A GraphQL subscription is valid only if it contains a single root field and
2020
that root field is not an introspection field.
21+
22+
See https://spec.graphql.org/draft/#sec-Single-root-field
2123
"""
2224

2325
def enter_operation_definition(

src/graphql/validation/rules/unique_argument_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class UniqueArgumentNamesRule(ASTValidationRule):
1212
1313
A GraphQL field or directive is only valid if all supplied arguments are uniquely
1414
named.
15+
16+
See https://spec.graphql.org/draft/#sec-Argument-Names
1517
"""
1618

1719
def __init__(self, context: ASTValidationContext):

src/graphql/validation/rules/unique_directives_per_location.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class UniqueDirectivesPerLocationRule(ASTValidationRule):
2424
2525
A GraphQL document is only valid if all non-repeatable directives at a given
2626
location are uniquely named.
27+
28+
See https://spec.graphql.org/draft/#sec-Directives-Are-Unique-Per-Location
2729
"""
2830

2931
context: Union[ValidationContext, SDLValidationContext]

src/graphql/validation/rules/unique_fragment_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class UniqueFragmentNamesRule(ASTValidationRule):
1111
"""Unique fragment names
1212
1313
A GraphQL document is only valid if all defined fragments have unique names.
14+
15+
See https://spec.graphql.org/draft/#sec-Fragment-Name-Uniqueness
1416
"""
1517

1618
def __init__(self, context: ASTValidationContext):

src/graphql/validation/rules/unique_input_field_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class UniqueInputFieldNamesRule(ASTValidationRule):
1212
1313
A GraphQL input object value is only valid if all supplied fields are uniquely
1414
named.
15+
16+
See https://spec.graphql.org/draft/#sec-Input-Object-Field-Uniqueness
1517
"""
1618

1719
def __init__(self, context: ASTValidationContext):

src/graphql/validation/rules/unique_operation_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class UniqueOperationNamesRule(ASTValidationRule):
1111
"""Unique operation names
1212
1313
A GraphQL document is only valid if all defined operations have unique names.
14+
15+
See https://spec.graphql.org/draft/#sec-Operation-Name-Uniqueness
1416
"""
1517

1618
def __init__(self, context: ASTValidationContext):

src/graphql/validation/rules/values_of_correct_type.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class ValuesOfCorrectTypeRule(ValidationRule):
3838
3939
A GraphQL document is only valid if all value literals are of the type expected at
4040
their position.
41+
42+
See https://spec.graphql.org/draft/#sec-Values-of-Correct-Type
4143
"""
4244

4345
def enter_list_value(self, node: ListValueNode, *_args: Any) -> VisitorAction:

src/graphql/validation/rules/variables_are_input_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class VariablesAreInputTypesRule(ValidationRule):
1414
1515
A GraphQL operation is only valid if all the variables it defines are of input types
1616
(scalar, enum, or input object).
17+
18+
See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types
1719
"""
1820

1921
def enter_variable_definition(

src/graphql/validation/rules/variables_in_allowed_position.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616

1717

1818
class VariablesInAllowedPositionRule(ValidationRule):
19-
"""Variables passed to field arguments conform to type"""
19+
"""Variables in allowed position
20+
21+
Variable usages must be compatible with the arguments they are passed to.
22+
23+
See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed
24+
"""
2025

2126
def __init__(self, context: ValidationContext):
2227
super().__init__(context)

0 commit comments

Comments
 (0)