Class: GraphQL::StaticValidation::FieldsWillMerge

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/static_validation/rules/fields_will_merge.rb

Defined Under Namespace

Classes: FieldDefinitionComparison

Instance Method Summary collapse

Instance Method Details

#validate(context) ⇒ Object



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

def validate(context)
  fragments = {}
  has_selections = []
  visitor = context.visitor
  visitor[GraphQL::Language::Nodes::OperationDefinition] << -> (node, parent) {
    if node.selections.any?
      has_selections << node
    end
  }
  visitor[GraphQL::Language::Nodes::Document].leave << -> (node, parent) {
    has_selections.each { |node|
      field_map = gather_fields_by_name(node.selections, {}, [], context)
      find_conflicts(field_map, context)
    }
  }
end