Class: SolidusGraphqlApi::Schema

Inherits:
GraphQL::Schema
  • Object
show all
Defined in:
lib/solidus_graphql_api/schema.rb

Class Method Summary collapse

Class Method Details

.id_from_object(object, _type_definition, _query_ctx) ⇒ Object

Return a string UUID for object



21
22
23
# File 'lib/solidus_graphql_api/schema.rb', line 21

def id_from_object(object, _type_definition, _query_ctx)
  GraphQL::Schema::UniqueWithinType.encode(object.class.name, object.id)
end

.object_from_id(id, _query_ctx) ⇒ Object

Given a string UUID, find the object



26
27
28
29
30
# File 'lib/solidus_graphql_api/schema.rb', line 26

def object_from_id(id, _query_ctx)
  class_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)

  ::Object.const_get(class_name).find(item_id)
end

.resolve_type(_type_definition, object, _query_ctx) ⇒ Object

Object Resolution



33
34
35
36
37
# File 'lib/solidus_graphql_api/schema.rb', line 33

def resolve_type(_type_definition, object, _query_ctx)
  class_name = object.is_a?(Spree::PaymentMethod) ? "PaymentMethod" : object.class.name.demodulize

  Types.const_get(class_name)
end