Cannot query field type on type Node...

Created on 11 January 2024, 12 months ago
Updated 26 January 2024, 11 months ago

Problem/Motivation

Since D10.2 an entityQuery on a specific node entity cannot return any type content anymore

Steps to reproduce

query MyQuery {
  entityQuery(
    entityType: NODE
    filter: {conditions: {field: "type", value: "article"}}
  ) {
    items {
      ... on NodeArticle {
        id
        type {
          name
        }
      }
    }
  }
}

throws ""Cannot query field \"type\" on type \"NodeArticle\".","

🐛 Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇪🇸Spain abelass

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

Comments & Activities

  • Issue created by @abelass
  • Status changed to Closed: works as designed 11 months ago
  • 🇨🇭Switzerland ayalon

    I don't think this is related to Drupal 10.2. I tested this on a fresh Drupal 10.2 installation.

    The type and the bundle have to be explicitly enabled under "Enabled entity base fields":

    Then you can query the type like that:

    query MyQuery {
      entityQuery(
        entityType: NODE
        filter: {conditions: {field: "type", value: "page"}}
      ) {
        items {
          __typename
          ... on NodePage {
            id
            entityBundle
            entityTypeId
          }
        }
      }
    }
    

    Result:

    {
      "data": {
        "entityQuery": {
          "items": [
            {
              "__typename": "NodePage",
              "id": "1",
              "entityBundle": "page",
              "entityTypeId": "node"
            }
          ]
        }
      }
    }
    
  • 🇪🇸Spain abelass

    This is not exactly the same as

    type {
    name
    }

    returned the label of the content type and not the machine name. "Article" and not "article" / "Page" and not "page"

    Since 10.2 this is not available anymore and can't see how the fetch this info in 10.2.

  • 🇨🇭Switzerland ayalon

    You are right. I found the issue. I commited a fix into the dev version.

    These fields have new types:

    • required_label
    • machine_name

    https://www.drupal.org/project/drupal/issues/3341682 📌 New config schema data type: `required_label` Fixed

    IF you want, you can try the DEV version until I make a new release.

  • 🇪🇸Spain abelass

    Ok, thanks

  • 🇨🇭Switzerland ayalon

    A new release was created.

Production build 0.71.5 2024