Sha256: b94243ff333522de385160985ad1bebc50485b9e355e91115f76ae126c4cc083

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

class SoulsApiSchema < GraphQL::Schema
  default_max_page_size 100
  mutation(Types::MutationType)
  query(Types::QueryType)
  use GraphQL::Batch

  def self.id_from_object(object, _type_definition, _query_ctx)
    # Call your application"s UUID method here
    # It should return a string
    to_global_id(object.class.name, object.id)
  end

  def self.object_from_id(id, _query_ctx)
    class_name, item_id = from_global_id(id)

    # "Post" => Post.find(item_id)
    Object.const_get(class_name).find(item_id)
  end

  def self.resolve_type(_type, obj, _ctx)
    case obj
    when Article
      Types::ArticleType
    when User
      Types::UserType
    when ArticleCategory
      Types::ArticleCategoryType
    when JobConsole
      Types::JobConsoleType
    else
      GraphQL::ExecutionError.new("Unexpected object: #{obj}")
    end
  end

  def self.to_global_id(class_name, item_id)
    Base64.strict_encode64("#{class_name}:#{item_id}")
  end

  def self.from_global_id(global_id)
    token = Base64.decode64(global_id)
    token.split(":")
  end
end

Version data entries

6 entries across 4 versions & 1 rubygems

Version Path
souls-0.24.2 apps/api/app/graphql/souls_api_schema.rb
souls-0.24.2 apps/worker/app/graphql/souls_api_schema.rb
souls-0.24.1 apps/api/app/graphql/souls_api_schema.rb
souls-0.24.1 apps/worker/app/graphql/souls_api_schema.rb
souls-0.22.8 hoy/app/graphql/souls_api_schema.rb
souls-0.22.7 hoy/app/graphql/souls_api_schema.rb