GatoGraphQL / GatoGraphQL

Interact with all your data in WordPress using GraphQL

Home Page:https://gatographql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set field to `null` with error "Field '...' is not a connection"

leoloso opened this issue · comments

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
    }
  }
}

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;
-   }