Class: GraphQL::CardSchema
- Inherits:
-
Schema
- Object
- Schema
- GraphQL::CardSchema
- Defined in:
- lib/graph_q_l/card_schema.rb
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`
18 19 20 21 22 23 |
# File 'lib/graph_q_l/card_schema.rb', line 18 def 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
26 27 28 29 30 31 32 33 |
# File 'lib/graph_q_l/card_schema.rb', line 26 def 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
9 10 11 12 13 |
# File 'lib/graph_q_l/card_schema.rb', line 9 def resolve_type abstract_type, obj, ctx # TODO: Implement this function # to return the correct object type for `obj` raise GraphQL::RequiredImplementationMissingError end |