-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Issue with Apollo Server API (404 Error and no JSON Fetching work) #56
Comments
Two things:
Here is an example test file that you can drop into the official Next.js Apollo example repo and run with jest. The test passes: import { testApiHandler } from 'next-test-api-route-handler';
import handler, { config } from '../pages/api/graphql';
// ? This is the configuration that tells Next not to use body parser
handler.config = config;
describe('my-test', () => {
it('does what I want', async () => {
expect.hasAssertions();
await testApiHandler({
requestPatcher: (req) => (req.url = '/api/graphql'),
handler,
test: async ({ fetch }) => {
const query = `query ViewerQuery {
viewer {
id
name
status
}
}`;
const res = await fetch({
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
query
})
});
expect(await res.json()).toStrictEqual({
data: { viewer: { id: '1', name: 'John Smith', status: 'cached' } }
});
}
});
});
}); This seems like good knowledge to add to the README, thanks! And feel free to reply if you're still experiencing issues. |
Thanks a lot for your help seems like the Issue was the
Maybe this is a reason of my hacky solution to make the async buildSchema from typegraphql work in sync environment. |
Problematic behavior
I created an API that serves an Apollo-Server with an Query. When I test it with your library it returns 404 Not Found and I can't access the Response Data json without invalid json error.
Expected behavior
Reproduction steps
Runtime environment
Additional context
The text was updated successfully, but these errors were encountered: