Azure / Azure/data-api-builder

GraphQL relationships can cause a stack overflow exception

オープン
#746 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug cosmos engine graphql
主要言語
C#
スター
1.5k
フォーク
370
平均マージ
3日 22時間
マージ済み PR(30日)
9

説明

Due to the type walking within our schema builder, it's possible to create a GraphQL schema that will result in a stack overflow exception.

Here's an example of a schema that causes the problem:

```graphql
interface Node {
id: ID!
}

enum GameState {
WaitingForPlayers
Started
Completed
}

type Question implements Node @model {
id: ID!
question: String!
correctAnswer: String!
answers: [String!]!
}

type Player implements Node @model {
id: ID!
name: String!
game(gameId: ID!): Game!
games: [Game!]!
}

type Game implements Node @model {
id: ID!
state: GameState
players: [Player!]!
questions: [Question!]!
}
```

The head of the stack is here:

```
at Azure.DataApiBuilder.Service.GraphQLBuilder.GraphQLUtils.IsBuiltInType(HotChocolate.Language.ITypeNode)
at Azure.DataApiBuilder.Service.GraphQLBuilder.Mutations.CreateMutationBuilder.FieldAllowedOnCreateInput(HotChocolate.Language.FieldDefinitionNode, Azure.DataApiBuilder.Config.DatabaseType, System.Collections.Generic.IEnumerable`1)
```

But the full exception message is over 10k lines long.

I'm not sure what the state of relationships are in Cosmos, but this is realistic GraphQL schema (and the one I use for the demos I generally do).

My guess is that it doesn't like that `Player` references `Game` which references `Player` which references `Game` which...

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

issue にある GraphQL スキーマでスタックオーバーフローを再現し、スタックトレースで特定されている GraphQLUtils.IsBuiltInType と Mutations.FieldAllowedOnCreateInput を調査します。Player–Game 関係が繰り返し辿られる仕組みを追跡し、上限のある走査を確立します。このスキーマがスタックオーバーフローなしで構築でき、既存の mutation の動作が維持されれば完了です。

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

評価

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

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

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