Class: GraphQL::Types::Relay::BaseConnection
- Inherits:
-
BaseObject
- Object
- Schema::Member
- Schema::Object
- BaseObject
- GraphQL::Types::Relay::BaseConnection
- Extended by:
- Forwardable
- Defined in:
- lib/graphql/types/relay/base_connection.rb
Overview
Use this to implement Relay connections, or take it as inspiration for Relay classes in your own app.
You may wish to copy this code into your own base class,
so you can extend your own BaseObject
instead of GraphQL::Schema::Object
.
Constant Summary
Constants included from Schema::Member::GraphQLTypeNames
Schema::Member::GraphQLTypeNames::Boolean, Schema::Member::GraphQLTypeNames::ID, Schema::Member::GraphQLTypeNames::Int
Class Attribute Summary collapse
-
.edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type) ⇒ Object
readonly
Configure this connection to return
edges
andnodes
based onedge_type_class
. -
.node_type ⇒ Class
readonly
Attributes inherited from Schema::Object
Class Method Summary collapse
-
.nodes_field ⇒ Object
Add the shortcut
nodes
field to this connection and its subclasses.
Instance Method Summary collapse
-
#nodes ⇒ Object
By default this calls through to the ConnectionWrapper’s edge nodes method, but sometimes you need to override it to support the
nodes
field.
Methods inherited from BaseObject
default_relay, default_relay?, to_graphql
Methods inherited from Schema::Object
authorized_new, fields, implements, #initialize, interfaces, kind, own_interfaces, to_graphql
Methods included from Schema::Member::HasFields
add_default_resolve_module, #add_field, extended, #field, #field_class, #fields, #global_id_field, #included, #inherited, #own_fields
Methods included from Schema::Member::TypeSystemHelpers
#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Schema::Member::BaseDSLMethods
#accessible?, #authorized?, #description, #graphql_name, #introspection, #mutation, #name, #overridden_graphql_name, #to_graphql, #visible?
Methods included from Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Schema::Member::CachedGraphQLDefinition
#graphql_definition, #initialize_copy
Constructor Details
This class inherits a constructor from GraphQL::Schema::Object
Class Attribute Details
.edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type) ⇒ Object (readonly)
Configure this connection to return edges
and nodes
based on edge_type_class
.
This method will use the inputs to create:
- edges
field
- nodes
field
- description
It’s called when you subclass this base connection, trying to use the class name to set defaults. You can call it again in the class definition to override the default (or provide a value, if the default lookup failed).
39 40 41 |
# File 'lib/graphql/types/relay/base_connection.rb', line 39 def edge_type @edge_type end |
.node_type ⇒ Class (readonly)
36 37 38 |
# File 'lib/graphql/types/relay/base_connection.rb', line 36 def node_type @node_type end |
Class Method Details
.nodes_field ⇒ Object
Add the shortcut nodes
field to this connection and its subclasses
72 73 74 |
# File 'lib/graphql/types/relay/base_connection.rb', line 72 def nodes_field field :nodes, [@node_type, null: true], null: true end |
Instance Method Details
#nodes ⇒ Object
By default this calls through to the ConnectionWrapper’s edge nodes method,
but sometimes you need to override it to support the nodes
field
81 82 83 |
# File 'lib/graphql/types/relay/base_connection.rb', line 81 def nodes @object.edge_nodes end |