Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ describe('test harness', () => {
}),
);

expect(response.status).to.equal(200);
expect(response.status).to.equal(500);
expect(JSON.parse(response.text)).to.deep.equal({
errors: [
{
Expand Down Expand Up @@ -1435,6 +1435,36 @@ describe('test harness', () => {
});
});

it('handles invalid variables', async () => {
const app = server();

post(
app,
urlString(),
graphqlHTTP({
schema: TestSchema,
}),
);

const response = await request(app)
.post(urlString())
.send({
query: 'query helloWho($who: String){ test(who: $who) }',
variables: { who: ['Dolly', 'Jonty'] },
});

expect(response.status).to.equal(500);
expect(JSON.parse(response.text)).to.deep.equal({
errors: [
{
locations: [{ column: 16, line: 1 }],
message:
'Variable "$who" got invalid value ["Dolly","Jonty"]; Expected type String; String cannot represent an array value: [Dolly,Jonty]',
},
],
});
});

it('handles unsupported HTTP methods', async () => {
// This test doesn't apply to restify because you need to define methods
// manually for each endpoint.
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function graphqlHTTP(options: Options): Middleware {
// Note: Information about the error itself will still be contained in
// the resulting JSON payload.
// http://facebook.github.io/graphql/#sec-Data
if (result && result.data === null) {
if (response.statusCode === 200 && result && !result.data) {
response.statusCode = 500;
}
// Format any encountered errors.
Expand Down