Enum Class OperationValidationRule

java.lang.Object
java.lang.Enum<OperationValidationRule>
graphql.validation.OperationValidationRule
All Implemented Interfaces:
Serializable, Comparable<OperationValidationRule>, Constable

@PublicApi @NullMarked public enum OperationValidationRule extends Enum<OperationValidationRule>
Enumerates the individual validation rules that can be applied to a GraphQL operation document. Each value corresponds to a validation rule defined in the GraphQL specification.

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

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.

See OperationValidator class documentation for a detailed traversal example.

See Also:
  • Enum Constant Details

    • EXECUTABLE_DEFINITIONS

      public static final OperationValidationRule EXECUTABLE_DEFINITIONS
      Only executable definitions (operations and fragments) are allowed.
    • ARGUMENTS_OF_CORRECT_TYPE

      public static final OperationValidationRule ARGUMENTS_OF_CORRECT_TYPE
      Argument values must be compatible with their declared types.
    • FIELDS_ON_CORRECT_TYPE

      public static final OperationValidationRule FIELDS_ON_CORRECT_TYPE
      Fields must exist on the parent type.
    • FRAGMENTS_ON_COMPOSITE_TYPE

      public static final OperationValidationRule FRAGMENTS_ON_COMPOSITE_TYPE
      Fragment type conditions must be on composite types (object, interface, union).
    • KNOWN_ARGUMENT_NAMES

      public static final OperationValidationRule KNOWN_ARGUMENT_NAMES
      Arguments must be defined on the field or directive.
    • KNOWN_DIRECTIVES

      public static final OperationValidationRule KNOWN_DIRECTIVES
      Directives must be defined in the schema and used in valid locations.
    • KNOWN_FRAGMENT_NAMES

      public static final OperationValidationRule KNOWN_FRAGMENT_NAMES
      Fragment spreads must reference defined fragments.
    • KNOWN_TYPE_NAMES

      public static final OperationValidationRule KNOWN_TYPE_NAMES
      Type references must exist in the schema.
    • NO_FRAGMENT_CYCLES

      public static final OperationValidationRule NO_FRAGMENT_CYCLES
      Fragments must not form cycles through spreads.
    • NO_UNUSED_FRAGMENTS

      public static final OperationValidationRule NO_UNUSED_FRAGMENTS
      All defined fragments must be used by at least one operation.
    • OVERLAPPING_FIELDS_CAN_BE_MERGED

      public static final OperationValidationRule OVERLAPPING_FIELDS_CAN_BE_MERGED
      Fields with the same response key must be mergeable.
    • POSSIBLE_FRAGMENT_SPREADS

      public static final OperationValidationRule POSSIBLE_FRAGMENT_SPREADS
      Fragment type conditions must overlap with the parent type.
    • PROVIDED_NON_NULL_ARGUMENTS

      public static final OperationValidationRule PROVIDED_NON_NULL_ARGUMENTS
      Required (non-null without default) arguments must be provided.
    • SCALAR_LEAVES

      public static final OperationValidationRule SCALAR_LEAVES
      Scalar fields must not have subselections; composite fields must have them.
    • VARIABLE_DEFAULT_VALUES_OF_CORRECT_TYPE

      public static final OperationValidationRule VARIABLE_DEFAULT_VALUES_OF_CORRECT_TYPE
      Variable default values must match the variable type.
    • VARIABLES_ARE_INPUT_TYPES

      public static final OperationValidationRule VARIABLES_ARE_INPUT_TYPES
      Variables must be declared with input types (scalars, enums, input objects).
    • LONE_ANONYMOUS_OPERATION

      public static final OperationValidationRule LONE_ANONYMOUS_OPERATION
      Anonymous operations must be the only operation in the document.
    • UNIQUE_OPERATION_NAMES

      public static final OperationValidationRule UNIQUE_OPERATION_NAMES
      Operation names must be unique within the document.
    • UNIQUE_FRAGMENT_NAMES

      public static final OperationValidationRule UNIQUE_FRAGMENT_NAMES
      Fragment names must be unique within the document.
    • UNIQUE_DIRECTIVE_NAMES_PER_LOCATION

      public static final OperationValidationRule UNIQUE_DIRECTIVE_NAMES_PER_LOCATION
      Non-repeatable directives must appear at most once per location.
    • UNIQUE_ARGUMENT_NAMES

      public static final OperationValidationRule UNIQUE_ARGUMENT_NAMES
      Argument names must be unique within a field or directive.
    • UNIQUE_VARIABLE_NAMES

      public static final OperationValidationRule UNIQUE_VARIABLE_NAMES
      Variable names must be unique within an operation.
    • SUBSCRIPTION_UNIQUE_ROOT_FIELD

      public static final OperationValidationRule SUBSCRIPTION_UNIQUE_ROOT_FIELD
      Subscriptions must have exactly one root field (not introspection).
    • UNIQUE_OBJECT_FIELD_NAME

      public static final OperationValidationRule UNIQUE_OBJECT_FIELD_NAME
      Input object field names must be unique.
    • DEFER_DIRECTIVE_LABEL

      public static final OperationValidationRule DEFER_DIRECTIVE_LABEL
      Defer directive labels must be unique static strings.
    • KNOWN_OPERATION_TYPES

      public static final OperationValidationRule KNOWN_OPERATION_TYPES
      The schema must support the operation type (query/mutation/subscription).
    • NO_UNDEFINED_VARIABLES

      public static final OperationValidationRule NO_UNDEFINED_VARIABLES
      All variable references must be defined in the operation. Requires fragment traversal.
    • NO_UNUSED_VARIABLES

      public static final OperationValidationRule NO_UNUSED_VARIABLES
      All defined variables must be used somewhere in the operation. Requires fragment traversal.
    • VARIABLE_TYPES_MATCH

      public static final OperationValidationRule VARIABLE_TYPES_MATCH
      Variable types must be compatible with usage location types. Requires fragment traversal.
    • DEFER_DIRECTIVE_ON_ROOT_LEVEL

      public static final OperationValidationRule DEFER_DIRECTIVE_ON_ROOT_LEVEL
      Defer directive must not be on mutation or subscription root level. Requires operation context.
    • DEFER_DIRECTIVE_ON_VALID_OPERATION

      public static final OperationValidationRule DEFER_DIRECTIVE_ON_VALID_OPERATION
      Defer directive must not be used in subscription operations. Requires operation context.
  • Method Details

    • values

      public static OperationValidationRule[] 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

      public static OperationValidationRule valueOf(String name)
      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 name
      NullPointerException - if the argument is null