Class: GraphQL::Query::Result
- Inherits:
-
Object
- Object
- GraphQL::Query::Result
- Extended by:
- Delegate
- Defined in:
- lib/graphql/query/result.rb
Overview
A result from Schema#execute. It provides the requested data and access to the GraphQL::Query and Context.
Instance Attribute Summary collapse
-
#query ⇒ GraphQL::Query
readonly
The query that was executed.
-
#to_h ⇒ Hash
readonly
The resulting hash of "data" and/or "errors".
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
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
Methods included from Delegate
Constructor Details
#initialize(query:, values:) ⇒ Result
Returns a new instance of Result.
11 12 13 14 |
# File 'lib/graphql/query/result.rb', line 11 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.
27 28 29 30 31 32 33 |
# File 'lib/graphql/query/result.rb', line 27 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 ⇒ GraphQL::Query (readonly)
Returns The query that was executed.
17 18 19 |
# File 'lib/graphql/query/result.rb', line 17 def query @query end |
#to_h ⇒ Hash (readonly)
Returns The resulting hash of "data" and/or "errors".
20 21 22 |
# File 'lib/graphql/query/result.rb', line 20 def to_h @to_h end |
Instance Method Details
#==(other) ⇒ Boolean
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.)
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/graphql/query/result.rb', line 51 def ==(other) case other when Hash @to_h == other when Query::Result @to_h == other.to_h else super end end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/graphql/query/result.rb', line 39 def inspect "#<GraphQL::Query::Result @query=... @to_h=#{@to_h} >" end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
35 36 37 |
# File 'lib/graphql/query/result.rb', line 35 def respond_to_missing?(method_name, include_private = false) @to_h.respond_to?(method_name) || super end |