Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
graphql / lib / graphql / static_validation / rules / mutation_root_exists.rb
Size: Mime:
# frozen_string_literal: true
module GraphQL
  module StaticValidation
    class MutationRootExists
      include GraphQL::StaticValidation::Message::MessageHelper

      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
    end
  end
end