-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL Default Response Override Test Example #11
Comments
Hey, @orthimnas! Thanks for asking for this. I'll include a runtime request handler (override) usage scenario in the unit tests as you've suggested. |
Appreciate you offering to adding that test - I wasn't able to get it working on a local project and hoped that an example would make it clear what I was missing. |
In the meantime, is it possible to override the GraphQL default response? |
Hey, @danielbayerlein. It's possible to override GraphQL handlers the same way you override the REST ones. const server = setupServer(
graphql.query('GetUser', (req, res, ctx) => {
return res(ctx.data({ user: { firstName: 'John' } }))
})
)
afterEach(() => {
// Don't forget to remove all the handlers added in each individual
// test via `.use`.
server.resetHandlers()
})
test('renders a user', () => {
server.use(
// In this particular test the `GetUser` query
// will resolve to a different user object.
graphql.query('GetUser', (req, res, ctx) => {
return res(ctx.data({ user: { firstName: 'Dean' } }))
})
)
}) |
I'd like to see an example test that resets the handlers between tests and configures a unique response per test.
My understanding is that I should be able to add an "override" handler in individual tests that tweak a default configuration.
Here is some pseudo-code that represents what I think is needed for setup / use.
setupTests.js
Test:
The text was updated successfully, but these errors were encountered: