Class: GraphQL::Language::Nodes::Document

Inherits:
AbstractNode show all
Defined in:
lib/graphql/language/nodes/validate_ext.rb,
lib/graphql/language/nodes/inject_selection_ext.rb,
lib/graphql/language/nodes/replace_fragment_spread_ext.rb

Instance Method Summary collapse

Methods inherited from AbstractNode

#deep_freeze

Instance Method Details

#inject_selection(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/graphql/language/nodes/inject_selection_ext.rb', line 23

def inject_selection(*args)
  other = self.dup
  other.definitions = self.definitions.map do |definition|
    case definition
    when Selections
      definition.inject_selection(*args)
    else
      definition
    end
  end
  other
end

#replace_fragment_spread(fragments) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/graphql/language/nodes/replace_fragment_spread_ext.rb', line 29

def replace_fragment_spread(fragments)
  other = self.dup
  other.definitions = self.definitions.map do |definition|
    case definition
    when Selections
      definition.replace_fragment_spread(fragments)
    else
      definition
    end
  end
  other
end

#validate!(schema:, rules: StaticValidation::ALL_RULES) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/graphql/language/nodes/validate_ext.rb', line 10

def validate!(schema:, rules: StaticValidation::ALL_RULES)
  validator = StaticValidation::Validator.new(schema: schema, rules: rules)
  query = Query.new(schema, document: self)

  validator.validate(query).fetch(:errors).each do |error|
    raise ValidationError, error["message"]
  end

  nil
end