Class: GraphQL::StaticValidation::FieldsWillMerge::FieldDefinitionComparison

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

Overview

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Message::MessageHelper

#message

Constructor Details

#initialize(name, defs, context) ⇒ FieldDefinitionComparison

Returns a new instance of FieldDefinitionComparison.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/graphql/static_validation/rules/fields_will_merge.rb', line 69

def initialize(name, defs, context)
  errors = []

  names = defs.map(&:name).uniq
  if names.length != 1
    errors << message("Field '#{name}' has a field conflict: #{names.join(" or ")}?", defs.first, context: context)
  end

  args = defs.map { |defn| reduce_list(defn.arguments)}.uniq
  if args.length != 1
    errors << message("Field '#{name}' has an argument conflict: #{args.map {|a| print_arg(a) }.join(" or ")}?", defs.first, context: context)
  end

  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



68
69
70
# File 'lib/graphql/static_validation/rules/fields_will_merge.rb', line 68

def errors
  @errors
end