Module: GraphQLIncludable

Defined in:
lib/graphql_includable.rb,
lib/graphql_includable/includes.rb,
lib/graphql_includable/resolver.rb,
lib/graphql_includable/includes_builder.rb,
lib/graphql_includable/relay/edge_with_node.rb,
lib/graphql_includable/relay/instrumentation.rb,
lib/graphql_includable/relay/edge_with_node_connection.rb,
lib/graphql_includable/relay/edge_with_node_connection_type.rb

Defined Under Namespace

Modules: Relay Classes: ConnectionEdgesIncludesBuilder, ConnectionIncludesBuilder, Includes, IncludesBuilder, Resolver

Class Method Summary collapse

Class Method Details

.includes(ctx, starting_at: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/graphql_includable.rb', line 9

def self.includes(ctx, starting_at: nil)
  ActiveSupport::Notifications.instrument('graphql_includable.includes') do |instrument|
    instrument[:operation_name] = ctx.query&.operation_name
    instrument[:field_name] = ctx.irep_node.name
    instrument[:starting_at] = starting_at

    includes = Includes.new(nil)
    resolver = Resolver.new(ctx)

    node = ctx.irep_node
    node = node_for_path(node, starting_at) if starting_at.present?

    generated_includes = if node.present?
                           resolver.includes_for_node(node, includes)
                           includes.active_record_includes
                         end

    instrument[:includes] = generated_includes
    generated_includes
  end
end

.node_for_path(node, path_into_query) ⇒ Object



31
32
33
34
# File 'lib/graphql_includable.rb', line 31

def self.node_for_path(node, path_into_query)
  children = node.scoped_children[node.return_type.unwrap]&.with_indifferent_access || {}
  children.dig(path_into_query)
end