Class: GraphQL::Schema::RelayClassicMutation Private
- Defined in:
- lib/graphql/schema/relay_classic_mutation.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.
Mutations that extend this base class get some conventions added for free:
- An argument called
clientMutationId
is always added, but it’s not passed to the resolve method. The value is re-inserted to the response. (It’s for client libraries to manage optimistic updates.) - The returned object type always has a field called
clientMutationId
to support that. - The mutation accepts one argument called
input
,argument
s defined in the mutation class are added to that input object, which is generated by the mutation.
These conventions were first specified by Relay Classic, but they come in handy:
clientMutationId
supports optimistic updates and cache rollbacks on the client- using a single
input:
argument makes it easy to post whole JSON objects to the mutation using one GraphQL variable ($input
) instead of making a separate variable for each argument.
Constant Summary
Constants included from Member::GraphQLTypeNames
Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int
Instance Attribute Summary
Attributes inherited from Resolver
Class Method Summary collapse
-
.field_options ⇒ Object
private
Extend Schema::Mutation.field_options to add the
input
argument. -
.input_object_class(new_class = nil) ⇒ Class
private
The base class for generated input object types.
-
.input_type(new_input_type = nil) ⇒ Class
private
The generated InputObject class for this mutation’s
input
.
Instance Method Summary collapse
-
#resolve_mutation(kwargs) ⇒ Object
private
Override Mutation#resolve_mutation to delete
client_mutation_id
from the kwargs.
Methods inherited from Mutation
field, field_class, object_class, payload_type
Methods included from Member::HasFields
add_default_resolve_module, #add_field, extended, #field, #field_class, #fields, #global_id_field, #included, #inherited, #own_fields
Methods inherited from Resolver
extras, #initialize, null, #resolve, resolve_method, type, type_expr
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
This class inherits a constructor from GraphQL::Schema::Resolver
Class Method Details
.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.
Extend Schema::Mutation.field_options to add the input
argument
59 60 61 62 63 64 65 |
# File 'lib/graphql/schema/relay_classic_mutation.rb', line 59 def sig = super # Arguments were added at the root, but they should be nested sig[:arguments].clear sig[:arguments][:input] = { type: input_type, required: true } sig end |
.input_object_class(new_class = 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.
The base class for generated input object types
42 43 44 45 46 47 |
# File 'lib/graphql/schema/relay_classic_mutation.rb', line 42 def input_object_class(new_class = nil) if new_class @input_object_class = new_class end @input_object_class || (superclass.respond_to?(:input_object_class) ? superclass.input_object_class : GraphQL::Schema::InputObject) end |
.input_type(new_input_type = 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.
Returns The generated InputObject class for this mutation’s input
51 52 53 54 55 56 |
# File 'lib/graphql/schema/relay_classic_mutation.rb', line 51 def input_type(new_input_type = nil) if new_input_type @input_type = new_input_type end @input_type ||= generate_input_type end |
Instance Method Details
#resolve_mutation(kwargs) ⇒ 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.
Override Mutation#resolve_mutation to
delete client_mutation_id
from the kwargs.
30 31 32 33 34 |
# File 'lib/graphql/schema/relay_classic_mutation.rb', line 30 def resolve_mutation(kwargs) # This is handled by Relay::Mutation::Resolve, a bit hacky, but here we are. kwargs.delete(:client_mutation_id) resolve(**kwargs) end |