Sha256: 35685ec1ba3f2d9a728286f3a770b047720c1fa0d315afc7774ad6b3a370d13e

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

module GraphQL
  module Relay
    module ConnectionType
      # Create a connection which exposes edges of this type
      def self.create_type(wrapped_type, edge_type: nil, edge_class: nil, &block)
        edge_type ||= wrapped_type.edge_type
        edge_class ||= GraphQL::Relay::Edge
        connection_type_name = "#{wrapped_type.name}Connection"

        connection_type = ObjectType.define do
          name(connection_type_name)
          field :edges, types[edge_type] do
            resolve -> (obj, args, ctx) {
              obj.edge_nodes.map { |item| edge_class.new(item, obj) }
            }
          end
          field :pageInfo, PageInfo, property: :page_info
          block && instance_eval(&block)
        end

        connection_type
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-relay-0.11.2 lib/graphql/relay/connection_type.rb
graphql-relay-0.11.1 lib/graphql/relay/connection_type.rb
graphql-relay-0.11.0 lib/graphql/relay/connection_type.rb