Class: GraphQL::Schema::Argument Private
- Inherits:
-
Object
- Object
- GraphQL::Schema::Argument
- Defined in:
- lib/graphql/schema/argument.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary
- NO_DEFAULT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:__no_default__
Instance Attribute Summary collapse
-
#keyword ⇒ Symbol
readonly
private
This argument’s name in Ruby keyword arguments.
-
#name ⇒ String
(also: #graphql_name)
readonly
private
The GraphQL name for this argument, camelized unless
camelize: false
is provided. -
#owner ⇒ GraphQL::Schema::Field, Class
readonly
private
The field or input object this argument belongs to.
-
#prepare ⇒ Symbol
readonly
private
A method to call to transform this value before sending it to field resolution method.
Instance Method Summary collapse
-
#accessible?(context) ⇒ Boolean
private
-
#authorized?(obj, ctx) ⇒ Boolean
private
-
#description(text = nil) ⇒ Object
private
-
#initialize(arg_name = nil, type_expr = nil, desc = nil, required:, type: nil, name: nil, description: nil, default_value: NO_DEFAULT, as: nil, camelize: true, prepare: nil, owner:, &definition_block) ⇒ Argument
constructor
private
A new instance of Argument.
-
#prepare_value(obj, value) ⇒ Object
private
Apply the #prepare configuration to
value
, using methods fromobj
. -
#to_graphql ⇒ Object
private
-
#type ⇒ Object
private
-
#visible?(context) ⇒ Boolean
private
Methods included from Member::CachedGraphQLDefinition
#graphql_definition, #initialize_copy
Constructor Details
#initialize(arg_name = nil, type_expr = nil, desc = nil, required:, type: nil, name: nil, description: nil, default_value: NO_DEFAULT, as: nil, camelize: true, prepare: nil, owner:, &definition_block) ⇒ Argument
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.
Returns a new instance of Argument
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/graphql/schema/argument.rb', line 32 def initialize(arg_name = nil, type_expr = nil, desc = nil, required:, type: nil, name: nil, description: nil, default_value: NO_DEFAULT, as: nil, camelize: true, prepare: nil, owner:, &definition_block) arg_name ||= name @name = camelize ? Member::BuildType.camelize(arg_name.to_s) : arg_name.to_s @type_expr = type_expr || type @description = desc || description @null = !required @default_value = default_value @owner = owner @as = as @keyword = as || Schema::Member::BuildType.underscore(@name).to_sym @prepare = prepare if definition_block instance_eval(&definition_block) end end |
Instance Attribute Details
#keyword ⇒ Symbol (readonly)
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.
Returns This argument’s name in Ruby keyword arguments
21 22 23 |
# File 'lib/graphql/schema/argument.rb', line 21 def keyword @keyword end |
#name ⇒ String (readonly) Also known as: graphql_name
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.
Returns the GraphQL name for this argument, camelized unless camelize: false
is provided
11 12 13 |
# File 'lib/graphql/schema/argument.rb', line 11 def name @name end |
#owner ⇒ GraphQL::Schema::Field, Class (readonly)
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.
Returns The field or input object this argument belongs to
15 16 17 |
# File 'lib/graphql/schema/argument.rb', line 15 def owner @owner end |
#prepare ⇒ Symbol (readonly)
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.
Returns A method to call to transform this value before sending it to field resolution method
18 19 20 |
# File 'lib/graphql/schema/argument.rb', line 18 def prepare @prepare end |
Instance Method Details
#accessible?(context) ⇒ Boolean
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.
61 62 63 |
# File 'lib/graphql/schema/argument.rb', line 61 def accessible?(context) true end |
#authorized?(obj, ctx) ⇒ Boolean
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.
65 66 67 |
# File 'lib/graphql/schema/argument.rb', line 65 def (obj, ctx) true end |
#description(text = nil) ⇒ 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.
49 50 51 52 53 54 55 |
# File 'lib/graphql/schema/argument.rb', line 49 def description(text = nil) if text @description = text else @description end end |
#prepare_value(obj, value) ⇒ 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.
Apply the #prepare configuration to value
, using methods from obj
.
Used by the runtime.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/graphql/schema/argument.rb', line 91 def prepare_value(obj, value) case @prepare when nil value when Symbol, String obj.public_send(@prepare, value) when Proc @prepare.call(value, obj.context) else raise "Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}" end end |
#to_graphql ⇒ 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.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/graphql/schema/argument.rb', line 69 def to_graphql argument = GraphQL::Argument.new argument.name = @name argument.type = -> { type } argument.description = @description argument.[:type_class] = self argument.as = @as if NO_DEFAULT != @default_value argument.default_value = @default_value end argument end |
#type ⇒ 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.
82 83 84 85 86 |
# File 'lib/graphql/schema/argument.rb', line 82 def type @type ||= Member::BuildType.parse_type(@type_expr, null: @null) rescue StandardError => err raise ArgumentError, "Couldn't build type for Argument #{@owner.name}.#{name}: #{err.class.name}: #{err.}", err.backtrace end |
#visible?(context) ⇒ Boolean
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.
57 58 59 |
# File 'lib/graphql/schema/argument.rb', line 57 def visible?(context) true end |