Entity references to archived nodes causing errors and null responses

Created on 12 December 2023, about 1 year ago
Updated 19 January 2024, 11 months ago

Problem/Motivation

We're currently in the process of migrating our decoupled site from using JSON API-based API to using GraphQL. In Drupal, we have a paragraph called 'List' that allows a user to add various sub paragraph types to create a list on the front end of our site.

One of the paragraph types that can be added in this manner is called "Linked content" - it contains a variety of optional text fields and an entity reference field that allows the editor to select a node elsewhere on the site to link to.

Historically, the entity reference field (called linked_content) has been a required field to ensure when content creators add the paragraph to a page, they must link out out to content before saving.

The issue we've run in to is that occasionally content is archived and unpublished - but an editor may not remove all entity references across the site using this field to the archived content.

With our JSON API based api, this hasn't been a problem - any remaining Linked content paragraphs in the list are returned fine - the paragraph containing the archived entity reference is simply excluded.

However when pulling data via GraphQL, no data is returned for any of the linked paragraphs - because an anonymous user doesn't have permission to access the archived entity reference we'd expect that data not to be returned - but it also stops graphql returning the content the user DOES have access to.

We can resolve the issue by making the entity reference not required - but we'd prefer to not do this so editors can't add incomplete paragraphs.

Is there a recommended solution here?

Example responses - here the `list` paragraph contains three sub paragraphs, all `Linked content`. Each of these contains an entity reference. Two are linked to published content, one to archived content

What's returned when the `linked_content` entity reference is required:

{
  "id": "a7e5938f-141c-43a8-87f6-dc7023317a73",
  "sectionTitle": "Related content",
  "contentSlicesRef": [
    {
      "id": "5cb0dcb9-93d6-4072-b6af-157b2fa91d3d",
      "listingLayout": "horizontal_card",
      "contentSlicesRef": null
    }
  ]
}

What's returned when the `linked_content` entity reference is NOT required:

{
  "id": "5cb0dcb9-93d6-4072-b6af-157b2fa91d3d",
  "listingLayout": "horizontal_card",
  "contentSlicesRef": [
    {
      "id": "ad198e44-6c63-4439-a67f-9df8fff7463a",
      "linkedContent": {
        "articleContentType": "news",
        "id": "ca13b2b5-bdbc-491e-9308-0eefef2116ee",
        "path": "/news/mental-health-datasets-for-anxiety-depression-research",
        "title": "What would the perfect mental health dataset look like?"
        }
      }
    },
    {
      "id": "a2d987bd-4f48-4c26-a214-f5d7a7dc2ba7",
      "linkedContent": {
        "articleContentType": "news",
        "id": "951adcd3-6f98-4a60-845a-7ea7ec517a27",
        "path": "/news/world-where-no-one-held-back-our-vision-mental-health",
        "title": "A world where no one is held back: our vision for Mental Health"
      }
    },
    {
      "id": "991e8af3-35ac-48f4-b085-9067178cb6b3",
      "linkedContent": null
    }
  ]
}
💬 Support request
Status

Fixed

Version

2.1

Component

Code

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024