Class: GraphQL::Validations::FieldsWillMerge::FieldDefinitionComparison

Inherits:
Object
  • Object
show all
Defined in:
lib/graph_ql/validations/fields_will_merge.rb

Overview

Compare two field definitions, add errors to the list if there are any

Constant Summary collapse

NAMED_VALUES =
[GraphQL::Nodes::Enum, GraphQL::Nodes::VariableIdentifier]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, prev_def, next_def) ⇒ FieldDefinitionComparison

Returns a new instance of FieldDefinitionComparison.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/graph_ql/validations/fields_will_merge.rb', line 46

def initialize(name, prev_def, next_def)
  errors = []
  if prev_def.name != next_def.name
    errors << "Field '#{name}' has a field conflict: #{prev_def.name} or #{next_def.name}?"
  end
  prev_arguments = reduce_list(prev_def.arguments)
  next_arguments = reduce_list(next_def.arguments)
  if prev_arguments != next_arguments
    errors << "Field '#{name}' has an argument conflict: #{JSON.dump(prev_arguments)} or #{JSON.dump(next_arguments)}?"
  end
  prev_directive_names = prev_def.directives.map(&:name)
  next_directive_names = next_def.directives.map(&:name)
  if prev_directive_names != next_directive_names
    errors << "Field '#{name}' has a directive conflict: [#{prev_directive_names.join(", ")}] or [#{next_directive_names.join(", ")}]?"
  end
  prev_directive_args = prev_def.directives.map {|d| reduce_list(d.arguments) }
  next_directive_args = next_def.directives.map {|d| reduce_list(d.arguments) }
  if prev_directive_args != next_directive_args
    errors << "Field '#{name}' has a directive argument conflict: #{JSON.dump(prev_directive_args)} or #{JSON.dump(next_directive_args)}?"
  end
  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



45
46
47
# File 'lib/graph_ql/validations/fields_will_merge.rb', line 45

def errors
  @errors
end