-
Notifications
You must be signed in to change notification settings - Fork 30
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
Full support for union/interface types #153
Comments
I'd be interested in helping with this, though I'm just now getting onboarded with the source code. Our team would benefit greatly from incorporating the improvements you've made with the apollo cache. Here's how I understand the lib + parsing queries with InlineFragment
|
Hi @anthonychung14 — welcome to the project. I've implemented 95% of the support needed for inline fragments over in #183. If you'd like to begin using it today, I'd suggest you incorporate my branch into a private fork. (The comment thread on that PR outlines the remaining work needed to get support to 100%, and it's not trivial — it involves having the entire schema available on the client to understand which fragment was matched. This remaining work is mostly in the realm of validation, so it doesn't need to be finished to begin using the branch today.) |
We've merged support for inline fragments in #183. In the process of implementing it, it became clear that the 'hard' part of this is handling multiple fragments for different types on a given object. This is a common scenario when querying a union type (because you'll likely have one fragment for potential type in the union), but it also crops up when querying object interfaces. The problem is that without the client being aware of the schema, it doesn't know which type fragments actually matched the object on the server; consequently, it doesn't know which keys to write into the cache, and which to ignore. @nevir illustrated this problem in #183 (review). Generally, this problem is benign, because it only results in extra nullified keys in the cached object. However, as illustrated in #183 (comment), it can become a little more risky when an object changes types, because you can end up with residual key/value pairs from the prior type fragments. In the end, this will require something akin to |
Update: Much of this has been implemented. See this comment for remaining work.
We don't supportBut it shouldn't be too difficult to support, I think.... on Type {
queries currently.Rough outline of the work:
When parsing queries, we need to walkInlineFragment
AST nodes. Most likely, they are added as another field node (but explicitly flagged as being a union field)When writing fields, any union field present in the payload should be written normally(except if not present,null
s shouldn't be inserted)When reading queries there should be no work required for unions with only static fieldsPotential challenges:
__typename
or schema introspection)The text was updated successfully, but these errors were encountered: