Azure / Azure/data-api-builder
GraphQL relationships can cause a stack overflow exception
- Langage dominant
- C#
- Étoiles
- 1.5k
- Forks
- 370
- Merge moyen
- 3 j 22 h
- PR mergées (30 j)
- 9
Description
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...
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Reproduisez le débordement de pile avec le schéma GraphQL de l’issue, puis inspectez GraphQLUtils.IsBuiltInType et Mutations.FieldAllowedOnCreateInput, identifiés dans la stack trace. Suivez la manière dont la relation Player–Game est parcourue de façon répétée et établissez un parcours borné ; le travail est considéré comme terminé lorsque ce schéma se construit sans débordement de pile et que le comportement existant des mutations reste intact.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- csharp, graphql
- Domaine
- api, backend-api-design
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100