Class: GraphQL::Stitching::RemoteClient

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/stitching/remote_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(url:, headers: {}) ⇒ RemoteClient

Returns a new instance of RemoteClient.



10
11
12
13
# File 'lib/graphql/stitching/remote_client.rb', line 10

def initialize(url:, headers:{})
  @url = url
  @headers = headers
end

Instance Method Details

#call(location, document, variables) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/graphql/stitching/remote_client.rb', line 15

def call(location, document, variables)
  response = Net::HTTP.post(
    URI(@url),
    { "query" => document, "variables" => variables }.to_json,
    { "Content-Type" => "application/json" }.merge!(@headers)
  )
  JSON.parse(response.body)
end