-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Cache should not add __typename to @export-ed input variables #4691
Comments
I'm having the same problem. |
@extend
'ed variables having __typename
in them
According to (updated) reproduction, the error is still there with latest apollo-client 🤔 |
@benjamn 2.6.2 - same error in reproduction, where's the problem? Should I recreate issue? |
Theirs fixes just remove it works for me. resolvers.js - remove from response export const filter = (root, variables, { cache }, { field }) => {
const data = cache.readQuery({ query: filterQuery });
if (field.directives.some(({ name }) => name.value === 'export')) {
delete data.filter.__typename;
}
return data.filter;
}; cache.js - add when writing cache const cache = new InMemoryCache({
dataIdFromObject: (object) => {
// check some unique field for filter object
if ('contractual' in object) {
object.__typename = 'filter';
}
return defaultDataIdFromObject(object);
},
}); |
Do we really have to manually delete the __typename from the response as above? This seems rather hacky. I don't quite understand how this PR resolved the issue. Here is a reproduction: The fix at
i.e. in this: filters @client @export(as: "filters") {
priceFilters {
value
} It removes the __typename from filters, but not from priceFilters. I have been getting around it by doing this filters @client @export(as: "filters") {
priceFilters @export {
value
} However this also seems like a silly hack… |
Intended outcome:
Non-scalar
@export
-ed variables should be send to the server without adding a__typename
field, because input types do not have a__typename
field.Actual outcome:
Server responds with
Field "__typename" is not defined by type LessonFilter.
because the$where
variable has an extra__typename
field added.How to reproduce the issue:
https://codesandbox.io/s/n58767y81p
The query:
currentFilter
in cache is like this:Versions
apollo-client@2.5.1 and apollo-client@2.6.0-beta.4
Workaround for me right now is to have client resolved extra field, which is
@export
-ed instead of the originalcurrentFilter
and clears the extra__typename
.The text was updated successfully, but these errors were encountered: