Set field to `null` with error "Field '...' is not a connection"
leoloso opened this issue · comments
Leonardo Losoviz commented
Executing this query:
{
post(by: { id:1 }) {
categoryNames @forEach @upperCase {
id
}
}
}
produces:
{
"errors": [
{
"message": "Field 'categoryNames' is not a connection",
"locations": [
{
"line": 1,
"column": 1
}
],
"extensions": {
"type": "Post",
"field": "categoryNames"
}
}
],
"data": {
"post": {
"categoryNames": [
[],
[],
[]
]
}
}
}
Instead, it should be:
{
"errors": [
{
"message": "Field 'categoryNames' is not a connection",
"locations": [
{
"line": 1,
"column": 1
}
],
"extensions": {
"type": "Post",
"field": "categoryNames"
}
}
],
"data": {
"post": {
"categoryNames": null
}
}
}
Leonardo Losoviz commented
The issue started happening after this change in layers/API/packages/api-mirrorquery/src/DataStructureFormatters/MirrorQueryDataStructureFormatter.php
:
- // Watch out! If the property has already been loaded from a previous iteration, in some cases it can create trouble!
- // But make sure that there truly are subproperties! It could also be a schemaError.
- // Eg: ?query=posts.title.id, then no need to transform "title" from string to {"id" => ...}
- if ($this->getFeedbackMessageStore()->getSchemaErrorsForField($dbKey, $nestedField)) {
- $dbObjectRet[$nestedFieldOutputKey] = $dbObject[$uniqueNestedFieldOutputKey];
- continue;
- }