Class: SimpleGraphqlClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_graphql_client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, &block) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/simple_graphql_client/client.rb', line 10

def initialize(url:, &block)
  @url = url
  @request_options = block
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/simple_graphql_client/client.rb', line 8

def options
  @options
end

Instance Method Details

#query(gql:, variables: {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/simple_graphql_client/client.rb', line 15

def query(gql:, variables: {})
  response = RestClient.post(@url, {
    query: gql,
    variables: variables
  }.to_json, request_options)
  Response.new(response)
end