module GraphQL::Types::Relay
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:
-
Migrate the extensions from {Types::Relay::BaseObject} into _your app's_ base object
-
Copy {Relay::BaseConnection}, {Relay::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.
Constants
- DeprecatedNodeField
Don't use this field directly, instead, use one of these approaches:
@example Adding this field directly
include GraphQL::Types::Relay::HasNodeField
@example Implementing a similar field in your own
Query
rootfield :node, GraphQL::Types::Relay::Node, null: true, description: "Fetches an object given its ID" do argument :id, ID, required: true end def node(id:) context.schema.object_from_id(id, context) end
- DeprecatedNodesField
Public Class Methods
Don't use this directly, instead, use one of these:
@example Adding this field directly
include GraphQL::Types::Relay::HasNodesField
@example 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
# File lib/graphql/types/relay/nodes_field.rb, line 23 def self.const_missing(const_name) if const_name == :NodesField message = "NodesField is deprecated, use `include GraphQL::Types::Relay::HasNodesField` instead." message += "\n(referenced from #{caller(1, 1).first})" GraphQL::Deprecation.warn(message) DeprecatedNodesField elsif 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