Module: GraphQL::Types::Relay::ConnectionBehaviors::ClassMethods

Defined in:
lib/graphql/types/relay/connection_behaviors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#edge_classClass (readonly)

Returns:

  • (Class)


23
24
25
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 23

def edge_class
  @edge_class
end

#node_typeClass (readonly)

Returns:

  • (Class)


20
21
22
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 20

def node_type
  @node_type
end

Instance Method Details

#accessible?(ctx) ⇒ Boolean

Returns:



68
69
70
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 68

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

#authorized?(obj, ctx) ⇒ Boolean

Returns:



64
65
66
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 64

def authorized?(obj, ctx)
  true # Let nodes be filtered out
end

#edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: true, node_nullable: self.node_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).



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 35

def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: true, node_nullable: self.node_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: true],
    null: true,
    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

#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.



78
79
80
81
82
83
84
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 78

def node_nullable(new_value = nil)
  if new_value.nil?
    @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



60
61
62
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 60

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



55
56
57
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 55

def scope_items(items, context)
  node_type.scope_items(items, context)
end

#visible?(ctx) ⇒ Boolean

Returns:



72
73
74
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 72

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