EntityQueryRevisionMode is not evaluated correctly

Created on 10 August 2023, over 1 year ago
Updated 25 January 2024, 11 months ago

Problem/Motivation

When querying EntityRevisions of a Node, the response is always the latest published revision no matter what EntityQueryRevisionMode was used.

Steps to reproduce

Create a node in Drupal and publish it. Then edit some fields of the node and save it, but do not publish it (Draft mode).

Now it's time to send some GraphQL queries.

I used the following query:

query getNodes{
    entityQuery(
        entityType: NODE,
        revisions: DEFAULT
        sort: { direction: DESC, field: "created" }
    ) {
        items {
            id
            ...on NodeNews {
                vid
                moderationState
            }
        }
    }
}

With the same query, we can now test different revisionStates by simply changing the revisions field.
With the states DEFAULT and LATEST, the response is always:

{
  "data": {
    "entityQuery": {
      "items": [
        {
          "id": "171",
          "vid": 2228,
          "moderationState": "published"
        }
      ]
    }
  }
}

But the values should be different:
When using DEFAULT I would expect the response from above, but with LATEST I would expect to get the latest unpublished version of the node, something like:

{
  "data": {
    "entityQuery": {
      "items": [
        {
          "id": "171",
          "vid": 3001,
          "moderationState": "draft
        }
      ]
    }
  }
}

When using the RevisionMode ALL, I get a response where the number of nodes equals the number of all existing revisions, but the value (and the vid) is the same for each node:

{
  "data": {
    "entityQuery": {
      "items": [
        {
          "id": "171",
          "vid": 2228,
          "moderationState": "published
        },
        {
          "id": "171",
          "vid": 2228,
          "moderationState": "published
        }
      ]
    }
  }
}

Proposed resolution

We identified the bug which can be found in src/Wrappers/QueryConnection.php

When resolving each individual entity, the value of the query result list was used. These values reference the Entity-ID rather than the "vid" of the entity. By using the Entity-ID, the buffer always resolves to the default revision.

Instead of using the values of the query result, we could use their keys which are referencing the "vid"s.
For this change to be applied, we also had to change the buffer since the "graphql.buffer.entity" expects an Entity-ID, while the "graphql.buffer.entity_revision" buffer can work with "vid"s.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

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

Comments & Activities

Production build 0.71.5 2024