Class: GraphQL::Argument
- Inherits:
-
Object
- Object
- GraphQL::Argument
- Includes:
- Define::InstanceDefinable
- Defined in:
- lib/graphql/argument.rb
Overview
Used for defined arguments (Field, InputObjectType)
#name must be a String.
Defined Under Namespace
Modules: DefaultPrepare
Constant Summary collapse
- NO_DEFAULT_VALUE =
Object.new
Instance Attribute Summary collapse
-
#as ⇒ Object
Returns the value of attribute as.
-
#ast_node ⇒ Object
Returns the value of attribute ast_node.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#description ⇒ Object
Returns the value of attribute description.
-
#method_access ⇒ Object
Returns the value of attribute method_access.
-
#name ⇒ String
(also: #graphql_name)
The name of this argument on its Field or InputObjectType.
Class Method Summary collapse
-
.deep_stringify(val) ⇒ Object
private
-
.from_dsl(name, type_or_argument = nil, description = nil, default_value: NO_DEFAULT_VALUE, as: nil, prepare: DefaultPrepare, **kwargs, &block) ⇒ Object
private
Instance Method Summary collapse
-
#default_value? ⇒ Boolean
-
#expose_as ⇒ String
The name of this argument inside
resolve
functions. -
#initialize ⇒ Argument
constructor
A new instance of Argument.
-
#initialize_copy(other) ⇒ Object
-
#keyword ⇒ Object
Backport this to support legacy-style directives.
-
#method_access? ⇒ Boolean
-
#prepare(value, ctx) ⇒ Object
The prepared
value
for this argument orvalue
itself if noprepare
function exists. -
#prepare=(prepare_proc) ⇒ Object
Assign a
prepare
function to prepare this argument’s value beforeresolve
functions are called. -
#type ⇒ GraphQL::BaseType
The input type for this argument.
-
#type=(new_input_type) ⇒ Object
Methods included from Define::InstanceDefinable
Constructor Details
#initialize ⇒ Argument
Returns a new instance of Argument
52 53 54 |
# File 'lib/graphql/argument.rb', line 52 def initialize @prepare_proc = DefaultPrepare end |
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as
40 41 42 |
# File 'lib/graphql/argument.rb', line 40 def as @as end |
#ast_node ⇒ Object
Returns the value of attribute ast_node
41 42 43 |
# File 'lib/graphql/argument.rb', line 41 def ast_node @ast_node end |
#default_value ⇒ Object
Returns the value of attribute default_value
39 40 41 |
# File 'lib/graphql/argument.rb', line 39 def default_value @default_value end |
#description ⇒ Object
Returns the value of attribute description
40 41 42 |
# File 'lib/graphql/argument.rb', line 40 def description @description end |
#method_access ⇒ Object
Returns the value of attribute method_access
42 43 44 |
# File 'lib/graphql/argument.rb', line 42 def method_access @method_access end |
#name ⇒ String Also known as: graphql_name
Returns The name of this argument on its Field or InputObjectType
79 80 81 |
# File 'lib/graphql/argument.rb', line 79 def name @name end |
Class Method Details
.deep_stringify(val) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/graphql/argument.rb', line 144 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/graphql/argument.rb', line 118 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 |
Instance Method Details
#default_value? ⇒ Boolean
60 61 62 |
# File 'lib/graphql/argument.rb', line 60 def default_value? !!@has_default_value end |
#expose_as ⇒ String
Returns The name of this argument inside resolve
functions
94 95 96 |
# File 'lib/graphql/argument.rb', line 94 def expose_as @expose_as ||= (@as || @name).to_s end |
#initialize_copy(other) ⇒ Object
56 57 58 |
# File 'lib/graphql/argument.rb', line 56 def initialize_copy(other) @expose_as = nil end |
#keyword ⇒ Object
Backport this to support legacy-style directives
99 100 101 |
# File 'lib/graphql/argument.rb', line 99 def keyword @keyword ||= GraphQL::Schema::Member::BuildType.underscore(expose_as).to_sym end |
#method_access? ⇒ Boolean
64 65 66 67 |
# File 'lib/graphql/argument.rb', line 64 def method_access? # Treat unset as true -- only `false` should override @method_access != false end |
#prepare(value, ctx) ⇒ Object
Returns The prepared value
for this argument or value
itself if no prepare
function exists.
106 107 108 |
# File 'lib/graphql/argument.rb', line 106 def prepare(value, ctx) @prepare_proc.call(value, ctx) end |
#prepare=(prepare_proc) ⇒ Object
Assign a prepare
function to prepare this argument’s value before resolve
functions are called.
112 113 114 |
# File 'lib/graphql/argument.rb', line 112 def prepare=(prepare_proc) @prepare_proc = BackwardsCompatibility.wrap_arity(prepare_proc, from: 1, to: 2, name: "Argument#prepare(value, ctx)") end |
#type ⇒ GraphQL::BaseType
Returns the input type for this argument
89 90 91 |
# File 'lib/graphql/argument.rb', line 89 def type @clean_type ||= GraphQL::BaseType.(@dirty_type) end |
#type=(new_input_type) ⇒ Object
83 84 85 86 |
# File 'lib/graphql/argument.rb', line 83 def type=(new_input_type) @clean_type = nil @dirty_type = new_input_type end |