Class: GraphQL::Relay::Mutation
- Inherits:
-
Object
- Object
- GraphQL::Relay::Mutation
- Includes:
- Define::InstanceDefinable
- Defined in:
- lib/graphql/relay/mutation.rb,
lib/graphql/relay/mutation/result.rb,
lib/graphql/relay/mutation/resolve.rb,
lib/graphql/relay/mutation/instrumentation.rb
Overview
Define a Relay mutation:
- give it a name (used for derived inputs & outputs)
- declare its inputs
- declare its outputs
- declare the mutation procedure
resolve
should return a hash with a key for each of the return_field
s
Inputs may also contain a clientMutationId
Defined Under Namespace
Modules: Instrumentation Classes: Resolve, Result
Instance Attribute Summary collapse
-
#arguments ⇒ Object
(also: #input_fields)
Returns the value of attribute arguments.
-
#description ⇒ Object
Returns the value of attribute description.
-
#fields ⇒ Object
(also: #return_fields)
Returns the value of attribute fields.
-
#name ⇒ Object
Returns the value of attribute name.
- #return_interfaces ⇒ Object
- #return_type ⇒ Object
Instance Method Summary collapse
- #field ⇒ Object
- #has_generated_return_type? ⇒ Boolean
-
#initialize ⇒ Mutation
constructor
A new instance of Mutation.
- #input_type ⇒ Object
- #resolve=(new_resolve_proc) ⇒ Object
- #result_class ⇒ Object
Methods included from Define::InstanceDefinable
#define, #initialize_copy, #metadata, #redefine
Constructor Details
#initialize ⇒ Mutation
Returns a new instance of Mutation.
117 118 119 120 121 |
# File 'lib/graphql/relay/mutation.rb', line 117 def initialize @fields = {} @arguments = {} @has_generated_return_type = false end |
Instance Attribute Details
#arguments ⇒ Object Also known as: input_fields
Returns the value of attribute arguments.
104 105 106 |
# File 'lib/graphql/relay/mutation.rb', line 104 def arguments @arguments end |
#description ⇒ Object
Returns the value of attribute description.
104 105 106 |
# File 'lib/graphql/relay/mutation.rb', line 104 def description @description end |
#fields ⇒ Object Also known as: return_fields
Returns the value of attribute fields.
104 105 106 |
# File 'lib/graphql/relay/mutation.rb', line 104 def fields @fields end |
#name ⇒ Object
Returns the value of attribute name.
104 105 106 |
# File 'lib/graphql/relay/mutation.rb', line 104 def name @name end |
#return_interfaces ⇒ Object
147 148 149 |
# File 'lib/graphql/relay/mutation.rb', line 147 def return_interfaces @return_interfaces ||= [] end |
#return_type ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/graphql/relay/mutation.rb', line 151 def return_type @return_type ||= begin @has_generated_return_type = true relay_mutation = self GraphQL::ObjectType.define do name("#{relay_mutation.name}Payload") description("Autogenerated return type of #{relay_mutation.name}") field :clientMutationId, types.String, "A unique identifier for the client performing the mutation.", property: :client_mutation_id interfaces relay_mutation.return_interfaces relay_mutation.return_fields.each do |name, field_obj| field name, field: field_obj end mutation(relay_mutation) end end end |
Instance Method Details
#field ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/graphql/relay/mutation.rb', line 133 def field @field ||= begin relay_mutation = self field_resolve_proc = @resolve_proc GraphQL::Field.define do type(relay_mutation.return_type) description(relay_mutation.description) argument :input, !relay_mutation.input_type resolve(field_resolve_proc) mutation(relay_mutation) end end end |
#has_generated_return_type? ⇒ Boolean
123 124 125 126 127 |
# File 'lib/graphql/relay/mutation.rb', line 123 def has_generated_return_type? # Trigger the generation of the return type, if it is dynamically generated: return_type @has_generated_return_type end |
#input_type ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/graphql/relay/mutation.rb', line 168 def input_type @input_type ||= begin relay_mutation = self input_object_type = GraphQL::InputObjectType.define do name("#{relay_mutation.name}Input") description("Autogenerated input type of #{relay_mutation.name}") input_field :clientMutationId, types.String, "A unique identifier for the client performing the mutation." mutation(relay_mutation) end input_fields.each do |name, arg| input_object_type.arguments[name] = arg end input_object_type end end |
#resolve=(new_resolve_proc) ⇒ Object
129 130 131 |
# File 'lib/graphql/relay/mutation.rb', line 129 def resolve=(new_resolve_proc) @resolve_proc = new_resolve_proc end |
#result_class ⇒ Object
185 186 187 |
# File 'lib/graphql/relay/mutation.rb', line 185 def result_class @result_class ||= Result.define_subclass(self) end |