Class: GraphQL::Client::Query::Operation
- Inherits:
-
Object
- Object
- GraphQL::Client::Query::Operation
- Includes:
- HasSelectionSet
- Defined in:
- lib/graphql_client/query/operation.rb
Direct Known Subclasses
Constant Summary
Constants included from HasSelectionSet
HasSelectionSet::ID_FIELD_NAME, HasSelectionSet::INVALID_FIELD, HasSelectionSet::UNDEFINED_FRAGMENT
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#selection_set ⇒ Object
readonly
Returns the value of attribute selection_set.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#initialize(document, name: nil, variables: {}) {|_self| ... } ⇒ Operation
constructor
A new instance of Operation.
- #schema ⇒ Object
- #to_query ⇒ Object (also: #to_s)
Methods included from HasSelectionSet
#add_connection, #add_field, #add_fields, #add_fragment
Constructor Details
#initialize(document, name: nil, variables: {}) {|_self| ... } ⇒ Operation
Returns a new instance of Operation.
11 12 13 14 15 16 17 18 |
# File 'lib/graphql_client/query/operation.rb', line 11 def initialize(document, name: nil, variables: {}) @document = document @name = name @selection_set = SelectionSet.new @variables = variables yield self if block_given? end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
9 10 11 |
# File 'lib/graphql_client/query/operation.rb', line 9 def document @document end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/graphql_client/query/operation.rb', line 9 def name @name end |
#selection_set ⇒ Object (readonly)
Returns the value of attribute selection_set.
9 10 11 |
# File 'lib/graphql_client/query/operation.rb', line 9 def selection_set @selection_set end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
9 10 11 |
# File 'lib/graphql_client/query/operation.rb', line 9 def variables @variables end |
Instance Method Details
#schema ⇒ Object
20 21 22 |
# File 'lib/graphql_client/query/operation.rb', line 20 def schema document.schema end |
#to_query ⇒ Object Also known as: to_s
24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql_client/query/operation.rb', line 24 def to_query operation_type.dup.tap do |query_string| query_string << " #{name}" if name query_string << "(#{variables_string.join(', ')})" if variables.any? query_string << " {\n" query_string << selection_set.to_query query_string << "\n}\n" end end |