dotansimha / graphql-yoga

🧘 Rewrite of a fully-featured GraphQL Server with focus on easy setup, performance & great developer experience. The core of Yoga implements WHATWG Fetch API and can run/deploy on any JS environment.
https://the-guild.dev/graphql/yoga-server
MIT License
8.25k stars 574 forks source link

fix: context properties are shared between batched requests #3491

Closed n1ru4l closed 3 days ago

n1ru4l commented 4 days ago

While investigating an issue for usage reporting for batched requests, I realized that context assignments for one batch execution to one context are also shared/assigned to the other batch contexts.

Object.create creates a new object using the existing object as the prototype so the assignments seem to be inherited. 🫤

This bug was introduced in https://github.com/dotansimha/graphql-yoga/pull/3270

This bug originates from @whatwg-node/server See https://github.com/ardatan/whatwg-node/pull/1797 and https://github.com/ardatan/whatwg-node/pull/1796).

changeset-bot[bot] commented 4 days ago

🦋 Changeset detected

Latest commit: bcee0597b33d05d7d46f9c2ab3d6b411e191a1bd

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

This PR includes changesets to release 24 packages | Name | Type | | ------------------------------------------ | ----- | | graphql-yoga | Patch | | @graphql-yoga/nestjs | Patch | | @graphql-yoga/render-graphiql | Patch | | @graphql-yoga/plugin-apollo-inline-trace | Patch | | @graphql-yoga/apollo-managed-federation | Patch | | @graphql-yoga/plugin-apollo-usage-report | Patch | | @graphql-yoga/plugin-apq | Patch | | @graphql-yoga/plugin-csrf-prevention | Patch | | @graphql-yoga/plugin-defer-stream | Patch | | @graphql-yoga/plugin-disable-introspection | Patch | | @graphql-yoga/plugin-graphql-sse | Patch | | @graphql-yoga/plugin-jwt | Patch | | @graphql-yoga/plugin-persisted-operations | Patch | | @graphql-yoga/plugin-prometheus | Patch | | @graphql-yoga/plugin-response-cache | Patch | | @graphql-yoga/plugin-sofa | Patch | | apollo-federation-gateway-with-yoga | Patch | | apollo-subgraph-with-yoga | Patch | | graphql-lambda | Patch | | cloudflare-advanced | Patch | | cloudflare | Patch | | nextjs-app | Patch | | hello-world-benchmark | Patch | | @graphql-yoga/nestjs-federation | 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

github-actions[bot] commented 4 days ago
### 💻 Website Preview The latest changes are available as preview in: [https://d89a74f0.graphql-yoga.pages.dev](https://d89a74f0.graphql-yoga.pages.dev)
github-actions[bot] commented 4 days ago

✅ Benchmark Results

     ✓ no_errors{mode:graphql}
     ✓ expected_result{mode:graphql}
     ✓ no_errors{mode:graphql-jit}
     ✓ expected_result{mode:graphql-jit}
     ✓ no_errors{mode:graphql-response-cache}
     ✓ expected_result{mode:graphql-response-cache}
     ✓ no_errors{mode:graphql-no-parse-validate-cache}
     ✓ expected_result{mode:graphql-no-parse-validate-cache}
     ✓ no_errors{mode:uws}
     ✓ expected_result{mode:uws}

     checks.......................................: 100.00% ✓ 519280      ✗ 0     
     data_received................................: 2.1 GB  14 MB/s
     data_sent....................................: 104 MB  696 kB/s
     http_req_blocked.............................: avg=1.49µs   min=1µs      med=1.31µs   max=281.97µs p(90)=1.99µs   p(95)=2.19µs  
     http_req_connecting..........................: avg=2ns      min=0s       med=0s       max=139.94µs p(90)=0s       p(95)=0s      
     http_req_duration............................: avg=364.02µs min=222.17µs med=327.18µs max=19.51ms  p(90)=462.36µs p(95)=483.03µs
       { expected_response:true }.................: avg=364.02µs min=222.17µs med=327.18µs max=19.51ms  p(90)=462.36µs p(95)=483.03µs
     ✓ { mode:graphql-jit }.......................: avg=294.68µs min=222.17µs med=270.83µs max=19.51ms  p(90)=303.77µs p(95)=322.52µs
     ✓ { mode:graphql-no-parse-validate-cache }...: avg=493.06µs min=402.89µs med=463.34µs max=9.65ms   p(90)=501.51µs p(95)=532.95µs
     ✓ { mode:graphql-response-cache }............: avg=344.33µs min=272.06µs med=324.7µs  max=7.75ms   p(90)=354.8µs  p(95)=366.46µs
     ✓ { mode:graphql }...........................: avg=372.71µs min=274.86µs med=336µs    max=13.68ms  p(90)=394.59µs p(95)=448.98µs
     ✓ { mode:uws }...............................: avg=350.15µs min=275.26µs med=327.55µs max=9.51ms   p(90)=360.61µs p(95)=378.68µs
     http_req_failed..............................: 0.00%   ✓ 0           ✗ 259640
     http_req_receiving...........................: avg=33.7µs   min=15.97µs  med=33.57µs  max=2.28ms   p(90)=39.39µs  p(95)=41.57µs 
     http_req_sending.............................: avg=8.58µs   min=6.06µs   med=7.53µs   max=3.28ms   p(90)=11.06µs  p(95)=12.12µs 
     http_req_tls_handshaking.....................: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting.............................: avg=321.73µs min=186.33µs med=285.85µs max=19.37ms  p(90)=419.51µs p(95)=437.67µs
     http_reqs....................................: 259640  1730.911286/s
     iteration_duration...........................: avg=572.94µs min=389.29µs med=533.57µs max=20.1ms   p(90)=674.32µs p(95)=699.67µs
     iterations...................................: 259640  1730.911286/s
     vus..........................................: 1       min=1         max=1   
     vus_max......................................: 2       min=2         max=2   
github-actions[bot] commented 4 days ago

Apollo Federation Subgraph Compatibility Results

Federation 1 Support Federation 2 Support
_service🟢
@key (single)🟢
@key (multi)🟢
@key (composite)🟢
repeatable @key🟢
@requires🟢
@provides🟢
federated tracing🟢
@link🟢
@shareable🟢
@tag🟢
@override🟢
@inaccessible🟢
@composeDirective🟢
@interfaceObject🟢

Learn more: