Enum Class OperationValidationRule
- All Implemented Interfaces:
Serializable, Comparable<OperationValidationRule>, Constable
This enum is used with OperationValidator to selectively enable or disable
individual validation rules via a Predicate<OperationValidationRule>.
Rule Categories by Traversal Behavior
The OperationValidator tracks two independent state variables during traversal:
fragmentRetraversalDepth (0 = primary traversal, >0 = inside fragment retraversal)
and operationScope (true = inside an operation, false = outside).
This creates three possible traversal states:
┌────────────────────────────────────┬──────────────────────────────────────────────────┐ │ State │ When │ ├────────────────────────────────────┼──────────────────────────────────────────────────┤ │ depth=0, operationScope=false │ Fragment definitions at document level │ │ depth=0, operationScope=true │ Nodes directly inside an operation │ │ depth>0, operationScope=true │ Nodes inside fragments reached via spread │ └────────────────────────────────────┴──────────────────────────────────────────────────┘
Rules are categorized by which states they run in:
┌──────────────────────┬──────────────────────┬─────────────────────┬─────────────────────┐ │ Rule Category │ depth=0 │ depth=0 │ depth>0 │ │ │ operationScope=false │ operationScope=true │ operationScope=true │ ├──────────────────────┼──────────────────────┼─────────────────────┼─────────────────────┤ │ Document-Level Rules │ RUN │ RUN │ SKIP │ │ Operation-Scoped │ SKIP │ RUN │ RUN │ └──────────────────────┴──────────────────────┴─────────────────────┴─────────────────────┘
Document-Level Rules
Condition: fragmentRetraversalDepth == 0
Validates each AST node exactly once during primary traversal. Skips during fragment retraversal to avoid duplicate errors (fragments are validated at document level).
EXECUTABLE_DEFINITIONS- only executable definitions allowedARGUMENTS_OF_CORRECT_TYPE- argument values match declared typesFIELDS_ON_CORRECT_TYPE- fields exist on parent typeFRAGMENTS_ON_COMPOSITE_TYPE- fragments on object/interface/union typesKNOWN_ARGUMENT_NAMES- arguments are defined on field/directiveKNOWN_DIRECTIVES- directives are defined in schemaKNOWN_FRAGMENT_NAMES- fragment spreads reference defined fragmentsKNOWN_TYPE_NAMES- type references exist in schemaNO_FRAGMENT_CYCLES- fragments do not form cyclesNO_UNUSED_FRAGMENTS- all fragments are used by operationsOVERLAPPING_FIELDS_CAN_BE_MERGED- fields with same response key are mergeablePOSSIBLE_FRAGMENT_SPREADS- fragment type conditions overlap with parentPROVIDED_NON_NULL_ARGUMENTS- required arguments are providedSCALAR_LEAVES- scalar fields have no subselections, composites require themVARIABLE_DEFAULT_VALUES_OF_CORRECT_TYPE- variable defaults match typeVARIABLES_ARE_INPUT_TYPES- variables use input types onlyLONE_ANONYMOUS_OPERATION- anonymous operations are alone in documentUNIQUE_OPERATION_NAMES- operation names are uniqueUNIQUE_FRAGMENT_NAMES- fragment names are uniqueUNIQUE_DIRECTIVE_NAMES_PER_LOCATION- non-repeatable directives appear onceUNIQUE_ARGUMENT_NAMES- argument names are unique per field/directiveUNIQUE_VARIABLE_NAMES- variable names are unique per operationSUBSCRIPTION_UNIQUE_ROOT_FIELD- subscriptions have single root fieldUNIQUE_OBJECT_FIELD_NAME- input object fields are uniqueDEFER_DIRECTIVE_LABEL- defer labels are unique stringsKNOWN_OPERATION_TYPES- schema supports the operation type
Operation-Scoped Rules
Condition: operationScope == true
Tracks state across an entire operation, following fragment spreads to see all code paths. Skips outside operations (e.g., fragment definitions at document level) where there is no operation context to validate against.
NO_UNDEFINED_VARIABLES- all variable references are defined in operationNO_UNUSED_VARIABLES- all defined variables are used somewhereVARIABLE_TYPES_MATCH- variable types match usage location typesDEFER_DIRECTIVE_ON_ROOT_LEVEL- defer not on mutation/subscription rootDEFER_DIRECTIVE_ON_VALID_OPERATION- defer not in subscriptions
See OperationValidator class documentation for a detailed traversal example.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionArgument values must be compatible with their declared types.Defer directive labels must be unique static strings.Defer directive must not be on mutation or subscription root level.Defer directive must not be used in subscription operations.Only executable definitions (operations and fragments) are allowed.Fields must exist on the parent type.Fragment type conditions must be on composite types (object, interface, union).Good faith introspection check.Arguments must be defined on the field or directive.Directives must be defined in the schema and used in valid locations.Fragment spreads must reference defined fragments.The schema must support the operation type (query/mutation/subscription).Type references must exist in the schema.Anonymous operations must be the only operation in the document.Fragments must not form cycles through spreads.All variable references must be defined in the operation.All defined fragments must be used by at least one operation.All defined variables must be used somewhere in the operation.Fields with the same response key must be mergeable.Fragment type conditions must overlap with the parent type.Required (non-null without default) arguments must be provided.Scalar fields must not have subselections; composite fields must have them.Subscriptions must have exactly one root field (not introspection).Argument names must be unique within a field or directive.Non-repeatable directives must appear at most once per location.Fragment names must be unique within the document.Input object field names must be unique.Operation names must be unique within the document.Variable names must be unique within an operation.Variable default values must match the variable type.Variable types must be compatible with usage location types.Variables must be declared with input types (scalars, enums, input objects). -
Method Summary
Modifier and TypeMethodDescriptionstatic OperationValidationRuleReturns the enum constant of this class with the specified name.static OperationValidationRule[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
EXECUTABLE_DEFINITIONS
Only executable definitions (operations and fragments) are allowed. -
ARGUMENTS_OF_CORRECT_TYPE
Argument values must be compatible with their declared types. -
FIELDS_ON_CORRECT_TYPE
Fields must exist on the parent type. -
FRAGMENTS_ON_COMPOSITE_TYPE
Fragment type conditions must be on composite types (object, interface, union). -
KNOWN_ARGUMENT_NAMES
Arguments must be defined on the field or directive. -
KNOWN_DIRECTIVES
Directives must be defined in the schema and used in valid locations. -
KNOWN_FRAGMENT_NAMES
Fragment spreads must reference defined fragments. -
KNOWN_TYPE_NAMES
Type references must exist in the schema. -
NO_FRAGMENT_CYCLES
Fragments must not form cycles through spreads. -
NO_UNUSED_FRAGMENTS
All defined fragments must be used by at least one operation. -
OVERLAPPING_FIELDS_CAN_BE_MERGED
Fields with the same response key must be mergeable. -
POSSIBLE_FRAGMENT_SPREADS
Fragment type conditions must overlap with the parent type. -
PROVIDED_NON_NULL_ARGUMENTS
Required (non-null without default) arguments must be provided. -
SCALAR_LEAVES
Scalar fields must not have subselections; composite fields must have them. -
VARIABLE_DEFAULT_VALUES_OF_CORRECT_TYPE
Variable default values must match the variable type. -
VARIABLES_ARE_INPUT_TYPES
Variables must be declared with input types (scalars, enums, input objects). -
LONE_ANONYMOUS_OPERATION
Anonymous operations must be the only operation in the document. -
UNIQUE_OPERATION_NAMES
Operation names must be unique within the document. -
UNIQUE_FRAGMENT_NAMES
Fragment names must be unique within the document. -
UNIQUE_DIRECTIVE_NAMES_PER_LOCATION
Non-repeatable directives must appear at most once per location. -
UNIQUE_ARGUMENT_NAMES
Argument names must be unique within a field or directive. -
UNIQUE_VARIABLE_NAMES
Variable names must be unique within an operation. -
SUBSCRIPTION_UNIQUE_ROOT_FIELD
Subscriptions must have exactly one root field (not introspection). -
UNIQUE_OBJECT_FIELD_NAME
Input object field names must be unique. -
DEFER_DIRECTIVE_LABEL
Defer directive labels must be unique static strings. -
KNOWN_OPERATION_TYPES
The schema must support the operation type (query/mutation/subscription). -
NO_UNDEFINED_VARIABLES
All variable references must be defined in the operation. Requires fragment traversal. -
NO_UNUSED_VARIABLES
All defined variables must be used somewhere in the operation. Requires fragment traversal. -
VARIABLE_TYPES_MATCH
Variable types must be compatible with usage location types. Requires fragment traversal. -
DEFER_DIRECTIVE_ON_ROOT_LEVEL
Defer directive must not be on mutation or subscription root level. Requires operation context. -
DEFER_DIRECTIVE_ON_VALID_OPERATION
Defer directive must not be used in subscription operations. Requires operation context. -
GOOD_FAITH_INTROSPECTION
Good faith introspection check.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-