-
Notifications
You must be signed in to change notification settings - Fork 646
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
3.1.1-SNAPSHOT - CacheMissException: Object 'id=xxx' has no field named '__typename'
when querying cache with addTypename.set("ifAbstract")
#3965
Comments
Thanks a lot for the reproducer 💜 . This is perfect timing as we wanted to make a release soon so we'll make sure this works before releasing. |
So what's happening here is that query Shelf($id: ID!) {
viewer {
shelf(id: $id) {
id
books {
# __typename is not added here because Book is a concrete, not-abstract type
...bookFragment
}
}
}
} query BooksByIds($ids: [ID!]!) {
viewer {
nodes(ids: $ids) {
# __typename is added here because Node is abstract
__typename
...bookFragment
}
}
} I'm not sure there's a silver bullet here. I can see three possible solutions: Solution1: "tryHard" 😅This is the solution where we really want to minimize the number of extra Solution2: "ifImplementsAbstractType" (naming TBC)This is the intermediate solution. In addition to abstract types, we also add Solution3: "always"Just add ThoughtsI'm not sure there's a silver bullet. "ifFragments" isn't great because of #3672 (comment) so this one is certainly going to go away. For your specific case, I think 2. is the way to go (and certainly a good default). We could go "tryHard" but TBH I don't think it's worth it. This not only would take some build time but would also make the transformed queries harder to understand. I'll try to get solution2 in a SNAPSHOT so you can try it. Looks like you're not too wary of extra |
Thinking a bit more about this, I think I'm overthinking this 🙃 . Even "ifImplementsAbstractType" is not really bulletproof because it's not robust to schema changes that add an interface to an existing concrete type. All in all, for
We'll keep "ifFragments" in the short term for compat reasons and remove it in the next major version. In your specific case, that certainly means using "always" which is back to what 2.x is doing but I don't see an easy way out of adding |
Thanks, Martin, for taking care of it almost immediately, and my apologies for not taking part in the discussion earlier 😬 Fortunately I don't have much to add 😛 If I also think these three choices you listed above would be enough in most cases, where one can pick performance vs idempotency to schema changes. The only idea not mentioned here (and I can think of right now) is to allow consumers to provide custom strategy when I'll go ahead and close this issue. 3.2.0 introduced the |
Thanks! And apologies for rushing a bit the release. We've been sitting on a few important changes for some time and this release was direly needed. We can always do a patch release if you find anything during testing. Regarding
Indeed, that's something I've been contemplating for a while but feeding Gradle with custom code is awkward. Basically, we'd need to have user-supplied code as an input to a Gradle task and this comes with a few challenges like how to know whether the logic has changed (for up-to-date checks) or exposing more APIs in the Gradle plugin which wouldn't get relocated. We're doing this for After playing with Gradle a bit, I think the idiomatic way to provide user-defined logic to Gradle tasks is to actually put the logic in a new Gradle task itself. In this case, the user could create a new |
Summary
I wanted to try out changes introduced as a fix for: #3774 with the new
addTypename.set("ifAbstract")
option. I was still gettingcom.apollographql.apollo3.exception.CacheMissException: Object 'id=xxx' has no field named '__typename'
so I tried to come up with a repro.schema.sdl
queries
fails to fetch
BooksByIds
from cache, after pre-fetching it withShelf
query.Am I wrong to expect
ifAbstract
to work in this case too? The test I added in the repro passes if I use theifFragment
option which I understood is considered as deprecated and is scheduled for removal.Version
3.1.1-SNAPSHOT from ~yesterday.
Description
Here's full repro: mateuszkwiecinski/apollo-playground@dda7a0d
The text was updated successfully, but these errors were encountered: