-
Notifications
You must be signed in to change notification settings - Fork 574
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
Respect Accept headers in a more strict way #1516
Conversation
🦋 Changeset detectedLatest commit: 454013c The changes in this PR will be included in the next version bump. This PR includes changesets to release 37 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Related: graphql/graphql-over-http#167 |
✅ Benchmark Results
|
|
The latest changes of this PR are not available as canary, since there are no linked |
e3a09cb
to
454013c
Compare
describe('Respect Accept headers', () => { | ||
const yoga = createYoga({ | ||
schema, | ||
}) | ||
const server = createServer(yoga) | ||
let port: number | ||
let url: string | ||
beforeAll((done) => { | ||
port = Math.floor(Math.random() * 100) + 4000 | ||
url = `http://localhost:${port}/graphql` | ||
server.listen(port, done) | ||
}) | ||
afterAll(() => { | ||
server.close() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these tests do not necessarily require running a Node HTTP server, but we can change it later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is safer to test stream requests and responses via the really HTTP
it('should not allow to return if the result is an async iterable and accept is just json', async () => { | ||
const response = await fetch(`${url}?query=subscription{counter}`, { | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
}) | ||
expect(response.status).toEqual(406) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmmm, here it could actually be debatable whether it is okay for the client to only wait for the first event and then ditch the subscription 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved 🥳
Related ##1503 (comment)
Closes #1504
Currently Yoga processes only async iterable results according to the accept header, but instead we should respect the header even for regular results. So async iterable check should be done only for json responses.