Module: GraphQL::Types::Relay::ConnectionBehaviors::ClassMethods
- Defined in:
- lib/graphql/types/relay/connection_behaviors.rb
Instance Attribute Summary collapse
-
#edge_class ⇒ Class
readonly
-
#node_type ⇒ Class
readonly
Instance Method Summary collapse
-
#accessible?(ctx) ⇒ Boolean
-
#authorized?(obj, ctx) ⇒ Boolean
-
#edge_nullable(new_value = nil) ⇒ Object
Set the default
edge_nullable
for this class and its child classes. -
#edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable) ⇒ Object
Configure this connection to return
edges
andnodes
based onedge_type_class
. -
#edges_nullable(new_value = nil) ⇒ Object
Set the default
edges_nullable
for this class and its child classes. -
#has_nodes_field(new_value = nil) ⇒ Object
Set the default
nodes_field
for this class and its child classes. -
#node_nullable(new_value = nil) ⇒ Object
Set the default
node_nullable
for this class and its child classes. -
#nodes_field(node_nullable: self.node_nullable) ⇒ Object
Add the shortcut
nodes
field to this connection and its subclasses. -
#scope_items(items, context) ⇒ Object
Filter this list according to the way its node type would scope them.
-
#visible?(ctx) ⇒ Boolean
Instance Attribute Details
#edge_class ⇒ Class (readonly)
26 27 28 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 26 def edge_class @edge_class end |
#node_type ⇒ Class (readonly)
23 24 25 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 23 def node_type @node_type end |
Instance Method Details
#accessible?(ctx) ⇒ Boolean
71 72 73 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 71 def accessible?(ctx) node_type.accessible?(ctx) end |
#authorized?(obj, ctx) ⇒ Boolean
67 68 69 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 67 def (obj, ctx) true # Let nodes be filtered out end |
#edge_nullable(new_value = nil) ⇒ Object
Set the default edge_nullable
for this class and its child classes. (Defaults to true
.)
Use edge_nullable(false)
in your base class to make non-null edge
fields.
101 102 103 104 105 106 107 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 101 def edge_nullable(new_value = nil) if new_value.nil? defined?(@edge_nullable) ? @edge_nullable : superclass.edge_nullable else @edge_nullable = new_value end end |
#edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable) ⇒ Object
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).
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 38 def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable) # Set this connection's graphql name node_type_name = node_type.graphql_name @node_type = node_type @edge_type = edge_type_class @edge_class = edge_class field :edges, [edge_type_class, null: edge_nullable], null: edges_nullable, description: "A list of edges.", legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation connection: false define_nodes_field(node_nullable) if nodes_field description("The connection type for #{node_type_name}.") end |
#edges_nullable(new_value = nil) ⇒ Object
Set the default edges_nullable
for this class and its child classes. (Defaults to true
.)
Use edges_nullable(false)
in your base class to make non-null edges
fields.
91 92 93 94 95 96 97 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 91 def edges_nullable(new_value = nil) if new_value.nil? defined?(@edges_nullable) ? @edges_nullable : superclass.edges_nullable else @edges_nullable = new_value end end |
#has_nodes_field(new_value = nil) ⇒ Object
Set the default nodes_field
for this class and its child classes. (Defaults to true
.)
Use nodes_field(false)
in your base class to prevent adding of a nodes field.
111 112 113 114 115 116 117 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 111 def has_nodes_field(new_value = nil) if new_value.nil? defined?(@nodes_field) ? @nodes_field : superclass.has_nodes_field else @nodes_field = new_value end end |
#node_nullable(new_value = nil) ⇒ Object
Set the default node_nullable
for this class and its child classes. (Defaults to true
.)
Use node_nullable(false)
in your base class to make non-null node
and nodes
fields.
81 82 83 84 85 86 87 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 81 def node_nullable(new_value = nil) if new_value.nil? defined?(@node_nullable) ? @node_nullable : superclass.node_nullable else @node_nullable = new_value end end |
#nodes_field(node_nullable: self.node_nullable) ⇒ Object
Add the shortcut nodes
field to this connection and its subclasses
63 64 65 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 63 def nodes_field(node_nullable: self.node_nullable) define_nodes_field(node_nullable) end |
#scope_items(items, context) ⇒ Object
Filter this list according to the way its node type would scope them
58 59 60 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 58 def scope_items(items, context) node_type.scope_items(items, context) end |
#visible?(ctx) ⇒ Boolean
75 76 77 |
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 75 def visible?(ctx) node_type.visible?(ctx) end |