-
Notifications
You must be signed in to change notification settings - Fork 730
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
Schemas with customized root operation type lead to execution errors due to incorrectly generated selection sets #2955
Comments
Hahaha, I'm shocked it's finally happened!!! Using a typename other than We've had so many other things to address and have just continued to put this off because literally no one has ever actually done this and encountered the error. So thank you for finally getting us to have to fix this one. I'll get to it for the next release. :) |
Haha I didn't realize it had a been long standing limitation. I've been using the same schema for years and it wasn't until the generated type name fields were added to the selection sets did that non standard naming come to bite haha. I'm using the elixir graphql library Absinthe on my backend and it, by default, names the query, mutation, and subscription types like I showed in the example. It's pretty easy to change that on the backend side of things, but I agree with you: I can't believe no one else has brought this up haha. Thanks in advance for addressing it in the next release! |
I started seeing this when I tried updating to 1.1 last week and I thought I was crazy and I did something wrong that caused missing value errors on |
This is holding up our upgrade to 1.x as well. One of the generated schemas we use: {
"data": {
"__schema": {
"queryType": {
"name": "query"
},
"mutationType": {
"name": "mutation"
},
"types": [
{
"kind": "OBJECT",
"name": "mutation",
"fields": [
...
]
},
...
]
}
}
} |
Thanks for all the feedback everyone. This is at the top of my list! |
The fix for this has been merged into |
Summary
(Apologies for the terrible title. I'm struggling with the terminology and producing a concise title.)
Having custom root operation type names in the schema (see below) introduces a parsing error because the operation level selection set gets generated with a non-nil
__typename
field which won't actually exist in the operation's result JSON and leads to an execution error stating that a JSON value is missing for a key.Version
1.1.2
Steps to reproduce the behavior
Here's an example schema I extracted from a test I wrote to confirm the issue:
Here's the document:
Here's the generated operation definition:
Here's the an example of the underlying parsing error message from my actual app:
The
SelectionSetTemplate
generates the__typename
field based on the return value of:And here's how verifying a root field type is done in
GraphQLCompositeType
:Given the example schema above, an operation of type
RootMutationType
is not in the list["Query", "Mutation", "Subscription"]
, which leads to the incorrectly generated__typename
field in the operation's selection set.While I was trying to trace where the issue was stemming from, I cloned the repo and added a failing test case to
Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift
Logs
Anything else?
No response
The text was updated successfully, but these errors were encountered: