Azure / Azure/data-api-builder

GraphQL relationships can cause a stack overflow exception

Aperta
#746 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug cosmos engine graphql
Lingua principale
C#
Stelle
1.5k
Fork
370
Merge medio
3g 17h
PR unite (30g)
8

Descrizione

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...

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riproduci lo stack overflow con lo schema GraphQL riportato nell’issue, quindi esamina GraphQLUtils.IsBuiltInType e Mutations.FieldAllowedOnCreateInput, identificati nello stack trace. Traccia il modo in cui la relazione Player–Game viene attraversata ripetutamente e stabilisci un attraversamento limitato; il lavoro è completato quando questo schema viene costruito senza stack overflow e il comportamento esistente delle mutation rimane intatto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, graphql
Ambito
api, backend-api-design
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.