Class: GraphQL::Schema::Resolver Private
- Inherits:
-
Object
- Object
- GraphQL::Schema::Resolver
- Extended by:
- Member::BaseDSLMethods, Member::HasArguments
- Includes:
- Member::GraphQLTypeNames
- Defined in:
- lib/graphql/schema/resolver.rb
Overview
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.
A class-based container for field configuration and resolution logic. It supports:
- Arguments, via
.argument(...)
helper, which will be applied to the field. - Return type, via
.type(..., null: ...)
, which will be applied to the field. - Description, via
.description(...)
, which will be applied to the field - Resolution, via
#resolve(**args)
method, which will be called to resolve the field. #object
and#context
accessors for use during#resolve
.
Resolvers can be attached with the resolver:
option in a field(...)
call.
A resolver’s configuration may be overridden with other keywords in the field(...)
call.
See the Resolver.field_options to see how a Resolver becomes a set of field configuration options.
Direct Known Subclasses
Constant Summary
Constants included from Member::GraphQLTypeNames
Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int
Instance Attribute Summary collapse
-
#context ⇒ GraphQL::Query::Context
readonly
private
-
#object ⇒ Object
readonly
private
The application object this field is being resolved on.
Class Method Summary collapse
-
.extras(new_extras = nil) ⇒ Object
private
Additional info injected into #resolve.
-
.field_options ⇒ Object
private
-
.null(allow_null = nil) ⇒ Object
private
Specifies whether or not the field is nullable.
-
.resolve_method(new_method = nil) ⇒ Symbol
private
Default
:resolve
set below. -
.type(new_type = nil, null: nil) ⇒ Class
private
Call this method to get the return type of the field, or use it as a configuration method to assign a return type instead of generating one.
-
.type_expr ⇒ Object
private
A non-normalized type configuration, without
null
applied.
Instance Method Summary collapse
-
#initialize(object:, context:) ⇒ Resolver
constructor
private
A new instance of Resolver.
-
#resolve(**args) ⇒ Object
private
Do the work.
Methods included from Member::HasArguments
argument, argument_class, arguments, own_arguments
Methods included from Member::BaseDSLMethods
description, graphql_name, introspection, mutation, name, overridden_graphql_name, to_graphql, unwrap
Constructor Details
#initialize(object:, context:) ⇒ Resolver
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 Resolver
29 30 31 32 |
# File 'lib/graphql/schema/resolver.rb', line 29 def initialize(object:, context:) @object = object @context = context end |
Instance Attribute Details
#context ⇒ GraphQL::Query::Context (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.
38 39 40 |
# File 'lib/graphql/schema/resolver.rb', line 38 def context @context end |
#object ⇒ Object (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 application object this field is being resolved on
35 36 37 |
# File 'lib/graphql/schema/resolver.rb', line 35 def object @object end |
Class Method Details
.extras(new_extras = 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.
Additional info injected into #resolve
58 59 60 61 62 63 64 |
# File 'lib/graphql/schema/resolver.rb', line 58 def extras(new_extras = nil) if new_extras @own_extras = new_extras end own_extras = @own_extras || [] own_extras + (superclass.respond_to?(:extras) ? superclass.extras : []) end |
.field_options ⇒ 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.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/graphql/schema/resolver.rb', line 102 def { type: type_expr, description: description, extras: extras, method: resolve_method, resolver_class: self, arguments: arguments, null: null, } end |
.null(allow_null = 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.
Specifies whether or not the field is nullable. Defaults to true
TODO unify with #type
69 70 71 72 73 74 75 |
# File 'lib/graphql/schema/resolver.rb', line 69 def null(allow_null = nil) if !allow_null.nil? @null = allow_null end @null.nil? ? (superclass.respond_to?(:null) ? superclass.null : true) : @null end |
.resolve_method(new_method = nil) ⇒ Symbol
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.
Default :resolve
set below.
49 50 51 52 53 54 |
# File 'lib/graphql/schema/resolver.rb', line 49 def resolve_method(new_method = nil) if new_method @resolve_method = new_method end @resolve_method || (superclass.respond_to?(:resolve_method) ? superclass.resolve_method : :resolve) end |
.type(new_type = nil, null: nil) ⇒ Class
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.
Call this method to get the return type of the field, or use it as a configuration method to assign a return type instead of generating one. TODO unify with #null
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/graphql/schema/resolver.rb', line 84 def type(new_type = nil, null: nil) if new_type if null.nil? raise ArgumentError, "required argument `null:` is missing" end @type_expr = new_type @null = null else if @type_expr GraphQL::Schema::Member::BuildType.parse_type(@type_expr, null: @null) elsif superclass.respond_to?(:type) superclass.type else nil end end end |
.type_expr ⇒ 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.
A non-normalized type configuration, without null
applied
115 116 117 |
# File 'lib/graphql/schema/resolver.rb', line 115 def type_expr @type_expr || (superclass.respond_to?(:type_expr) ? superclass.type_expr : nil) end |
Instance Method Details
#resolve(**args) ⇒ 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.
Do the work. Everything happens here.
42 43 44 |
# File 'lib/graphql/schema/resolver.rb', line 42 def resolve(**args) raise NotImplementedError, "#{self.class.name}#resolve should execute the field's logic" end |