Class: GraphQL::Argument

Inherits:
Object
  • Object
show all
Includes:
Define::InstanceDefinable
Defined in:
lib/graphql/argument.rb

Overview

Used for defined arguments (Field, InputObjectType)

#name must be a String.

Examples:

defining an argument for a field

GraphQL::Field.define do
  # ...
  argument :favoriteFood, types.String, "Favorite thing to eat", default_value: "pizza"
end

defining an argument for an InputObjectType

GraphQL::InputObjectType.define do
  argument :newName, !types.String
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Define::InstanceDefinable

#define, #definition_proc=, #metadata

Instance Attribute Details

#nameString

Returns The name of this argument on its Field or InputObjectType

Returns:


# File 'lib/graphql/argument.rb', line 22

Instance Method Details

#typeGraphQL::BaseType

Returns the input type for this argument

Returns:


33
34
35
36
37
38
# File 'lib/graphql/argument.rb', line 33

def type
  @clean_type ||= begin
    ensure_defined
    GraphQL::BaseType.resolve_related_type(@dirty_type)
  end
end

#type=(new_input_type) ⇒ Object

Parameters:

  • new_input_type (GraphQL::BaseType, Proc)

    Assign a new input type for this argument (if it's a proc, it will be called after schema initialization)


26
27
28
29
30
# File 'lib/graphql/argument.rb', line 26

def type=(new_input_type)
  ensure_defined
  @clean_type = nil
  @dirty_type = new_input_type
end