wpengine / atlas-content-modeler

Content modeling plugin for WordPress
https://developers.wpengine.com/docs/atlas-content-modeler
GNU General Public License v2.0
165 stars 13 forks source link

Cannot return null for non-nullable field #663

Closed ttstauss closed 1 year ago

ttstauss commented 1 year ago

We have a Modal that contains two optional relationship fields (technically a third, but that one doesn't seem to be causing an issue like the others). When we start generating the content, we get the following GraphQL error: Cannot return null for non-nullable field.

Here are how the fields are set up:

Primary Department Staff Department
primary-department staff-department

Here is how ACM added the fields in the database:

i:1654044163004;a:14:{
  s:12:"show_in_rest";b:1;
  s:15:"show_in_graphql";b:1;
  s:4:"type";s:12:"relationship";
  s:2:"id";s:13:"1654044163004";
  s:8:"position";s:6:"145000";
  s:4:"name";s:18:"Primary Department";
  s:4:"slug";s:17:"primaryDepartment";
  s:9:"reference";s:10:"department";
  s:11:"cardinality";s:11:"many-to-one";
  s:13:"enableReverse";b:0;
  s:11:"reverseName";s:6:"People";
  s:11:"reverseSlug";s:6:"people";
  s:8:"required";b:0;
  s:11:"description";s:0:"";
}
  i:1663010776274;a:18:{
  s:12:"show_in_rest";b:1;
  s:15:"show_in_graphql";b:1;
  s:4:"type";s:12:"relationship";
  s:2:"id";s:13:"1663010776274";
  s:8:"position";s:6:"156250";
  s:4:"name";s:16:"Staff Department";
  s:4:"slug";s:15:"staffDepartment";
  s:8:"required";b:0;
  s:11:"description";s:0:"";
  s:8:"minChars";s:0:"";
  s:8:"maxChars";s:0:"";
  s:13:"minRepeatable";s:0:"";
  s:13:"maxRepeatable";s:0:"";
  s:9:"reference";s:9:"staffdept";
  s:11:"cardinality";s:11:"many-to-one";
  s:13:"enableReverse";b:0;
  s:11:"reverseName";s:7:"Faculty";
  s:11:"reverseSlug";s:7:"faculty";
}

When we run the following GraphQL query, we get the error (it's blowing up our GQTy based frontend):

query faculty {
  faculty(first: 100) {
    nodes {
      uri
      primaryDepartment {
        node {
          name
        }
      }
      otherDepartments {
        nodes {
          name
        }
      }
      staffDepartment {
        node {
          name
        }
      }
      id
      prefix
      firstName
      lastName
      displayName
      facultyTitle
      story
      featuredImage {
        node {
          sourceUrl
          altText
        }
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

Here is an example response (I added a test piece of content for purposes of this example):

{
  "errors": [
    {
      "debugMessage": "Cannot return null for non-nullable field \"FacultyMemberToStaffDeptConnectionEdge.node\".",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 16,
          "column": 9
        }
      ],
      "path": [
        "faculty",
        "nodes",
        4,
        "staffDepartment",
        "node"
      ]
    }
  ],
  "data": {
    "faculty": {
      "nodes": [
         ...
        {
          "uri": "/facultymember/example-staff/",
          "primaryDepartment": {
            "node": {
              "name": "Nursing"
            }
          },
          "otherDepartments": {
            "nodes": []
          },
          "staffDepartment": null,
          "id": "[ key ]",
          "prefix": "",
          "firstName": "test",
          "lastName": "test",
          "displayName": "test",
          "facultyTitle": "test",
          "story": "",
          "featuredImage": {
            "node": {
              "sourceUrl": "https://oururl.com/wp-content/uploads/2023/07/testjpg",
              "altText": "test"
            }
          }
        },
        ...
      ],
      "pageInfo": {
        "hasNextPage": true,
        "endCursor": "[ cursor ]"
      }
    }
  },
  "extensions": {
    "debug": [],
    "queryAnalyzer": {
      "keys": "[ key ] graphql:Query operation:faculty list:facultymember [ list of keys ]",
      "keysLength": 298,
      "keysCount": 15,
      "skippedKeys": "",
      "skippedKeysSize": 0,
      "skippedKeysCount": 0,
      "skippedTypes": []
    }
  }
}

Version information

Additional context

There's an additional issue that we're seeing in these fields. If we edit the content, any of these relational fields that do not have anything selected will suddenly fill with a list of selections after tabbing/changing out of the browser tab/window and then back. Here's an illustration:

Before switching tabs After switching tabs
before after

Please note in the after image the Other Departments relational field. We did not make those selections. Those show up after changing windows or tabs.

mindctrl commented 1 year ago

@ttstauss thank you for the report. I'm adding this to our backlog to address soon. The second issue you mentioned is logged here, and I'll add it too.