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

Attributes inherited from Error

#nodes

Instance Method Summary collapse

Constructor Details

#initialize(kind:, field_name:) ⇒ FieldsWillMergeError

Returns a new instance of FieldsWillMergeError.

[View source]

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

#messageObject


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

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

Instance Method Details

#add_conflict(node, conflict_str) ⇒ Object

[View source]

30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 30

def add_conflict(node, conflict_str)
  # Can't use `.include?` here because AST nodes implement `#==`
  # based on string value, not including location. But sometimes,
  # identical nodes conflict because of their differing return types.
  if nodes.any? { |n| n == node && n.line == node.line && n.col == node.col }
    # already have an error for this node
    return
  end

  @nodes << node
  @conflicts << conflict_str
end

#codeObject

[View source]

56
57
58
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 56

def code
  "fieldConflict"
end

#conflictsObject

[View source]

26
27
28
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 26

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

#pathObject

[View source]

22
23
24
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 22

def path
  []
end

#to_hObject

A hash representation of this Message

[View source]

44
45
46
47
48
49
50
51
52
53
54
# File 'lib/graphql/static_validation/rules/fields_will_merge_error.rb', line 44

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

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