Azure / Azure/data-api-builder
GraphQL relationships can cause a stack overflow exception
- Ngôn ngữ chính
- C#
- Star
- 1.5k
- Fork
- 370
- Merge trung bình
- 3 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 9
Mô tả
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...
Hướng dẫn đóng góp
Hướng nghiên cứu
Tái hiện lỗi tràn ngăn xếp với GraphQL schema trong issue, sau đó kiểm tra GraphQLUtils.IsBuiltInType và Mutations.FieldAllowedOnCreateInput, được xác định trong stack trace. Theo dõi cách mối quan hệ Player–Game được duyệt lặp đi lặp lại và thiết lập một phép duyệt có giới hạn; được xem là hoàn tất khi schema này được xây dựng mà không gây tràn ngăn xếp và hành vi mutation hiện có vẫn được giữ nguyên.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp, graphql
- Lĩnh vực
- api, backend-api-design
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100