Issue Description: What’s happening?
I want each record in the data I return from the GraphQL API to include its own type. Usually GraphQL APIs expose the field name __typename
that has what I need.
When I try to do this in the API explorer, this doesn’t work. I can see that __typename
is clearly included in the schema, because I don’t get an error when I query it and the playground gives me details about it.
Reproduce the Issue: What steps can someone take to replicate the problem?
- Go to API explorer
- Query any data type and return the field
__typename
- Observe no error message, but also no
__typename
in the return fields
Example:
{
usersList {
items {
__typename
}
}
}
Expected Behavior: What did you expect to happen?
-
__typename
should be returned (preferred), OR - Error should be thrown, as invalid field name is used in the query, and API explorer should not expose
__typename
.
Expected response:
{
"data": {
"usersList": {
"items": [
{
"__typename": "User"
}
]
}
}
}
Actual Behavior: What actually happened?
Actual response:
{
"data": {
"usersList": {
"items": [
{}
]
}
}
}
More details or screenshot
This is important because having the type means not having to maintain field mappings on the client side. There is no particular reason why blogPosts.authors
should contain Users
, but if each record under .authors
has its type included, I can have lighter-weight, more generic client-side code where I don’t have to explicitly maintain that level of schema configuration. There’s a package I use to treat the response data that needs the types.
Other GraphQL APIs do return __typename
. GraphCMS recommends using it in their documentation: Programmatically create forms & submissions with NextJS & GraphQL | GraphCMS
If there’s another field I could use for this, that would be fine. I couldn’t find another way to do this though, and as I said __typename
clearly is part of the schema.
(I did not try to get this via the SDK, but I assume the situation is the same there.)