Failure of read database policy for related entity in multiple create for N:1 and 1:1 relationships returns error
For N:1 and 1:1 relationships where the read policy prohibits returning the result of the insertion in the related entity, we get an exception:
In the config, the policy for read operation is defined as:
This is an existing behavior and not something that is introduced as part of multiple create. The same behavior is observed even for queries (not just mutations) when processing read policy.
DAB version: 0.12.0-rc
In the config file, Publisher entity has a role Anonymous defined with the following read policy
{
"role": "authenticated",
"actions": [
{
"action": "create"
},
{
"action": "read",
"policy": {
"database": "@item.id ne 1234"
}
}
]
}
The following graphQL query results in an exception
{
book_by_pk(id: 1) {
id
title
publisher_id
publishers {
id
name
}
}
}
Response:
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 6,
"column": 5
}
],
"path": [
"book_by_pk",
"publishers"
],
"extensions": {
"code": "HC0018"
}
}
],
"data": {
"book_by_pk": null
}
}
Mutation:
mutation{
createbook(item: {
publisher_id: 1234,
title: "Book #1"
}){
id
title
publishers{
id
name
}
}
}
Response:
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 8,
"column": 5
}
],
"path": [
"createbook",
"publishers"
],
"extensions": {
"code": "HC0018"
}
}
],
"data": {
"createbook": null
}
}
Reason for the exception:
The return type for both the operations book_by_pk and createbook : book.
Snip of the book object type:
In the schema, publishers field is created as a non-null/required field with type Publisher! ~ this makes hotchocolate throw an error when a null response is to be returned.