Class: Tasker::TaskerRailsSchema
- Inherits:
-
GraphQL::Schema
- Object
- GraphQL::Schema
- Tasker::TaskerRailsSchema
- Defined in:
- app/graphql/tasker/tasker_rails_schema.rb
Defined Under Namespace
Classes: InvalidObjectTypeError, TypeResolutionError, UnknownInterfaceError
Class Method Summary collapse
-
.id_from_object(object, type_definition, query_ctx) ⇒ Object
Return a string UUID for
object
. -
.object_from_id(id, query_ctx) ⇒ Object
Given a string UUID, find the object.
-
.resolve_type(abstract_type, obj, _ctx) ⇒ Object
Union and Interface Resolution.
Class Method Details
.id_from_object(object, type_definition, query_ctx) ⇒ Object
Return a string UUID for object
35 36 37 38 39 40 |
# File 'app/graphql/tasker/tasker_rails_schema.rb', line 35 def self.id_from_object(object, type_definition, query_ctx) # Here's a simple implementation which: # - joins the type name & object.id # - encodes it with base64: # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id) end |
.object_from_id(id, query_ctx) ⇒ Object
Given a string UUID, find the object
43 44 45 46 47 48 49 50 |
# File 'app/graphql/tasker/tasker_rails_schema.rb', line 43 def self.object_from_id(id, query_ctx) # For example, to decode the UUIDs generated above: # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id) # # Then, based on `type_name` and `id` # find an object in your application # ... end |
.resolve_type(abstract_type, obj, _ctx) ⇒ Object
Union and Interface Resolution
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/graphql/tasker/tasker_rails_schema.rb', line 17 def self.resolve_type(abstract_type, obj, _ctx) case abstract_type.graphql_name when 'TaskInterface' # TaskInterface is only implemented by TaskType unless obj.is_a?(Tasker::Task) || (obj.is_a?(Hash) && obj.key?(:named_task_id)) raise InvalidObjectTypeError, "Unable to resolve TaskInterface for object: #{obj.class}" end GraphQLTypes::TaskType else raise UnknownInterfaceError, "Unknown abstract type: #{abstract_type.graphql_name}" end end |