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

Extended by:
Forwardable
Included in:
BaseConnection
Defined in:
lib/graphql/types/relay/connection_behaviors.rb

Overview

-- @requires_ancestor: GraphQL::Schema::Object

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_page_info_field(obj_type) ⇒ Object



206
207
208
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 206

def add_page_info_field(obj_type)
  obj_type.field :page_info, GraphQL::Types::Relay::PageInfo, null: false, description: "Information to aid in pagination."
end

.included(child_class) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 14

def self.included(child_class)
  child_class.extend(ClassMethods)
  child_class.has_nodes_field(true)
  child_class.node_nullable(true)
  child_class.edges_nullable(true)
  child_class.edge_nullable(true)
  child_class.module_exec {
    #: self as GraphQL::Types::Relay::ConnectionBehaviors::ClassMethods
    self.edge_type = nil
    self.node_type = nil
    self.edge_class = nil
  }
  child_class.default_broadcastable(nil)
  add_page_info_field(child_class)
end

Instance Method Details

#edges ⇒ Object



211
212
213
214
215
216
217
218
219
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 211

def edges
  # Assume that whatever authorization needed to happen
  # already happened at the connection level.
  if (current_runtime_state = Fiber[:__graphql_runtime_info])
    query_runtime_state = current_runtime_state[context.query]
    query_runtime_state.was_authorized_by_scope_items = @object.was_authorized_by_scope_items?
  end
  @object.edges
end

#nodes ⇒ Object



221
222
223
224
225
226
227
228
229
# File 'lib/graphql/types/relay/connection_behaviors.rb', line 221

def nodes
  # Assume that whatever authorization needed to happen
  # already happened at the connection level.
  if (current_runtime_state = Fiber[:__graphql_runtime_info])
    query_runtime_state = current_runtime_state[context.query]
    query_runtime_state.was_authorized_by_scope_items = @object.was_authorized_by_scope_items?
  end
  @object.nodes
end