module GraphQL::Compatibility::LazyExecutionSpecification::LazySchema

Public Class Methods

build(execution_strategy) click to toggle source
# File lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb, line 68
def self.build(execution_strategy)
  lazy_push_type = GraphQL::ObjectType.define do
    name "LazyPush"
    field :value, !types.Int
    field :push, !lazy_push_type do
      argument :value, types.Int
      resolve ->(o, a, c) {
        LazyPush.new(c, a[:value])
      }
    end
  end

  query_type = GraphQL::ObjectType.define do
    name "Query"
    field :push, !lazy_push_type do
      argument :value, types.Int
      resolve ->(o, a, c) {
        LazyPush.new(c, a[:value])
      }
    end

    connection :pushes, lazy_push_type.connection_type do
      argument :values, types[types.Int]
      resolve ->(o, a, c) {
        LazyPushCollection.new(c, a[:values])
      }
    end
  end

  GraphQL::Schema.define do
    query(query_type)
    mutation(query_type)
    query_execution_strategy(execution_strategy)
    mutation_execution_strategy(execution_strategy)
    lazy_resolve(LazyPush, :push)
    lazy_resolve(LazyPushCollection, :push)
    instrument(:field, LazyInstrumentation)
  end
end