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 = { "Content-Type" => "application/json" }.merge!(headers)
end

Instance Method Details

#call(_location, document, variables, _context) ⇒ Object



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

def call(_location, document, variables, _context)
  response = Net::HTTP.post(
    URI(@url),
    JSON.generate({ "query" => document, "variables" => variables }),
    @headers,
  )
  JSON.parse(response.body)
end