Class: GraphQL::DSL::VariableDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/dsl/nodes/containers/variable_definition.rb

Overview

Container for variable definition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, default = UNDEFINED, directives = []) ⇒ VariableDefinition

Create variable definition container

Parameters:

  • type (String, Symbol)

    variable type

  • default (Object, nil) (defaults to: UNDEFINED)

    default value

  • directives (Array<Directive, Hash, Array>) (defaults to: [])

    list of directives

Raises:



26
27
28
29
30
31
32
# File 'lib/graphql/dsl/nodes/containers/variable_definition.rb', line 26

def initialize(type, default = UNDEFINED, directives = [])
  raise Error, 'Variable type must be specified' if type.nil? || type.empty?

  @type = type
  @default = default
  @directives = directives.map { |directive| Directive.from(directive) }
end

Instance Attribute Details

#defaultObject? (readonly)

Returns default value of variable.

Returns:

  • (Object, nil)

    default value of variable



14
15
16
# File 'lib/graphql/dsl/nodes/containers/variable_definition.rb', line 14

def default
  @default
end

#directivesArray<Directive> (readonly)

Returns list of directives.

Returns:



18
19
20
# File 'lib/graphql/dsl/nodes/containers/variable_definition.rb', line 18

def directives
  @directives
end

#typeString, ... (readonly)

Returns variable type.

Returns:

  • (String, Symbol, nil)

    variable type



10
11
12
# File 'lib/graphql/dsl/nodes/containers/variable_definition.rb', line 10

def type
  @type
end

Class Method Details

.from(value) ⇒ VariableDefinition

Create variable definition container from argument value

Parameters:

  • value

    argument value

Returns:



41
42
43
44
45
46
47
48
# File 'lib/graphql/dsl/nodes/containers/variable_definition.rb', line 41

def from(value)
  case value
  when VariableDefinition then value
  when Symbol, String then new(value)
  else
    raise Error.new('Unsupported format of variable definition', class: value.class.name, value: value)
  end
end