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

  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.



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

def ast_nodes
  @ast_nodes
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#field_definitionObject (readonly)

Returns the value of attribute field_definition.



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

def field_definition
  @field_definition
end

#multiplexObject

Returns the value of attribute multiplex.



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

def multiplex
  @multiplex
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



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

def query
  @query
end

#result_valuesObject

Returns the value of attribute result_values.



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

def result_values
  @result_values
end

#root_typeObject (readonly)

Returns the value of attribute root_type.



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

def root_type
  @root_type
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

Instance Method Details

#analysis_errors=(_ignored) ⇒ Object



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

def analysis_errors=(_ignored)
  # pass
end

#analyzersObject



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

def analyzers
  EmptyObjects::EMPTY_ARRAY
end

#current_traceObject



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

def current_trace
  @query.current_trace
end

#fragmentsObject



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

def fragments
  @query.fragments
end

#leaf?Boolean

Returns:

  • (Boolean)


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

def leaf?
  @leaf
end

#resolve_typeObject



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

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

#resultObject



69
70
71
# File 'lib/graphql/query/partial.rb', line 69

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

#selected_operationObject



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

def selected_operation
  ast_nodes.first
end

#selected_operation_nameObject



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

def selected_operation_name
  @query.selected_operation_name
end

#static_errorsObject



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

def static_errors
  @query.static_errors
end

#subscription?Boolean

Returns:

  • (Boolean)


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

def subscription?
  @query.subscription?
end

#typesObject



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

def types
  @query.types
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  @query.valid?
end

#variablesObject



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

def variables
  @query.variables
end