Sha256: a5aef60aa3a5d294ca37aeefaaad70c85fbb530504ba15d1e79e115e81a066bc

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require 'benchmark'

class BaseType < GraphQL::Schema::Object
  field_class GraphQL::Cache::Field
end

class OrderType < BaseType
  field :id, Int, null: false
  field :number, Int, null: true
  field :total_price_cents, Int, null: true
end

class CustomerType < BaseType
  field :display_name, String, null: false
  field :email, String, null: false
  field :orders, OrderType.connection_type, null: false, cache: true
end

class QueryType < BaseType
  field :customer, CustomerType, null: true, cache: true do
    argument :id, ID, 'Unique Identifier for querying a specific user', required: true
  end

  def customer(id:)
    Customer[id]
  end
end

class CacheSchema < GraphQL::Schema
  query QueryType

  use GraphQL::Cache

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

  def self.texecute(*args, **kwargs)
    result = nil
    measurement = Benchmark.measure { result = execute(*args, *kwargs) }
    GraphQL::Cache.logger.debug("Query executed in #{measurement.real}")
    result
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql-cache-0.6.0 test_schema/graphql_schema.rb
graphql-cache-0.5.0 test_schema/graphql_schema.rb
graphql-cache-0.4.0 test_schema/graphql_schema.rb
graphql-cache-0.3.0 test_schema/graphql_schema.rb