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

feat: add served from response cache symbol to response cache #3164

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

n1ru4l
Copy link
Collaborator

@n1ru4l n1ru4l commented Jan 16, 2024

Add servedFromResponseCache symbol property to responses served from the response cache in order
to allow other plugins to determine, whether a response was served from the cache and apply custom
logic based on that.

This is required for solving graphql-hive/console#3807

Copy link

changeset-bot bot commented Jan 16, 2024

🦋 Changeset detected

Latest commit: ae0790a

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

This PR includes changesets to release 2 packages
Name Type
@graphql-yoga/plugin-response-cache Minor
hello-world-benchmark 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

Copy link
Contributor

github-actions bot commented Jan 16, 2024

Apollo Federation Subgraph Compatibility Results

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

Learn more:

Copy link
Contributor

github-actions bot commented Jan 16, 2024

✅ 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}

     checks.......................................: 100.00% ✓ 410316     ✗ 0     
     data_received................................: 1.7 GB  14 MB/s
     data_sent....................................: 83 MB   690 kB/s
     http_req_blocked.............................: avg=1.42µs   min=962ns    med=1.28µs   max=271.77µs p(90)=1.87µs   p(95)=2.06µs  
     http_req_connecting..........................: avg=2ns      min=0s       med=0s       max=158.77µs p(90)=0s       p(95)=0s      
     http_req_duration............................: avg=374.43µs min=212.99µs med=331.62µs max=18.21ms  p(90)=525.55µs p(95)=543.58µs
       { expected_response:true }.................: avg=374.43µs min=212.99µs med=331.62µs max=18.21ms  p(90)=525.55µs p(95)=543.58µs
     ✓ { mode:graphql-jit }.......................: avg=281.71µs min=212.99µs med=260.95µs max=18.21ms  p(90)=290µs    p(95)=301µs   
     ✓ { mode:graphql-no-parse-validate-cache }...: avg=552.18µs min=460.65µs med=525.08µs max=9.56ms   p(90)=563.56µs p(95)=602.88µs
     ✓ { mode:graphql-response-cache }............: avg=356.86µs min=282.23µs med=337.57µs max=8.71ms   p(90)=368.44µs p(95)=378.94µs
     ✓ { mode:graphql }...........................: avg=367.73µs min=284.32µs med=336.07µs max=12.91ms  p(90)=376.49µs p(95)=415.22µs
     http_req_failed..............................: 0.00%   ✓ 0          ✗ 205158
     http_req_receiving...........................: avg=32.28µs  min=16.44µs  med=32.43µs  max=822.35µs p(90)=37.93µs  p(95)=40.09µs 
     http_req_sending.............................: avg=8.21µs   min=5.99µs   med=7.33µs   max=5.52ms   p(90)=10.67µs  p(95)=11.31µs 
     http_req_tls_handshaking.....................: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting.............................: avg=333.94µs min=180.58µs med=291.68µs max=18.1ms   p(90)=485.04µs p(95)=501.17µs
     http_reqs....................................: 205158  1709.62886/s
     iteration_duration...........................: avg=580.12µs min=378.87µs med=533.46µs max=18.74ms  p(90)=733.96µs p(95)=755.92µs
     iterations...................................: 205158  1709.62886/s
     vus..........................................: 1       min=1        max=1   
     vus_max......................................: 2       min=2        max=2   

Copy link
Contributor

github-actions bot commented Jan 16, 2024

🚀 Snapshot Release (rc)

The latest changes of this PR are available as rc on npm (based on the declared changesets):

Package Version Info
@graphql-yoga/plugin-response-cache 3.3.0-rc-20240116104337-ae0790aa npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Jan 16, 2024

💻 Website Preview

The latest changes are available as preview in: https://b5a3b9eb.graphql-yoga.pages.dev

@@ -170,10 +170,14 @@ export function useResponseCache(options: UseResponseCacheParameter): Plugin {
if (enabled(request)) {
const cachedResponse = await cache.get(operationId);
if (cachedResponse) {
const responseWithSymbol = {
...cachedResponse,
[Symbol.for('servedFromResponseCache')]: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

So finaly you don't expose the entire metadata object ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it would be { hit: true } always in this scenario anyways, we can change it to an object later on if there is more information to store.

@n1ru4l n1ru4l merged commit 353c0fe into main Jan 16, 2024
27 of 28 checks passed
@n1ru4l n1ru4l deleted the feat-response-cache-symbol branch January 16, 2024 12:18
This was referenced Jan 16, 2024
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