Sha256: 9cf07910e2b3a33e79ee0e63a62924dc573b9e2d0f574065c266a7b3f2e4b185

Contents?: true

Size: 1.45 KB

Versions: 18

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Relay
    module ConnectionType
      class << self
        # @return [Boolean] If true, connection types get a `nodes` shortcut field
        attr_accessor :default_nodes_field
        # @return [Boolean] If true, connections check for reverse-direction `has*Page` values
        attr_accessor :bidirectional_pagination
      end

      self.default_nodes_field = false
      self.bidirectional_pagination = false

      # Create a connection which exposes edges of this type
      def self.create_type(wrapped_type, edge_type: wrapped_type.edge_type, edge_class: GraphQL::Relay::Edge, nodes_field: ConnectionType.default_nodes_field, &block)
        custom_edge_class = edge_class

        # Any call that would trigger `wrapped_type.ensure_defined`
        # must be inside this lazy block, otherwise we get weird
        # cyclical dependency errors :S
        ObjectType.define do
          name("#{wrapped_type.name}Connection")
          description("The connection type for #{wrapped_type.name}.")
          field :edges, types[edge_type], "A list of edges.", edge_class: custom_edge_class, property: :edge_nodes

          if nodes_field
            field :nodes, types[wrapped_type],  "A list of nodes.", property: :edge_nodes
          end

          field :pageInfo, !PageInfo, "Information to aid in pagination.", property: :page_info
          block && instance_eval(&block)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
graphql-1.7.14 lib/graphql/relay/connection_type.rb
graphql-1.7.13 lib/graphql/relay/connection_type.rb
graphql-1.7.12 lib/graphql/relay/connection_type.rb
graphql-1.7.11 lib/graphql/relay/connection_type.rb
graphql-1.7.10 lib/graphql/relay/connection_type.rb
graphql-1.7.9 lib/graphql/relay/connection_type.rb
graphql-1.8.0.pre4 lib/graphql/relay/connection_type.rb
graphql-1.8.0.pre3 lib/graphql/relay/connection_type.rb
graphql-1.7.8 lib/graphql/relay/connection_type.rb
graphql-1.8.0.pre2 lib/graphql/relay/connection_type.rb
graphql-1.7.7 lib/graphql/relay/connection_type.rb
graphql-1.8.0.pre1 lib/graphql/relay/connection_type.rb
graphql-1.7.6 lib/graphql/relay/connection_type.rb
graphql-1.7.5 lib/graphql/relay/connection_type.rb
graphql-1.7.4 lib/graphql/relay/connection_type.rb
graphql-1.7.3 lib/graphql/relay/connection_type.rb
graphql-1.7.2 lib/graphql/relay/connection_type.rb
graphql-1.7.1 lib/graphql/relay/connection_type.rb