Class: ForemanGraphqlSchema

Inherits:
GraphQL::Schema
  • Object
show all
Defined in:
app/graphql/foreman_graphql_schema.rb

Class Method Summary collapse

Class Method Details

.id_from_object(object, type_definition, query_ctx) ⇒ Object


17
18
19
# File 'app/graphql/foreman_graphql_schema.rb', line 17

def self.id_from_object(object, type_definition, query_ctx)
  Foreman::GlobalId.encode(type_definition.name, object.id)
end

.object_from_id(id, query_ctx) ⇒ Object


21
22
23
24
25
26
27
28
29
30
# File 'app/graphql/foreman_graphql_schema.rb', line 21

def self.object_from_id(id, query_ctx)
  return unless id.present?

  _, model_class_name, item_id = Foreman::GlobalId.decode(id)
  model_class = ForemanGraphqlSchema.types.keys.find { |t| t == model_class_name }&.safe_constantize

  return unless model_class

  RecordLoader.for(model_class).load(item_id.to_i)
end

.resolve_type(_, object, _) ⇒ Object


32
33
34
35
# File 'app/graphql/foreman_graphql_schema.rb', line 32

def self.resolve_type(_, object, _)
  klass = object.class
  klass.try(:graphql_type)&.safe_constantize || types[klass.name]
end