Class: GraphQL::Query::Result
- Inherits:
-
Object
- Object
- GraphQL::Query::Result
- Extended by:
- Forwardable
- Defined in:
- lib/graphql/query/result.rb
Overview
A result from Schema.execute. It provides the requested data and access to the Query and Query::Context.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns.
-
#to_h ⇒ Object
readonly
Returns.
Instance Method Summary collapse
-
#==(other) ⇒ Object
A result is equal to another object when:.
-
#initialize(query:, values:) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
-
#method_missing(method_name, *args, &block) ⇒ Object
Delegate any hash-like method to the underlying hash.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(query:, values:) ⇒ Result
Returns a new instance of Result.
13 14 15 16 |
# File 'lib/graphql/query/result.rb', line 13 def initialize(query:, values:) @query = query @to_h = values end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Delegate any hash-like method to the underlying hash.
33 34 35 36 37 38 39 |
# File 'lib/graphql/query/result.rb', line 33 def method_missing(method_name, *args, &block) if @to_h.respond_to?(method_name) @to_h.public_send(method_name, *args, &block) else super end end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns
GraphQL::Query— The query that was executed
21 22 23 |
# File 'lib/graphql/query/result.rb', line 21 def query @query end |
#to_h ⇒ Object (readonly)
Returns
Hash— The resulting hash of "data" and/or "errors"
26 27 28 |
# File 'lib/graphql/query/result.rb', line 26 def to_h @to_h end |
Instance Method Details
#==(other) ⇒ Object
A result is equal to another object when:
- The other object is a Hash whose value matches
result.to_h - The other object is a Result whose value matches
result.to_h
(The query is ignored for comparing result equality.)
Returns
Boolean
:call-seq:
==(other) -> bool
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/graphql/query/result.rb', line 62 def ==(other) case other when Hash @to_h == other when Query::Result @to_h == other.to_h else super end end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/graphql/query/result.rb', line 45 def inspect "#<GraphQL::Query::Result @query=... @to_h=#{@to_h}>" end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
41 42 43 |
# File 'lib/graphql/query/result.rb', line 41 def respond_to_missing?(method_name, include_private = false) @to_h.respond_to?(method_name) || super end |