Azure / Azure/data-api-builder

Cosmos GraphQL schema should enforce the `id` field be non-null

Aperta
#1,238 1 commento 1 reazione 0 assegnatari Vedi su GitHub
cosmos graphql
Lingua principale
C#
Stelle
1.5k
Fork
370
Merge medio
3g 22h
PR unite (30g)
9

Descrizione

When creating a GraphQL schema to use with Cosmos, it is possible to define a nullable `id` field, which will then result in a runtime error trying to use the `create` mutation, since the `id` field is required for both the `id` and partition key.

Our tests are showing this as an incorrect pattern:

```graphql
type Character @model(name:"Character") {
id : ID,
name : String,
type: String,
homePlanet: Int,
primaryFunction: String,
star: Star
}

type Planet @model(name:"Planet") {
id : ID,
name : String,
character: Character,
age : Int,
dimension : String,
stars: [Star]
tags: [String!]
}

type Star @model(name:"StarAlias") {
id : ID,
name : String
}
```

There is a test that covers the error you would get _at runtime_: https://github.com/Azure/data-api-builder/blob/007d84c060d1fee62530313bd6b3db5f4106e06e/src/Service.Tests/CosmosTests/MutationTests.cs#L148-L162

Since this is a requirement, it should be made clear in the GraphQL schema that is served by DAB, to ensure that clients are aware of what the contract is with the server, rather than waiting until runtime to receive an error response.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con il test di errore in fase di esecuzione in src/Service.Tests/CosmosTests/MutationTests.cs, righe 148-162, quindi traccia il modo in cui DAB serve lo schema GraphQL per Cosmos. Il lavoro è completato quando lo schema servito contrassegna il campo id come non-null, in modo che i client vedano il contratto prima che le mutazioni create arrivino a un errore in fase di esecuzione.

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

Valutazione

Stack tecnologico
azure, graphql
Ambito
api, databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.