-
Notifications
You must be signed in to change notification settings - Fork 127
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
[useResponseCache] In Multipart Response queries (using defer) only the last part sent is cached #2228
Comments
Thanks for the quick response, very much appreciated. The pattern of requesting retrieving data is very simple.
In my server on the first request (not cached) I am returning a multipart response that looks like this
Then I make a second request identical to the previous one, and I get the following cached response {
"data": {
"countries": [
{ "code": "ITA", "defaultName": "Italy", "localName": "Italia" },
{ "code": "USA", "defaultName": "United States", "localName": "United States" }
]
},
"extensions": {
"responseCache": {
"hit": true
}
}
} As you can see the cached response takes into account only the For completion, this is the prettified document stored within persisted documents query AccountSettingsPage_Query {
...AccountSettingsFormOrganism_User_Query
}
fragment AccountSettingsFormOrganism_Countries_Query on Query {
countries {
code
defaultName
localName
}
}
fragment AccountSettingsFormOrganism_User_Query on Query {
user {
id
fullName
username
country {
code
localName
}
}
...AccountSettingsFormOrganism_Countries_Query @defer(label: "AccountSettingsFormOrganism_User_Query$defer$AccountSettingsFormOrganism_Countries_Defer")
} |
I think the source of the problem is here My server does never attach the I appreciate the effort in making all the requests cacheable, but maybe you can consider adding a flag to skip async/iterable responses from the cache. As a long term solution, I will probably need to invest some time to replace my Helix implementation with Yoga; but this is dangerous and requires time, carefulness and tests so is not something I can consider in urgency. |
Are you using GraphQL Helix with graphql-js's defer stream version? |
Currently, I am using Helix with I have started also looking into Yoga but having issues with |
Hi! can you share more about your setup ? Which version of helix are you using ? With which clients ? |
Rather than spending more time and diggining more into the source of the issue I decided to spend the time to migrate to Yoga. This is the function I use with Relay, in case in can be useful to others const fetchOrSubscribe = (document, variables) =>
Observable.create(sink =>
subscriptionsClient.subscribe(
{
variables,
operationName: document.name,
query: document.text
},
{
next: data =>
data?.incremental
? data?.incremental.forEach(part => sink.next(part))
: sink.next(data),
error: error => sink.error(error),
complete: () => sink.complete()
}
)
) I attach it to Relay Environment like this: const relayEnvironment = new Environment({
network: Network.create(fetchOrSubscribe, fetchOrSubscribe),
store: new Store(new RecordSource(), {})
}) Thanks for your support. I believe the issue can be closed. |
Great news! I hope the migration was not too dificult :-) If you have some insight about it, perhaps we can even add a migration guide to the documentation. Thank you for the Relay boilerplate snippet! Very useful! |
Closing this in favor of #2244 :-) Since this documentation update is actually not related that much to the initial issue. Thank you again for the report! |
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
minimal reproduction available on
Stackblitz.
@envelop/*
packages that you are using.Describe the bug
Hello folks, been some time, hope you're all well.
I reporting an issue I discovered with Envelop response cache plugin.
When I have defer queries, using multipart, it caches the last part sent over the entire query.
This is quite problematic because it will serve only that part to anyone making the same queries.
Since the response if very incomplete, it causes application errors.
Would be great to cache the combined response in these cases. Or the minimum requirement to bypass this issue is disabling cache for these specific queries.
I looked into
shouldCacheResult
but it doesn't have any useful param to disable caching for multipart or defer queries.Do you have any advice?
Environment:
@envelop/*
versions:@envelop/core
: 5.0.0@envelop/response-cache
: 6.1.2The text was updated successfully, but these errors were encountered: