Auto-generated mutation payload incorrectly set to null when mutation returns null
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
We use .AddMutationConventions(applyToAllMutations: true)
to automatically apply conventions to all our mutations. However, when null
is returned from the mutation, it seems to return null
for the entire auto-generated __payload
type.
For example:
// mutation code
public async Task<GuardianProfile> DeleteProfileAndRelationships
// generated schema
deleteProfileAndRelationships: DeleteProfileAndRelationshipsPayload!
// error when DeleteProfileAndRelationships returns null GuardianProfile
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 4,
"column": 3
}
],
"path": [
"deleteProfileAndRelationships"
],
"extensions": {
"code": "HC0018"
}
}
]
}
Expected:
Valid DeleteProfileAndRelationshipsPayload
returned with a guardianProfile: null
field
Actual: Nullability error thrown
Steps to reproduce
- Use
.AddMutationConventions(applyToAllMutations: true)
- Create a simple mutation that returns a reference type
- Observe that a non-nullable
___payload
type is auto-generated in the schema - Return null from mutation
- Observe that a nullability error is thrown
- Now, use
[UseMutationConvention(Disable = true)]
to NOT use mutation convention - Observe that a nullable return type is specified in the schema, as expected
- Return null from mutation
- Observe that it works as expected, null is returned
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.7.0
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Graphql mutation returning null, but database is updated
The problem is that you are not returning any value in resolve function, the lineitem.save(); returns the value inside the callBack.
Read more >Subscription returns null for deep elements. ( ...
Hi everyone, I'm currently using subscriptions to update the state of my "manager" in order to spread the update through useContext.
Read more >Returning null from a GraphQL mutation in type-graphql
All GraphQL types are nullable by default so you can just return a bool in the schema but return void from the implementation....
Read more >GraphQL permits null fields on mutation
The gist of my question is why do the auto-generated mutations not enforce the presence of fields marked non-null on types. The details:....
Read more >GraphQL Nullability - Episode #42
This mutation has a non-null input argument CreateUserInput! , and the createUser mutation returns non-null User! . The input type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
GuardianProfile
is a nullable type since it’s a reference type and we don’t have nullable reference types enabled (https://chillicream.com/docs/hotchocolate/v12/defining-a-schema/non-null#implicit-nullability). So without the convention, the mutation is allowed to return null.With the convention enabled, the auto-generated mutation return type
DeleteProfileAndRelationshipsPayload
is non-nullable, which makes sense. However, when the mutation returns a nullGuardianProfile
, I am expectingInstead, I think it is returning null for the entire
DeleteProfileAndRelationships**Payload**
, which causes the nullability error.Sure, working on creating one
@nancyl-ol tanks for the repro. The issue here seems to be that this mutation has now
input
. Its a bug … By trying to repro your issue I found another related bug. I will fix both with 12.16.0I will add some test cases first and you can expect a fix by the end of the week.