Class: Osso::GraphQL::Schema

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

Class Method Summary collapse

Class Method Details

.id_from_object(object, _type_definition = nil, _query_ctx = nil) ⇒ Object



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

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

.object_from_id(id, _query_ctx = nil) ⇒ Object



25
26
27
28
# File 'lib/osso/graphql/schema.rb', line 25

def self.object_from_id(id, _query_ctx = nil)
  class_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
  Object.const_get(class_name).find(item_id)
end

.resolve_type(_type, obj, _ctx) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/osso/graphql/schema.rb', line 30

def self.resolve_type(_type, obj, _ctx)
  case obj
  when Osso::Models::EnterpriseAccount
    Types::EnterpriseAccount
  when Osso::Models::IdentityProvider
    Types::IdentityProvider
  else
    raise("Unexpected object: #{obj}")
  end
end

.unauthorized_object(error) ⇒ Object

Raises:

  • (::GraphQL::ExecutionError)


41
42
43
# File 'lib/osso/graphql/schema.rb', line 41

def self.unauthorized_object(error)
  raise ::GraphQL::ExecutionError, "An object of type #{error.type.graphql_name} was hidden due to permissions"
end