Sha256: bf51737bb44f1e12af5e59eba44a0e57f94f6618e44fe8a8367657885a315731

Contents?: true

Size: 949 Bytes

Versions: 2

Compression:

Stored size: 949 Bytes

Contents

# frozen_string_literal: true

require 'graphql'
require 'graphql/groups'

class BaseType < GraphQL::Schema::Object; end

class AuthorGroupType < GraphQL::Groups::Schema::GroupType
  scope { Author.all }

  by :name
end

class SlowAuthorGroupResultType < GraphQL::Schema::Object
  field :key, String, null: false
  field :count, Integer, null: false

  def key
    object[0]
  end

  def count
    object[1].size
  end
end

class SlowAuthorGroupType < GraphQL::Schema::Object
  field :name, [SlowAuthorGroupResultType], null: false

  def name
    object.group_by(&:name)
  end
end

class QueryType < BaseType
  include GraphQL::Groups

  group :fast_groups, AuthorGroupType, camelize: true

  field :slow_groups, SlowAuthorGroupType, null: false, camelize: true

  def slow_groups
    Author.all
  end
end

class PerformanceSchema < GraphQL::Schema
  query QueryType

  def self.resolve_type(_type, obj, _ctx)
    "#{obj.class.name}Type"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-groups-0.1.3 benchmark/benchmark_schema.rb
graphql-groups-0.1.2 benchmark/benchmark_schema.rb