[Plugin Request]: Apollo-link-state InMemoryCache read* and write* method generator #1312
-
Apollo-link-state uses client side resolvers to merge client and server responses, and the client methods readQuery, writeQuery, readFragment, and writeFragment on that object can be typed using existing gql-gen code generators. A generator that provides pre-baked methods that include those types would be useful to me as it can get a bit verbose as it stands. All examples are with no-namespaces, I'm just more familiar with that flag being on at this point, I understand that some of the use cases get less crazy if you only have to deal with the namespace object, but it is still rather verbose. As an example, given this client side schema for an apollo client
Generate client side resolvers (using typescript-common, typescript-server, and typescript-resolver), where the context type argument conforms to the Context type described like this:
Now to make the resolver
Quite a bit of duplicated code in there, adding a generator to auto provide a lot of these queries could simplify a lot of this. As an example if it code gens something like this:
the resolvers would pivot to looking like this:
I think fragments are in the same boat read and write wise, however I am not certain. Please let me know what you think, I am not sure how complicated it would be to add. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Ya, I agree. Something like this would be nice. I was needing the same except for using Currently the signature for readFragment is If we could get the Apollo team to also include FragmentType in DataProxy.Fragment, like |
Beta Was this translation helpful? Give feedback.
-
That sounds like a great idea, @DanielMillerSEL @NickClark ! |
Beta Was this translation helpful? Give feedback.
-
I am curious to try, however I need to do some legal-foo on my end first. If someone hasn't taken it up by that point I will. |
Beta Was this translation helpful? Give feedback.
-
The solution for that will be with |
Beta Was this translation helpful? Give feedback.
The solution for that will be with
TypedDocumentNode
. You can find more details here: #4580