Sha256: cdf93c243e1160ebae85a562b7efe15669cf2a96ec7b4f4d043dd3f3b35bf4a2

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'graphql'
require_relative 'types'
require_relative 'resolvers'
require_relative 'mutation'
require_relative 'query'

GraphQL::Relay::BaseConnection.register_connection_implementation(
  ActiveRecord::Relation,
  GraphQL::Relay::RelationConnection,
)

module Osso
  module GraphQL
    class Schema < ::GraphQL::Schema
      use ::GraphQL::Pagination::Connections
      query Types::QueryType
      mutation Types::MutationType

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

      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
osso-0.0.3.6 lib/osso/graphql/schema.rb