Azure / Azure/data-api-builder
GraphQL relationships can cause a stack overflow exception
- Lenguaje dominante
- C#
- Estrellas
- 1.5k
- Forks
- 370
- Merge medio
- 3 d 22 h
- PR fusionados (30 d)
- 9
Descripción
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...
Guía de contribución
Línea de trabajo
Reproduce el desbordamiento de pila con el esquema GraphQL del issue y, a continuación, inspecciona GraphQLUtils.IsBuiltInType y Mutations.FieldAllowedOnCreateInput, identificados en el stack trace. Rastrea cómo se recorre repetidamente la relación Player–Game y establece un recorrido acotado; se considera terminado cuando este esquema se construye sin un desbordamiento de pila y el comportamiento existente de las mutaciones permanece intacto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp, graphql
- Área
- api, backend-api-design
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100