Sha256: 8c1f993df680852f61d446996548efafc58cba5ceaa57e4f984e22bfd9f5f607

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Compatibility
    module ExecutionSpecification
      module CounterSchema
        def self.build(execution_strategy)
          counter_type = nil
          schema = nil

          has_count_interface = GraphQL::InterfaceType.define do
            name "HasCount"
            field :count, types.Int
            field :counter, ->{ counter_type }
          end

          counter_type = GraphQL::ObjectType.define do
            name "Counter"
            interfaces [has_count_interface]
            field :count, types.Int, resolve: ->(o,a,c) { schema.metadata[:count] += 1 }
            field :counter, has_count_interface, resolve: ->(o,a,c) { :counter }
          end

          alt_counter_type = GraphQL::ObjectType.define do
            name "AltCounter"
            interfaces [has_count_interface]
            field :count, types.Int, resolve: ->(o,a,c) { schema.metadata[:count] += 1 }
            field :counter, has_count_interface, resolve: ->(o,a,c) { :counter }
          end

          has_counter_interface = GraphQL::InterfaceType.define do
            name "HasCounter"
            field :counter, counter_type
          end

          query_type = GraphQL::ObjectType.define do
            name "Query"
            interfaces [has_counter_interface]
            field :counter, has_count_interface, resolve: ->(o,a,c) { :counter }
          end

          schema = GraphQL::Schema.define(
            query: query_type,
            resolve_type: ->(o, c) { o == :counter ? counter_type : nil },
            orphan_types: [alt_counter_type],
            query_execution_strategy: execution_strategy,
          )
          schema.metadata[:count] = 0
          schema
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-1.4.5 lib/graphql/compatibility/execution_specification/counter_schema.rb
graphql-1.4.4 lib/graphql/compatibility/execution_specification/counter_schema.rb
graphql-1.4.3 lib/graphql/compatibility/execution_specification/counter_schema.rb
graphql-1.4.2 lib/graphql/compatibility/execution_specification/counter_schema.rb
graphql-1.4.1 lib/graphql/compatibility/execution_specification/counter_schema.rb
graphql-1.4.0 lib/graphql/compatibility/execution_specification/counter_schema.rb
graphql-1.3.0 lib/graphql/compatibility/execution_specification/counter_schema.rb