Skip to content
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

Merged
merged 4 commits into from
Aug 1, 2022
Merged

Conversation

ardatan
Copy link
Collaborator

@ardatan ardatan commented Jul 29, 2022

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.

@ardatan ardatan requested a review from n1ru4l July 29, 2022 13:30
@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2022

🦋 Changeset detected

Latest commit: 454013c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 37 packages
Name Type
graphql-yoga Major
@graphql-yoga/common Patch
@graphql-yoga/node Patch
@graphql-yoga/render-graphiql Major
@graphql-yoga/plugin-apq Major
@graphql-yoga/persisted-operations Major
@graphql-yoga/plugin-response-cache Major
apollo-federation-gateway-with-yoga Patch
apollo-subgraph-with-yoga Patch
azure-function Patch
cloudflare-advanced Patch
cloudflare Patch
defer-stream-example Patch
error-masking-example Patch
express-example Patch
fastify-modules-example Patch
fastify-example Patch
file-upload-nextjs-pothos Patch
file-upload-nexus Patch
file-upload Patch
example-generic-auth Patch
graphql-config-example Patch
graphql-ws Patch
hackernews Patch
hello-world Patch
issue-template Patch
koa-example Patch
example-live-query Patch
nextjs-auth Patch
nextjs Patch
node-esm Patch
example-redis-pub-sub Patch
service-worker Patch
subscriptions-example Patch
sveltekit Patch
hello-world-benchmark Patch
graphql-lambda Patch

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

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jul 29, 2022

Related: graphql/graphql-over-http#167

@github-actions
Copy link
Contributor

github-actions bot commented Jul 29, 2022

✅ Benchmark Results

     ✓ no_errors
     ✓ expected_result

     checks.........................: 100.00% ✓ 168008      ✗ 0    
     data_received..................: 22 MB   745 kB/s
     data_sent......................: 9.7 MB  322 kB/s
     http_req_blocked...............: avg=1.42µs   min=800ns   med=1.2µs   max=2.58ms  p(90)=1.8µs   p(95)=2.2µs   
     http_req_connecting............: avg=27ns     min=0s      med=0s      max=2.34ms  p(90)=0s      p(95)=0s      
   ✓ http_req_duration..............: avg=272.21µs min=180.2µs med=243.9µs max=21.79ms p(90)=307.9µs p(95)=343.5µs 
       { expected_response:true }...: avg=272.21µs min=180.2µs med=243.9µs max=21.79ms p(90)=307.9µs p(95)=343.5µs 
     http_req_failed................: 0.00%   ✓ 0           ✗ 84004
     http_req_receiving.............: avg=21.85µs  min=11.5µs  med=19.7µs  max=10.2ms  p(90)=26.7µs  p(95)=29.2µs  
     http_req_sending...............: avg=9.09µs   min=4.3µs   med=6.8µs   max=4.05ms  p(90)=11.7µs  p(95)=13µs    
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=241.25µs min=157.7µs med=215.5µs max=21.44ms p(90)=273.2µs p(95)=307.5µs 
     http_reqs......................: 84004   2799.985219/s
     iteration_duration.............: avg=350.7µs  min=237.2µs med=320.6µs max=22.29ms p(90)=396.8µs p(95)=438.29µs
     iterations.....................: 84004   2799.985219/s
     vus............................: 1       min=1         max=1  
     vus_max........................: 1       min=1         max=1  

@ardatan
Copy link
Collaborator Author

ardatan commented Jul 29, 2022

I think I broke bunch of stuff :D I'm on that.
Ok now it works fine!

@ardatan ardatan changed the title Respect Accept headers Respect Accept headers in a more strict way Jul 29, 2022
@github-actions
Copy link
Contributor

The latest changes of this PR are not available as canary, since there are no linked changesets for this PR.

Comment on lines +1486 to +1500
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()
})
Copy link
Collaborator

@n1ru4l n1ru4l Aug 1, 2022

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.

Copy link
Collaborator Author

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

Comment on lines +1531 to +1538
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)
})
Copy link
Collaborator

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 🤔

Copy link
Collaborator

@n1ru4l n1ru4l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants