Class: GraphQL::StaticValidation::VariablesAreUsedAndDefinedError

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

Constant Summary collapse

VIOLATIONS =
{
  :VARIABLE_NOT_USED     => "variableNotUsed",
  :VARIABLE_NOT_DEFINED  => "variableNotDefined",
}

Instance Attribute Summary collapse

Attributes inherited from Error

#message, #nodes, #path

Instance Method Summary collapse

Constructor Details

#initialize(message, path: nil, nodes: [], name:, error_type:) ⇒ VariablesAreUsedAndDefinedError

Returns a new instance of VariablesAreUsedAndDefinedError.



13
14
15
16
17
18
# File 'lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb', line 13

def initialize(message, path: nil, nodes: [], name:, error_type:)
  super(message, path: path, nodes: nodes)
  @variable_name = name
  raise("Unexpected error type: #{error_type}") if !VIOLATIONS.values.include?(error_type)
  @violation = error_type
end

Instance Attribute Details

#variable_nameObject (readonly)

Returns the value of attribute variable_name.



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

def variable_name
  @variable_name
end

#violationObject (readonly)

Returns the value of attribute violation.



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

def violation
  @violation
end

Instance Method Details

#codeObject



32
33
34
# File 'lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb', line 32

def code
  @violation
end

#to_hObject

A hash representation of this Message



21
22
23
24
25
26
27
28
29
30
# File 'lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb', line 21

def to_h
  extensions = {
    "code" => code,
    "variableName" => variable_name
  }

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