Class: GraphQL::StaticValidation::MutationRootExists

Inherits:
Object
  • Object
show all
Includes:
GraphQL::StaticValidation::Message::MessageHelper
Defined in:
lib/graphql/static_validation/rules/mutation_root_exists.rb

Instance Method Summary collapse

Methods included from GraphQL::StaticValidation::Message::MessageHelper

#message

Instance Method Details

#validate(context) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql/static_validation/rules/mutation_root_exists.rb', line 7

def validate(context)
  return if context.warden.root_type_for_operation("mutation")

  visitor = context.visitor

  visitor[GraphQL::Language::Nodes::OperationDefinition].enter << ->(ast_node, prev_ast_node) {
    if ast_node.operation_type == 'mutation'
      context.errors << message('Schema is not configured for mutations', ast_node, context: context)
      return GraphQL::Language::Visitor::SKIP
    end
  }
end