laravel-graphql
laravel-graphql copied to clipboard
Relay Mutation error: Cannot return null for non-nullable field PayloadClassName.clientMutationId
I have installed the following versions:
- folklore/graphql dev-feature/relay c80b697
- webonyx/graphql-php v0.10.2
I followed the instructions to create a Relay mutation. My mutation returns with the error Cannot return null for non-nullable field PayloadClassName.clientMutationId.
My frontend does provide a valid clientMutationId to the API.
I did some debugging and found the following: The node data and the clientMutationId are stored for response in the MutationResponse Class but the clientMutationId can never be retrieved. The HasClientMutationIdField Trait has no resolve method. The Executor of the webonyx library will default to the defaultFieldResolver method.
As the MutationResponse Class implements the \ArrayAccess interface it tries to retrieve the clientMutationId by $source['clientMutationId']; This will always return null.
Possible solutions: The first solution is to add a resolve function to HasClientMutationIdField Trait:
'resolve' => function ($root) {
return $root->getClientMutationId();
}
The second solution is to add the clientMutationId to the attributes property in the MutationResponse class so it can be accessed as an array value.
A third option is I did not understand your documentation and there is an other solution to the problem. Did I install the wrong version?