Class: ElasticGraph::SchemaDefinition::SchemaElements::Argument

Inherits:
Struct
  • Object
show all
Includes:
Mixins::HasDirectives, Mixins::HasDocumentation, Mixins::SupportsDefaultValue, Mixins::VerifiesGraphQLName
Defined in:
elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb

Overview

Represents a GraphQL argument.

Instance Attribute Summary collapse

Attributes included from Mixins::HasDocumentation

#doc_comment

Instance Method Summary collapse

Methods included from Mixins::HasDirectives

#directive, #directives, #directives_sdl

Methods included from Mixins::HasDocumentation

#append_to_documentation, #derived_documentation, #documentation, #formatted_documentation

Methods included from Mixins::VerifiesGraphQLName

verify_name!

Methods included from Mixins::SupportsDefaultValue

#default, #default_value_sdl

Instance Attribute Details

#nameString (readonly)

Returns name of the argument.

Returns:

  • (String)

    name of the argument



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb', line 30

class Argument < Struct.new(:schema_def_state, :parent_field, :name, :original_value_type)
  prepend Mixins::VerifiesGraphQLName
  prepend Mixins::SupportsDefaultValue
  include Mixins::HasDocumentation
  include Mixins::HasDirectives
  include Mixins::HasReadableToSAndInspect.new { |a| "#{a.parent_field.parent_type.name}.#{a.parent_field.name}(#{a.name}: #{a.value_type})" }

  # @return [String] GraphQL SDL form of the argument
  def to_sdl
    "#{formatted_documentation}#{name}: #{value_type}#{default_value_sdl}#{directives_sdl(prefix_with: " ")}"
  end

  # When the argument type is an enum, and we're configured with different naming for input vs output enums,
  # we need to convert the value type to its input form. Note that this intentionally happens lazily (rather than
  # doing this when `Argument` is instantiated), because the referenced type need not exist when the argument
  # is defined, and we may not be able to figure out if it's an enum until the type has been defined. So, we
  # apply this lazily.
  #
  # @return [TypeReference] the type of the argument
  # @see #original_value_type
  def value_type
    original_value_type.to_final_form(as_input: true)
  end
end

#original_value_typeTypeReference (readonly)

Returns type of the argument, as originally provided.

Returns:

  • (TypeReference)

    type of the argument, as originally provided

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb', line 30

class Argument < Struct.new(:schema_def_state, :parent_field, :name, :original_value_type)
  prepend Mixins::VerifiesGraphQLName
  prepend Mixins::SupportsDefaultValue
  include Mixins::HasDocumentation
  include Mixins::HasDirectives
  include Mixins::HasReadableToSAndInspect.new { |a| "#{a.parent_field.parent_type.name}.#{a.parent_field.name}(#{a.name}: #{a.value_type})" }

  # @return [String] GraphQL SDL form of the argument
  def to_sdl
    "#{formatted_documentation}#{name}: #{value_type}#{default_value_sdl}#{directives_sdl(prefix_with: " ")}"
  end

  # When the argument type is an enum, and we're configured with different naming for input vs output enums,
  # we need to convert the value type to its input form. Note that this intentionally happens lazily (rather than
  # doing this when `Argument` is instantiated), because the referenced type need not exist when the argument
  # is defined, and we may not be able to figure out if it's an enum until the type has been defined. So, we
  # apply this lazily.
  #
  # @return [TypeReference] the type of the argument
  # @see #original_value_type
  def value_type
    original_value_type.to_final_form(as_input: true)
  end
end

#parent_fieldField (readonly)

Returns field which has this argument.

Returns:

  • (Field)

    field which has this argument



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb', line 30

class Argument < Struct.new(:schema_def_state, :parent_field, :name, :original_value_type)
  prepend Mixins::VerifiesGraphQLName
  prepend Mixins::SupportsDefaultValue
  include Mixins::HasDocumentation
  include Mixins::HasDirectives
  include Mixins::HasReadableToSAndInspect.new { |a| "#{a.parent_field.parent_type.name}.#{a.parent_field.name}(#{a.name}: #{a.value_type})" }

  # @return [String] GraphQL SDL form of the argument
  def to_sdl
    "#{formatted_documentation}#{name}: #{value_type}#{default_value_sdl}#{directives_sdl(prefix_with: " ")}"
  end

  # When the argument type is an enum, and we're configured with different naming for input vs output enums,
  # we need to convert the value type to its input form. Note that this intentionally happens lazily (rather than
  # doing this when `Argument` is instantiated), because the referenced type need not exist when the argument
  # is defined, and we may not be able to figure out if it's an enum until the type has been defined. So, we
  # apply this lazily.
  #
  # @return [TypeReference] the type of the argument
  # @see #original_value_type
  def value_type
    original_value_type.to_final_form(as_input: true)
  end
end

#schema_def_stateState (readonly)

Returns state of the schema.

Returns:

  • (State)

    state of the schema



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb', line 30

class Argument < Struct.new(:schema_def_state, :parent_field, :name, :original_value_type)
  prepend Mixins::VerifiesGraphQLName
  prepend Mixins::SupportsDefaultValue
  include Mixins::HasDocumentation
  include Mixins::HasDirectives
  include Mixins::HasReadableToSAndInspect.new { |a| "#{a.parent_field.parent_type.name}.#{a.parent_field.name}(#{a.name}: #{a.value_type})" }

  # @return [String] GraphQL SDL form of the argument
  def to_sdl
    "#{formatted_documentation}#{name}: #{value_type}#{default_value_sdl}#{directives_sdl(prefix_with: " ")}"
  end

  # When the argument type is an enum, and we're configured with different naming for input vs output enums,
  # we need to convert the value type to its input form. Note that this intentionally happens lazily (rather than
  # doing this when `Argument` is instantiated), because the referenced type need not exist when the argument
  # is defined, and we may not be able to figure out if it's an enum until the type has been defined. So, we
  # apply this lazily.
  #
  # @return [TypeReference] the type of the argument
  # @see #original_value_type
  def value_type
    original_value_type.to_final_form(as_input: true)
  end
end

Instance Method Details

#to_sdlString

Returns GraphQL SDL form of the argument.

Returns:

  • (String)

    GraphQL SDL form of the argument



38
39
40
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb', line 38

def to_sdl
  "#{formatted_documentation}#{name}: #{value_type}#{default_value_sdl}#{directives_sdl(prefix_with: " ")}"
end

#value_typeTypeReference

When the argument type is an enum, and we’re configured with different naming for input vs output enums, we need to convert the value type to its input form. Note that this intentionally happens lazily (rather than doing this when Argument is instantiated), because the referenced type need not exist when the argument is defined, and we may not be able to figure out if it’s an enum until the type has been defined. So, we apply this lazily.

Returns:

  • (TypeReference)

    the type of the argument

See Also:



50
51
52
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/argument.rb', line 50

def value_type
  original_value_type.to_final_form(as_input: true)
end