Class: GraphQL::Client::Base
- Inherits:
-
Object
- Object
- GraphQL::Client::Base
- Defined in:
- lib/graphql_client/base.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #build_query ⇒ Object
- #configure {|@config| ... } ⇒ Object
-
#initialize(schema, config: nil, adapter: nil, &block) ⇒ Base
constructor
A new instance of Base.
- #query(query, operation_name: nil, variables: {}) ⇒ Object
- #raw_query(query_string, operation_name: nil, variables: {}) ⇒ Object
- #raw_query_with_extensions(query_string, operation_name: nil, variables: {}) ⇒ Object
Constructor Details
#initialize(schema, config: nil, adapter: nil, &block) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 |
# File 'lib/graphql_client/base.rb', line 8 def initialize(schema, config: nil, adapter: nil, &block) @config = config || Config.new @schema = load_schema(schema) @adapter = adapter || Adapters::HTTPAdapter.new(@config) instance_eval(&block) if block_given? end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/graphql_client/base.rb', line 6 def adapter @adapter end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/graphql_client/base.rb', line 6 def config @config end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/graphql_client/base.rb', line 6 def schema @schema end |
Instance Method Details
#build_query ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/graphql_client/base.rb', line 16 def build_query query = Query::Document.new(@schema) if block_given? yield query else query end end |
#configure {|@config| ... } ⇒ Object
26 27 28 |
# File 'lib/graphql_client/base.rb', line 26 def configure yield @config end |
#query(query, operation_name: nil, variables: {}) ⇒ Object
30 31 32 33 |
# File 'lib/graphql_client/base.rb', line 30 def query(query, operation_name: nil, variables: {}) response = adapter.request(query.to_query, operation_name: operation_name, variables: variables) GraphObject.new(data: response.data, query: query) end |
#raw_query(query_string, operation_name: nil, variables: {}) ⇒ Object
35 36 37 |
# File 'lib/graphql_client/base.rb', line 35 def raw_query(query_string, operation_name: nil, variables: {}) raw_query_with_extensions(query_string, operation_name: operation_name, variables: variables)[0] end |
#raw_query_with_extensions(query_string, operation_name: nil, variables: {}) ⇒ Object
39 40 41 42 |
# File 'lib/graphql_client/base.rb', line 39 def raw_query_with_extensions(query_string, operation_name: nil, variables: {}) response = adapter.request(query_string, operation_name: operation_name, variables: variables) [ResponseObject.new(response.data), ResponseObject.new(response.extensions)] end |