Image field when null will fail when any nested object is in the query.

Created on 7 August 2024, 5 months ago
Updated 13 August 2024, 4 months ago

Problem/Motivation

When I run the following query:

query getEpisode {
  entityQuery(
    entityType: NODE
    limit: 1000
  ) {
    items {
      ... on NodeEpisode {
        id
        title
        fieldHeroImage {
          entity {
            urlAbsolute
          }
        }
      }
    }
  }
}

The fieldHeroImage will cause the query to error out if any of the nodes do not have fieldHeroImage populated.

{
  "errors": [
    {
      "message": "Unexpected token '<', \"<html>\r\n<h\"... is not valid JSON",
      "stack": "SyntaxError: Unexpected token '<', \"<html>\r\n<h\"... is not valid JSON"
    }
  ]
}

The fieldHeroImage is a regular image field.

If I remove the entity or any other nested object within fieldHeroImage and just use:

fieldHeroImage {
          alt
        }

The fieldHeroImage will return null for nodes missing the image.

{
  "data": {
    "entityQuery": {
      "items": [
        {
          "id": "3996",
          "fieldHeroImage": null
        },
        {
          "id": "852775",
          "fieldHeroImage": {
            "alt": "test image"
          }
        }
      ]
    }
  }
}

Steps to Reproduce

Query for an image on a node and do not populate the image.

Proposed Resolution

Can we just return null instead of erroring out?

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States andysipple

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @andysipple
  • πŸ‡§πŸ‡¬Bulgaria pfrenssen Sofia

    Thanks for the report! Do you think it is possible to discover the full error message somehow? Maybe the error can be found in the logs, or you can get more info by inspecting the GraphQL response in the Network tab of the browser?

Production build 0.71.5 2024