Sha256: 8d44bbfcff1b9e7bfc36cd64519d0342691e7274160b3522270de1166121ab63

Contents?: true

Size: 1.71 KB

Versions: 41

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Types
    module Relay
      # A class-based definition for Relay edges.
      #
      # Use this as a parent class in your app, or use it as inspiration for your
      # own base `Edge` class.
      #
      # For example, you may want to extend your own `BaseObject` instead of the
      # built-in `GraphQL::Schema::Object`.
      #
      # @example Making a UserEdge type
      #   # Make a base class for your app
      #   class Types::BaseEdge < GraphQL::Types::Relay::BaseEdge
      #   end
      #
      #   # Then extend your own base class
      #   class Types::UserEdge < Types::BaseEdge
      #     node_type(Types::User)
      #   end
      #
      # @see {Relay::BaseConnection} for connection types
      class BaseEdge < Types::Relay::BaseObject
        description "An edge in a connection."

        class << self
          # Get or set the Object type that this edge wraps.
          #
          # @param node_type [Class] A `Schema::Object` subclass
          # @param null [Boolean]
          def node_type(node_type = nil, null: true)
            if node_type
              @node_type = node_type
              # Add a default `node` field
              field :node, node_type, null: null, description: "The item at the end of the edge."
            end
            @node_type
          end

          def authorized?(obj, ctx)
            true
          end

          def accessible?(ctx)
            node_type.accessible?(ctx)
          end

          def visible?(ctx)
            node_type.visible?(ctx)
          end
        end


        field :cursor, String,
          null: false,
          description: "A cursor for use in pagination."
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
graphql-1.11.6 lib/graphql/types/relay/base_edge.rb
graphql-1.11.5 lib/graphql/types/relay/base_edge.rb
graphql-1.11.4 lib/graphql/types/relay/base_edge.rb
graphql-1.11.3 lib/graphql/types/relay/base_edge.rb
graphql-1.11.2 lib/graphql/types/relay/base_edge.rb
graphql-1.10.14 lib/graphql/types/relay/base_edge.rb
graphql-1.11.1 lib/graphql/types/relay/base_edge.rb
graphql-1.10.13 lib/graphql/types/relay/base_edge.rb
graphql-1.11.0 lib/graphql/types/relay/base_edge.rb
graphql-1.10.12 lib/graphql/types/relay/base_edge.rb
graphql-1.9.21 lib/graphql/types/relay/base_edge.rb
graphql-1.10.11 lib/graphql/types/relay/base_edge.rb
graphql-1.9.20 lib/graphql/types/relay/base_edge.rb
graphql-1.10.10 lib/graphql/types/relay/base_edge.rb
graphql-1.10.9 lib/graphql/types/relay/base_edge.rb
graphql-1.10.8 lib/graphql/types/relay/base_edge.rb
graphql-1.10.7 lib/graphql/types/relay/base_edge.rb
graphql-1.10.6 lib/graphql/types/relay/base_edge.rb
graphql-1.10.5 lib/graphql/types/relay/base_edge.rb
graphql-1.10.4 lib/graphql/types/relay/base_edge.rb