diff --git a/lib/graphql/client/http.rb b/lib/graphql/client/http.rb index ba4b764..e992f04 100644 --- a/lib/graphql/client/http.rb +++ b/lib/graphql/client/http.rb @@ -29,7 +29,7 @@ module GraphQL # block - Optional block to configure class def initialize(uri, &block) @uri = URI.parse(uri) - class_eval(&block) if block_given? + singleton_class.class_eval(&block) if block_given? end # Public: Parsed endpoint URI diff --git a/test/test_http.rb b/test/test_http.rb index ed0b255..24d6bcf 100644 --- a/test/test_http.rb +++ b/test/test_http.rb @@ -3,8 +3,10 @@ require "graphql/client/http" require "minitest/autorun" class TestHTTP < MiniTest::Test - def setup - @http = GraphQL::Client::HTTP.new("http://graphql-swapi.parseapp.com/") + SWAPI = GraphQL::Client::HTTP.new("http://graphql-swapi.parseapp.com/") do + def headers(_context) + { "User-Agent" => "GraphQL/1.0" } + end end def test_execute @@ -28,7 +30,7 @@ class TestHTTP < MiniTest::Test } } } - actual = @http.execute(document: document, operation_name: name, variables: variables) + actual = SWAPI.execute(document: document, operation_name: name, variables: variables) assert_equal(expected, actual) end end