-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle undefined reply object inside mercurius context (#30)
* fix: handle undefined reply object inside mercurius context --------- Co-authored-by: Davide Arena <d.arena@treedom.net>
- Loading branch information
1 parent
0d1d50f
commit 79950ce
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
const { buildApp, jsonLogger } = require('./_helper') | ||
|
||
test('should handle without logging when context.reply is undefined', async (t) => { | ||
t.plan(1) | ||
|
||
const app = buildApp(t) | ||
|
||
app.get('/custom-endpoint', async function () { | ||
const query = `query { | ||
four: add(x: 2, y: 2) | ||
six: add(x: 3, y: 3) | ||
echo(msg: "hello") | ||
counter | ||
}` | ||
return app.graphql(query) | ||
}) | ||
|
||
const response = await app.inject({ | ||
method: 'GET', | ||
headers: { 'content-type': 'application/json' }, | ||
url: '/custom-endpoint' | ||
}) | ||
|
||
t.deepEqual(response.json(), { | ||
data: { | ||
four: 4, | ||
six: 6, | ||
echo: 'hellohello', | ||
counter: 0 | ||
} | ||
}) | ||
}) | ||
|
||
test('should log when using graphql mercurius decorator providing reply object inside context', async (t) => { | ||
t.plan(4) | ||
|
||
const stream = jsonLogger( | ||
line => { | ||
t.is(line.req, undefined) | ||
t.is(line.reqId, 'req-1') | ||
t.deepEqual(line.graphql, { | ||
queries: ['add', 'add', 'echo', 'counter'] | ||
}) | ||
}) | ||
|
||
const app = buildApp(t, { stream }) | ||
|
||
app.get('/custom-endpoint', async function (_, reply) { | ||
const query = `query { | ||
four: add(x: 2, y: 2) | ||
six: add(x: 3, y: 3) | ||
echo(msg: "hello") | ||
counter | ||
}` | ||
return app.graphql(query, { reply }) | ||
}) | ||
|
||
const response = await app.inject({ | ||
method: 'GET', | ||
headers: { 'content-type': 'application/json' }, | ||
url: '/custom-endpoint' | ||
}) | ||
|
||
t.deepEqual(response.json(), { | ||
data: { | ||
four: 4, | ||
six: 6, | ||
echo: 'hellohello', | ||
counter: 0 | ||
} | ||
}) | ||
}) |