Class: GraphQL::Query::Partial

Inherits:
Object
  • Object
show all
Includes:
Runnable
Defined in:
lib/graphql/query/partial.rb

Overview

This class is like a GraphQL::Query, except it can run on an arbitrary path within a query string.

It depends on a "parent" GraphQL::Query.

During execution, it calls query-related tracing hooks but passes itself as query:.

The Partial will use your Schema.resolve_type hook to find the right GraphQL type to use for object in some cases.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Runnable

#after_lazy, #arguments_cache, #arguments_for, #handle_or_reraise

Constructor Details

#initialize(path: nil, object:, query:, context: nil, fragment_node: nil, type: nil) ⇒ Partial

Returns a new instance of Partial.

Parameters:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/graphql/query/partial.rb', line 22

def initialize(path: nil, object:, query:, context: nil, fragment_node: nil, type: nil)
  @path = path
  @object = object
  @query = query
  @schema = query.schema
  context_vals = @query.context.to_h
  if context
    context_vals = context_vals.merge(context)
  end
  @context = GraphQL::Query::Context.new(query: self, schema: @query.schema, values: context_vals)
  @multiplex = nil
  @result_values = nil
  @result = nil
  @finalizers = @top_level_finalizers = nil

  if fragment_node
    @ast_nodes = [fragment_node]
    @root_type = type || raise(ArgumentError, "Pass `type:` when using `node:`")
    # This is only used when `@leaf`
    @field_definition = nil
  elsif path.nil?
    raise ArgumentError, "`path:` is required if `node:` is not given; add `path:`"
  else
    set_type_info_from_path
  end

  @leaf = @root_type.unwrap.kind.leaf?
end

Instance Attribute Details

#ast_nodesObject (readonly)

Returns the value of attribute ast_nodes.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def ast_nodes
  @ast_nodes
end

#contextObject (readonly)

Returns the value of attribute context.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def context
  @context
end

#field_definitionObject (readonly)

Returns the value of attribute field_definition.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def field_definition
  @field_definition
end

#multiplexObject

Returns the value of attribute multiplex.



61
62
63
# File 'lib/graphql/query/partial.rb', line 61

def multiplex
  @multiplex
end

#objectObject (readonly)

Returns the value of attribute object.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def object
  @object
end

#pathObject (readonly)

Returns the value of attribute path.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def query
  @query
end

#result_valuesObject

Returns the value of attribute result_values.



61
62
63
# File 'lib/graphql/query/partial.rb', line 61

def result_values
  @result_values
end

#root_typeObject (readonly)

Returns the value of attribute root_type.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def root_type
  @root_type
end

#schemaObject (readonly)

Returns the value of attribute schema.



59
60
61
# File 'lib/graphql/query/partial.rb', line 59

def schema
  @schema
end

Instance Method Details

#analysis_errors=(_ignored) ⇒ Object



118
119
120
# File 'lib/graphql/query/partial.rb', line 118

def analysis_errors=(_ignored)
  # pass
end

#analyzersObject



114
115
116
# File 'lib/graphql/query/partial.rb', line 114

def analyzers
  EmptyObjects::EMPTY_ARRAY
end

#current_traceObject



78
79
80
# File 'lib/graphql/query/partial.rb', line 78

def current_trace
  @query.current_trace
end

#fragmentsObject



94
95
96
# File 'lib/graphql/query/partial.rb', line 94

def fragments
  @query.fragments
end

#leaf?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/graphql/query/partial.rb', line 51

def leaf?
  @leaf
end

#query?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/graphql/query/partial.rb', line 106

def query?
  true
end

#resolve_typeObject



86
87
88
# File 'lib/graphql/query/partial.rb', line 86

def resolve_type(...)
  @query.resolve_type(...)
end

#resultObject



74
75
76
# File 'lib/graphql/query/partial.rb', line 74

def result
  @result ||= Result.new(query: self, values: result_values)
end

#root_valueObject



55
56
57
# File 'lib/graphql/query/partial.rb', line 55

def root_value
  object
end

#run_partialsObject



110
111
112
# File 'lib/graphql/query/partial.rb', line 110

def run_partials(...)
  @query.run_partials(...)
end

#selected_operationObject



126
127
128
# File 'lib/graphql/query/partial.rb', line 126

def selected_operation
  Language::Nodes::OperationDefinition.new(selections: ast_nodes.flat_map(&:selections))
end

#selected_operation_nameObject



134
135
136
# File 'lib/graphql/query/partial.rb', line 134

def selected_operation_name
  @query.selected_operation_name
end

#static_errorsObject



130
131
132
# File 'lib/graphql/query/partial.rb', line 130

def static_errors
  @query.static_errors
end

#subscription?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/graphql/query/partial.rb', line 122

def subscription?
  @query.subscription?
end

#typesObject



82
83
84
# File 'lib/graphql/query/partial.rb', line 82

def types
  @query.types
end

#valid?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/graphql/query/partial.rb', line 102

def valid?
  @query.valid?
end

#validateObject



98
99
100
# File 'lib/graphql/query/partial.rb', line 98

def validate
  @query.validate
end

#variablesObject



90
91
92
# File 'lib/graphql/query/partial.rb', line 90

def variables
  @query.variables
end