GraphQL error with M2A blocks in draft versions: Cannot return null for non-nullable field pages_blocks.id

オープン
#27,331 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@Uday9909 がすでに取り組んでいます。

2026年10月14日 から。

  • #28446 @Uday9909 による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
graphql, postgresql, typescript
領域
api, backend, databases

調査の方向性

まず、提供された snapshot.json と文書化された M2A セットアップに対して、issue 内の draft-version query を再現します。draft のレスポンスと main item のレスポンスを比較し、null の junction row について GraphQL の結果を調査します。query が新しい変更を含むすべての draft block を、non-nullable-field error なしで返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug Engine Med Impact Med Reach Versioning
Describe the Bug

I realize I'm not using the latest version of Directus in this bug report, but I have tested the bug locally in the latest version of Directus.

When querying a versioned (version: "draft") item that contains an M2A field, GraphQL fails with:
Cannot return null for non-nullable field pages_blocks.id

This happens because one of the M2A junction rows is returned as null in the draft version, even though the block exists and is valid in the Admin UI.

The same content works correctly when querying the main (non-versioned) item.

Additionally, in the Admin UI, the affected block shows issues with display templates, which may indicate the same underlying problem.

To Reproduce

Steps to Reproduce

  1. Create a block collection "faq_blocks".
  2. Create a page collection "pages".
  3. Enable versioning on the page collection.
  4. Add an M2A field "blocks" to page collection and configure to allow faq_blocks.
  5. Create an empty page.
  6. Create a draft version of the page.
  7. In the draft, add a new faq_blocks and save the draft version.
  8. Query the page via GraphQL:
query {  
  pages_by_id(id: "<page-id>", version: "draft") {
    id
    blocks {
      id
      collection
    }
  }
}

Expected Behavior
GraphQL should return all blocks, including draft changes, without errors.

Actual Behavior

{
  "data": {
    "pages_by_id": {
      "id": "...",
      "blocks": [
        null
      ]
    }
  },
  "errors": [
    {
      "message": "Cannot return null for non-nullable field pages_blocks.id.",
      "path": ["pages_by_id", "blocks", 0, "id"]
    }
  ]
}

snapshot.json

It appears that draft versions can contain M2A relational rows where the junction id is null, but the GraphQL schema defines pages_blocks.id as non-nullable (ID!), causing the resolver to fail.

Directus Version

v11.17.1

Hosting Strategy

Self-Hosted (Docker Image)

Database

postgis/postgis:13-master

主要言語
TypeScript
スター
38.8k
フォーク
5k
平均マージ
4日 23時間
マージ済み PR(30日)
72

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

directus/directus のほかの issue

directus/directus の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。