Class: GraphQL::StaticValidation::FieldsWillMergeError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, field_name:) ⇒ FieldsWillMergeError

Returns a new instance of FieldsWillMergeError.



8
9
10
11
12
13
14
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 8

def initialize(kind:, field_name:)
  super(nil)

  @field_name = field_name
  @kind = kind
  @conflicts = []
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



5
6
7
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 5

def field_name
  @field_name
end

#kindObject (readonly)

Returns the value of attribute kind.



6
7
8
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 6

def kind
  @kind
end

Instance Method Details

#add_conflict(node, conflict_str) ⇒ Object



28
29
30
31
32
33
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 28

def add_conflict(node, conflict_str)
  return if nodes.include?(node)

  @nodes << node
  @conflicts << conflict_str
end

#codeObject



48
49
50
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 48

def code
  "fieldConflict"
end

#conflictsObject



24
25
26
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 24

def conflicts
  @conflicts.join(' or ')
end

#messageObject



16
17
18
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 16

def message
  "Field '#{field_name}' has #{kind == :argument ? 'an' : 'a'} #{kind} conflict: #{conflicts}?"
end

#pathObject



20
21
22
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 20

def path
  []
end

#to_hObject

A hash representation of this Message



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 36

def to_h
  extensions = {
    "code" => code,
    "fieldName" => field_name,
    "conflicts" => conflicts
  }

  super.merge({
    "extensions" => extensions
  })
end