Class: SimpleGraphqlClient::Client
- Inherits:
-
Object
- Object
- SimpleGraphqlClient::Client
- Defined in:
- lib/simple_graphql_client/client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(url:, options: {}, &block) ⇒ Client
constructor
A new instance of Client.
- #query(gql:, variables: {}) ⇒ Object
Constructor Details
#initialize(url:, options: {}, &block) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 |
# File 'lib/simple_graphql_client/client.rb', line 10 def initialize(url:, options: {}, &block) @url = url @options = @request_options = block end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/simple_graphql_client/client.rb', line 8 def @options end |
Instance Method Details
#query(gql:, variables: {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/simple_graphql_client/client.rb', line 16 def query(gql:, variables: {}) response = RestClient.post(@url, { query: gql, variables: variables }.to_json, ) handle_response(JSON.parse(response.body, object_class: .fetch(:parsing_class, OpenStruct))) end |