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.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/graphql/static_validation/rules/fields_will_merge.rb', line 66

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| JSON.dump(a) }.join(" or ")}?", defs.first, context: context)
  end

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

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

  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



65
66
67
# File 'lib/graphql/static_validation/rules/fields_will_merge.rb', line 65

def errors
  @errors
end