Class: GraphQL::Client::Query
- Inherits:
-
Object
- Object
- GraphQL::Client::Query
- Defined in:
- lib/graphql/client/query.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Public: Hash of contextual metadata.
-
#document ⇒ Object
readonly
Public: A parsed GraphQL::Language::Nodes::Document of the query.
-
#operation_name ⇒ Object
readonly
Public: String name of operation to execute.
-
#variables ⇒ Object
readonly
Public: Hash of variables to execute with the operation.
Instance Method Summary collapse
-
#initialize(document, operation_name: nil, variables: {}, context: {}) ⇒ Query
constructor
Internal: Construct Query.
-
#operation ⇒ Object
Public: Get operation definition node.
-
#operation_type ⇒ Object
Public: Query operation type.
-
#payload ⇒ Object
Internal: Payload object to pass to ActiveSupport::Notifications.
-
#to_s ⇒ Object
Public: Serialized query string.
Constructor Details
#initialize(document, operation_name: nil, variables: {}, context: {}) ⇒ Query
Internal: Construct Query.
Avoid creating queries with this constructor, perfer using Client#query.
document - A parsed GraphQL::Language::Nodes::Document of the query operation_name - String operation to execute variables - Hash of variables to execute with the operation context - Hash of metadata to pass to network adapter
12 13 14 15 16 17 |
# File 'lib/graphql/client/query.rb', line 12 def initialize(document, operation_name: nil, variables: {}, context: {}) @document = document @operation_name = operation_name @variables = variables @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Public: Hash of contextual metadata.
29 30 31 |
# File 'lib/graphql/client/query.rb', line 29 def context @context end |
#document ⇒ Object (readonly)
Public: A parsed GraphQL::Language::Nodes::Document of the query.
20 21 22 |
# File 'lib/graphql/client/query.rb', line 20 def document @document end |
#operation_name ⇒ Object (readonly)
Public: String name of operation to execute.
23 24 25 |
# File 'lib/graphql/client/query.rb', line 23 def operation_name @operation_name end |
#variables ⇒ Object (readonly)
Public: Hash of variables to execute with the operation.
26 27 28 |
# File 'lib/graphql/client/query.rb', line 26 def variables @variables end |
Instance Method Details
#operation ⇒ Object
Public: Get operation definition node.
Returns GraphQL::Language::Nodes::OperationDefinition.
41 42 43 |
# File 'lib/graphql/client/query.rb', line 41 def operation document.definitions.find { |node| node.name == operation_name } end |
#operation_type ⇒ Object
Public: Query operation type
Returns “query”, “mutation” or “subscription”.
48 49 50 |
# File 'lib/graphql/client/query.rb', line 48 def operation_type operation.operation_type end |
#payload ⇒ Object
Internal: Payload object to pass to ActiveSupport::Notifications.
Returns Hash.
55 56 57 58 59 60 61 62 |
# File 'lib/graphql/client/query.rb', line 55 def payload { document: document, operation_name: operation_name, operation_type: operation_type, variables: variables } end |
#to_s ⇒ Object
Public: Serialized query string
Returns String.
34 35 36 |
# File 'lib/graphql/client/query.rb', line 34 def to_s document.to_query_string end |