-
Notifications
You must be signed in to change notification settings - Fork 125
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
Make Operation Context serializable #111
Comments
Shouldn't we be able to store the raw already-serialized request that will be sent over the wire? |
@micimize I believe we'd need the deserialized request to pass into any cache update functions. |
hmm... I would think cache updates should depend on responses. So conceptually, the cache should update in response to an optimistic response, which has optimistic data and context. Response contexts only depend on the execution result: gql/links/gql_http_link/lib/src/link.dart Lines 82 to 106 in 1884596
|
If optimistic data is provided, the update function should get called twice: first with the optimistic data, then again with the actual response (with the optimistic data and updates discarded). Of course, if no optimistic data is provided, update is only run with the actual response. Either way, if the client is offline when the mutation is made, then the app comes online, we'd have to execute the query, then run the cache update function with the result. |
Here's my comment from #110: Context may have both useful and useless information. (Or critical and nice-to-have information). I tend to think that Context should not be serializable because it kind-of contains the current state of request execution. It might be a fundamental design flaw of the Context if it's allowed to be used as a container for internal state and a container external request parameters. Maybe it should be hidden from the users of a graphql client, by providing an alternative approach which lets the client decide what's serializable and what's not. |
I'm closing this as I decided to use a separate JSON object for cache handler state rather than using Context. |
I mentioned the issue of serializing
Context
in #110, but I figured I'd open a separate issue to discuss this further.As far as I can tell, some way of serializing data passed into
Context
is necessary to enable first-class support for offline-first use cases.For example, let's say we have a mutation that requires passing the
userId
as an argument. We might create aContextEntry
such as the following:If the app is offline, a GraphQL client will need to persist this data along with the query in order to properly execute the mutation when the app comes back online.
We could potentially work around this using code generators without adjusting the existing
Context
implementation. For example, we could create an aggregate builder that searches source code for implementations ofContextEntry
, then builds a serializer that maps type names to types so thatContextEntry
s can be deserialized later. This would, of course, require eachContextEntry
to be serializable, meaning that ourUserContextEntry
above would probably need to be extended to something like this:This is starting to be a lot of boilerplate just to pass a
userId
to a mutation.@klavs @micimize I'd appreciate any insight you may have on this.
The text was updated successfully, but these errors were encountered: