class ServerTest < Minitest::Test include Rack::Test::Methods def app Server.new end def test_get_graphql_with_query_string header 'Content-Type', 'application/graphql' get '/', query: '{me}' assert last_response.ok? assert_equal 200, last_response.status refute_empty last_response.body json = JSON.parse(last_response.body) assert_equal 'mo', json['data']['me'] end def test_get_graphql_with_post_body header 'Content-Type', 'application/graphql' post '/', '{me}' assert last_response.ok? assert_equal 200, last_response.status refute_empty last_response.body json = JSON.parse(last_response.body) assert_equal 'mo', json['data']['me'] end def test_get_schema header 'Content-Type', 'application/graphql' post '/', '{ __schema { types { name } } }' assert last_response.ok? json = JSON.parse(last_response.body) [ 'Boolean', 'Cake', 'Query', 'String', '__Directive', '__DirectiveLocation', '__EnumValue', '__InputValue', '__Type', '__TypeKind', ].each do |type| assert json['data']['__schema']['types'].include?('name' => type) end end def test_get_query_type header 'Content-Type', 'application/graphql' post '/', '{ __schema { queryType { name } } }' assert last_response.ok? json = JSON.parse(last_response.body) assert 'Query', json['data']['__schema']['queryType']['name'] end def test_get_cakes_type header 'Content-Type', 'application/graphql' post '/', <<~GQL { __type(name: "Cake") { name kind } } GQL assert last_response.ok? json = JSON.parse(last_response.body) assert_equal 'Cake', json['data']['__type']['name'] assert_equal 'OBJECT', json['data']['__type']['kind'] end def test_get_cake_fields header 'Content-Type', 'application/graphql' post '/', <<~GQL { __type(name: "Cake") { name fields { name type { name kind } } } } GQL assert last_response.ok? json = JSON.parse(last_response.body) assert_equal 'Cake', json.dig('data', '__type', 'name') assert_equal [{ 'name' => 'name', 'type' => { 'name' => nil, 'kind' => 'NON_NULL' } }], json.dig('data', '__type', 'fields') end end