module GraphQL::Schema::Resolver::HasPayloadType
Adds field(...) helper to resolvers so that they can generate payload types.
Or, an already-defined one can be attached with payload_type(...).
Constants
- NO_INTERFACES
Public Instance Methods
# File lib/graphql/schema/resolver/has_payload_type.rb, line 84 def field(*args, **kwargs, &block) pt = payload_type # make sure it's initialized with any inherited fields field_defn = super # Remove any inherited fields to avoid false conflicts at runtime prev_fields = pt.own_fields[field_defn.graphql_name] case prev_fields when GraphQL::Schema::Field if prev_fields.owner != self pt.own_fields.delete(field_defn.graphql_name) end when Array prev_fields.reject! { |f| f.owner != self } if prev_fields.empty? pt.own_fields.delete(field_defn.graphql_name) end end pt.add_field(field_defn, method_conflict_warning: false) field_defn end
Calls superclass method
# File lib/graphql/schema/resolver/has_payload_type.rb, line 49 def field_class(new_class = nil) if new_class @field_class = new_class elsif defined?(@field_class) && @field_class @field_class else find_inherited_value(:field_class, GraphQL::Schema::Field) end end
# File lib/graphql/schema/resolver/has_payload_type.rb, line 71 def object_class(new_class = nil) if new_class if defined?(@payload_type) raise "Can't configure `object_class(...)` after the payload type has already been initialized. Move this configuration higher up the class definition." end @object_class = new_class else @object_class || find_inherited_value(:object_class, GraphQL::Schema::Object) end end
An object class to use for deriving return types
Parameters
-
new_class(Class, nil) — Defaults toGraphQL::Schema::Object
Returns
-
Class
# File lib/graphql/schema/resolver/has_payload_type.rb, line 29 def payload_type(new_payload_type = nil) if new_payload_type @payload_type = new_payload_type end @payload_type ||= generate_payload_type end
Call this method to get the derived return type of the mutation, or use it as a configuration method to assign a return type instead of generating one.
Parameters
-
new_payload_type(Class, nil) — If a type definition class is provided, it will be used as the return type of the mutation field
Returns
-
Class— The object type which this mutation returns.
Also aliased as: type_expr
# File lib/graphql/schema/resolver/has_payload_type.rb, line 36 def type(new_type = nil, null: nil) if new_type payload_type(new_type) if !null.nil? self.null(null) end else super() end end
Calls superclass method
Alias for: payload_type