I would like to understand why __typename is added to every object in a query. I would expect it to be there only in cases of unions or interfaces.
We use persisted queries to know which parts of the schema was safe to break when refactoring the schema, which includes type names.
With this query transformation, our contract is getting extending to the type names we use with no obvious benefit.
Don't really remember why we decided to include it by default, @martijnwalraven could you please elaborate on the decision we made in the past?
@sav007 How to disable the __typename to false. please help
there is no such option to remove it. As this field is critical and required for fragments and inline fragments. Plus it can be used for compound normalized cache key if id is not globally unique.
Could you please elaborate more why you need to remove it?
How is it required for fragments?
@sav007 I just want __typename to not print in my json response.
@sav007 _Here is my response :_
Data {
getChannels = [GetChannel1 {
__typename = ChannelResponse, _id = 5 a8bb0b84e4ee9a6f2f0b00c, channelName = medplus
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 a8bb0b84e4ee9a6f2f0b00e, channelName = jiva
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 a8bb0b84e4ee9a6f2f0b011, channelName = alpha
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 a8bb0b84e4ee9a6f2f0b013, channelName = myCare
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 a8bb0b84e4ee9a6f2f0b017, channelName = my trialing
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 a93aa15b13d4c002736d336, channelName = Sample test Channel
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 a97cb13fa9b91002734c09c, channelName = newchannel
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 aa6236b4a71f5002a4fa895, channelName = doctorc
}, GetChannel1 {
__typename = ChannelResponse, _id = 5 aaf53ce4897f500279e3061, channelName = cellmoney
}]
}
__typename is displaying in response it looks clumsy i just dont want __typename in my response
Earlier in Hybride web apps we used Angular we approached
apollo.create({
link: httpLink.create({URl'}),
cache: new InMemoryCache({
addTypename: false
})
});
Here we user addTypeaname to remove __typename varaible in the response
@sav007 can you please help for the above issue that i am facing.
Inline fragments and regular fragments requires this field to be able correctly parse response.
query TestQuery {
hero {
...HeroDetails
}
}
fragment HeroDetails on Character {
name
}
in this example we have fragment defined on the type Character. The only way to find out that the respose returned as Character type is to look for this special field __typename. There is no option to turn it off.
Still I don't understand the issue, you want to remove __typename field from the response just because you don't like it? And by doing this fragments and inline fragments will stop working.
The problem is that __typename is added to every object, regardless if it is a fragment or not.
closing due to no actual problem being presented.
Adding typename to every object is generating a null response in your sample app. I checked with Insomnia. Firing queries on base url : https://api.githunt.com/graphql normally work fine but in case of sample app it is giving null response for some field. Eg. for FeedQuery, it is giving all "repository" and "postedBy" as null.
{
"errors": [
{
"message": "column "__typename" does not exist",
"locations": [
{
"line": 1,
"column": 134
}
],
"path": [
"search",
"articles"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
],
"data": null,
"extensions": {
"tracing": {
"version": 1,
"startTime": "2019-05-31T09:30:52.213Z",
"endTime": "2019-05-31T09:30:52.271Z",
"duration": 57717193,
"execution": {
"resolvers": [
{
"path": [
"search"
],
"parentType": "Query",
"fieldName": "search",
"returnType": "SearchResults!",
"startOffset": 396178,
"duration": 1018880
},
{
"path": [
"search",
"articles"
],
"parentType": "SearchResults",
"fieldName": "articles",
"returnType": "[Article]!",
"startOffset": 1480480,
"duration": 55994106
}
]
}
}
}
}
why is the apollo anroid insisting on breaking every single query we created in it by adding a non required __typename
Hi @roffe!
__typename is required by the runtime to handle polymorphism and fragments. For an example:
query GetHero {
hero {
... on Human {
name
height
}
... on Droid {
name
primaryFunction
}
}
}
The generated models for Droid and Humans will be different so the concrete type of the Hero is required.
Can you elaborate on what is breaking? The __typename field is in the GraphQL spec and any compliant server should support it.
how do i turn it off, don't need either
There is still no option to remove __typename at the moment as it would require a lot of changes to support this and would complexify the code a lot. Adding such an option would be complex but, in theory, possible. We'd first need to understand what actual problem we're trying to solve.
Most helpful comment
The problem is that
__typenameis added to every object, regardless if it is a fragment or not.