Module: GraphQL::Types::Relay

Defined in:
lib/graphql/types/relay.rb,
lib/graphql/types/relay/node.rb,
lib/graphql/types/relay/base_edge.rb,
lib/graphql/types/relay/page_info.rb,
lib/graphql/types/relay/node_field.rb,
lib/graphql/types/relay/nodes_field.rb,
lib/graphql/types/relay/default_relay.rb,
lib/graphql/types/relay/edge_behaviors.rb,
lib/graphql/types/relay/has_node_field.rb,
lib/graphql/types/relay/node_behaviors.rb,
lib/graphql/types/relay/base_connection.rb,
lib/graphql/types/relay/has_nodes_field.rb,
lib/graphql/types/relay/page_info_behaviors.rb,
lib/graphql/types/relay/connection_behaviors.rb

Overview

This module contains some types and fields that could support Relay conventions in GraphQL.

You can use these classes out of the box if you want, but if you want to use your own GraphQL extensions along with the features in this code, you could also open up the source files and copy the relevant methods and configuration into your own classes.

For example, the provided object types extend Types::Relay::BaseObject, but you might want to:

  1. Migrate the extensions from Types::Relay::BaseObject into your app’s base object
  2. Copy BaseConnection, BaseEdge, etc into your app, and change them to extend your base object.

Similarly, BaseField’s extensions could be migrated to your app and Node could be implemented to mix in your base interface module.

Defined Under Namespace

Modules: ConnectionBehaviors, DefaultRelay, EdgeBehaviors, HasNodeField, HasNodesField, Node, NodeBehaviors, PageInfoBehaviors Classes: BaseConnection, BaseEdge, PageInfo

Constant Summary collapse

DeprecatedNodeField =
GraphQL::Schema::Field.new(owner: nil, **HasNodeField.field_options, &HasNodeField.field_block)
DeprecatedNodesField =
GraphQL::Schema::Field.new(owner: nil, **HasNodesField.field_options, &HasNodesField.field_block)

Class Method Summary collapse

Class Method Details

.const_missing(const_name) ⇒ Object

Don’t use this directly, instead, use one of these:

Examples:

Adding this field directly

include GraphQL::Types::Relay::HasNodesField

Implementing a similar field in your own Query root


field :nodes, [GraphQL::Types::Relay::Node, null: true], null: false,
  description: Fetches a list of objects given a list of IDs." do
    argument :ids, [ID], required: true
  end

def nodes(ids:)
  ids.map do |id|
    context.schema.object_from_id(context, id)
  end
end


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/types/relay/node_field.rb', line 21

def self.const_missing(const_name)
  if const_name == :NodeField
    message = "NodeField is deprecated, use `include GraphQL::Types::Relay::HasNodeField` instead."
    message += "\n(referenced from #{caller(1, 1).first})"
    GraphQL::Deprecation.warn(message)

    DeprecatedNodeField
  else
    super
  end
end