class GraphQL::Argument
@api deprecated
Constants
- NO_DEFAULT_VALUE
Attributes
as[RW]
ast_node[RW]
default_value[R]
deprecation_reason[RW]
description[RW]
graphql_name[RW]
method_access[RW]
name[RW]
Public Class Methods
deep_stringify(val)
click to toggle source
@api private
# File lib/graphql/argument.rb, line 116 def self.deep_stringify(val) case val when Array val.map { |v| deep_stringify(v) } when Hash new_val = {} val.each do |k, v| new_val[k.to_s] = deep_stringify(v) end new_val else val end end
from_dsl(name, type_or_argument = nil, description = nil, default_value: NO_DEFAULT_VALUE, as: nil, prepare: DefaultPrepare, **kwargs, &block)
click to toggle source
@api private
# File lib/graphql/argument.rb, line 90 def self.from_dsl(name, type_or_argument = nil, description = nil, default_value: NO_DEFAULT_VALUE, as: nil, prepare: DefaultPrepare, **kwargs, &block) name_s = name.to_s # Move some positional args into keywords if they're present description && kwargs[:description] ||= description kwargs[:name] ||= name_s kwargs[:default_value] ||= default_value kwargs[:as] ||= as unless prepare == DefaultPrepare kwargs[:prepare] ||= prepare end if !type_or_argument.nil? && !type_or_argument.is_a?(GraphQL::Argument) # Maybe a string, proc or BaseType kwargs[:type] = type_or_argument end if type_or_argument.is_a?(GraphQL::Argument) type_or_argument.redefine(**kwargs, &block) else GraphQL::Argument.define(**kwargs, &block) end end
new()
click to toggle source
# File lib/graphql/argument.rb, line 20 def initialize @prepare_proc = DefaultPrepare end
Public Instance Methods
default_value=(new_default_value)
click to toggle source
# File lib/graphql/argument.rb, line 37 def default_value=(new_default_value) if new_default_value == NO_DEFAULT_VALUE @has_default_value = false @default_value = nil else @has_default_value = true @default_value = GraphQL::Argument.deep_stringify(new_default_value) end end
default_value?()
click to toggle source
# File lib/graphql/argument.rb, line 28 def default_value? !!@has_default_value end
expose_as()
click to toggle source
@return [String] The name of this argument inside `resolve` functions
# File lib/graphql/argument.rb, line 62 def expose_as @expose_as ||= (@as || @name).to_s end
initialize_copy(other)
click to toggle source
# File lib/graphql/argument.rb, line 24 def initialize_copy(other) @expose_as = nil end
keyword()
click to toggle source
Backport this to support legacy-style directives
# File lib/graphql/argument.rb, line 67 def keyword @keyword ||= GraphQL::Schema::Member::BuildType.underscore(expose_as).to_sym end
method_access?()
click to toggle source
# File lib/graphql/argument.rb, line 32 def method_access? # Treat unset as true -- only `false` should override @method_access != false end
prepare(value, ctx)
click to toggle source
@param value [Object] The incoming value from variables or query string literal @param ctx [GraphQL::Query::Context] @return [Object] The prepared `value` for this argument or `value` itself if no `prepare` function exists.
# File lib/graphql/argument.rb, line 74 def prepare(value, ctx) @prepare_proc.call(value, ctx) end
prepare=(prepare_proc)
click to toggle source
Assign a `prepare` function to prepare this argument's value before `resolve` functions are called. @param prepare_proc [#<call(value, ctx)>]
# File lib/graphql/argument.rb, line 80 def prepare=(prepare_proc) @prepare_proc = BackwardsCompatibility.wrap_arity(prepare_proc, from: 1, to: 2, name: "Argument#prepare(value, ctx)") end
type()
click to toggle source
@return [GraphQL::BaseType] the input type for this argument
# File lib/graphql/argument.rb, line 57 def type @clean_type ||= GraphQL::BaseType.resolve_related_type(@dirty_type) end
type=(new_input_type)
click to toggle source
@param 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)
# File lib/graphql/argument.rb, line 51 def type=(new_input_type) @clean_type = nil @dirty_type = new_input_type end
type_class()
click to toggle source
# File lib/graphql/argument.rb, line 84 def type_class metadata[:type_class] end