Module: GraphQL::Compatibility::LazyExecutionSpecification::LazySchema

Defined in:
lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb

Defined Under Namespace

Modules: LazyInstrumentation Classes: LazyPush, LazyPushCollection

Class Method Summary collapse

Class Method Details

.build(execution_strategy) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb', line 55

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