-
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
__typename in query response #1913
Comments
@seeden it is the intended default behavior. Apollo Client uses I hope this was helpful! If not, please feel free to reopen the issue and we can keep discussing it 👍 |
Sorry for reopening, but it doesn't make sense to me. You can't mutate with |
@jbaxleyiii Agreed with @mhlavacka, this field breaks my mutations. |
I am having same problem. I am parsing long list of data and at the end i have to test for __typename and remove it manually every time. That is huge waste of time... any solutions to remove this from query ? |
You can remove it by adding const client = new ApolloClient({
networkInterface,
addTypename: false
}); |
@jbaxleyiii It would be useful to know exactly the consequences of turning this off. I can't quite piece it together from the various issues on the topic. I'm assuming turning this off will break caching in some way? |
To stop adding const client = new ApolloClient({
link: new HttpLink({uri: MY_URL}),
cache: new InMemoryCache({
addTypename: false
})
}); |
Does anybody have a script to remove __typename from nested object of Query response? |
@Access2emma you can use https://github.com/jonschlinkert/omit-deep like so: omitDeep(data, '__typename') |
I'd recommend against introducing a dependency just to do this: const omitTypename = (key, value) => (key === '__typename' ? undefined : value)
const newPayload = JSON.parse(JSON.stringify(payload), omitTypename) As far as setting the Can anyone from the apollo team chime in here, either by explaining the consequences, or linking some documentation? The readme states:
It's not really clear what the performace impact is here. |
If you're using import ApolloClient from "apollo-boost";
import { InMemoryCache } from 'apollo-cache-inmemory';
export default new ApolloClient({
uri: "http://localhost:8030/graphql",
cache: new InMemoryCache({
addTypename: false
})
}); |
If you're using Note that setting |
Just a note on using the |
Combining solutions from a few places (including @danderson00 and this readme):
|
in Angular JS export default new ApolloClient({ how to do in androdi please help... |
It would make sense to have __typename be a Symbol. That way you expose metadata without doing it inband and confusing code which just wants to deal in data. |
Setting |
Hi All In the above thread, I have posted the answer for this problem please refer to it. Please let me know if it works for you. Regards |
This comment has been minimized.
This comment has been minimized.
Then please suggest the optimal solution. |
The reason I have tried multiple times to exclude unwanted Making |
Perhaps a silly question, but if all id fields in the schema are UUIDs, does that make |
What about this case: I am trying to set initial data in local cache, sth like this:
And I've got warning that
|
The ID doesn't need to be a uuid. It just needs to be unique to the type of object. You can technically have a user object with ID 1, another with ID 2, and also have a list object with ID 1, another with ID 2. |
Yes, the ID doesn't have to be a UUID, but I think what @vlindhol is getting at is if all your ID are UUIDs then maybe we don't need |
The only problem with this approach is that it will break file uploads. Because we need the |
If only the mutations would accept the |
I've tried the Not sure what is the easiest way to remove the const responseObj = {
...omitDeep(JSON.parse(JSON.stringify(data)), '__typename'),
}; I could remove it from my response without the error. I think It's related to So IMO the only option is to clone the object and return the mutated response. Or what is the best practice here? Is it safe to disable the |
I can see an explanation for why typename exists but no solution for it breaking mutations so I don't understand why this issue has been closed. I agree with @luizcarlos1405 that having the server ignore the field would work. Could even take it further and have it ignore everything that begins with two underscores. |
For anyone using Typescript, you can define a Type for your mutation using the using |
When I use next query
I get next response:
I know and understand that apollo-client will add __typename automatically into the query. But my question is if it is all right that I will get it in my response. Currently I am using this object as input for mutation which is defined as
And therefore I need to remove __typename for each mutation.
I do not want to complain. I am just asking if it is feature or bug.
The text was updated successfully, but these errors were encountered: