Azure / Azure/data-api-builder

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

Offen
#1,238 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
cosmos graphql
Vorherrschende Sprache
C#
Sterne
1.5k
Forks
370
Ø Merge
3 T. 22 Std.
Gemergte PRs (30 T.)
9

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem Laufzeitfehler-Test in src/Service.Tests/CosmosTests/MutationTests.cs, Zeilen 148-162, und verfolge anschließend, wie DAB das GraphQL-Schema für Cosmos bereitstellt. Als abgeschlossen gilt die Änderung, wenn das bereitgestellte Schema das id-Feld als non-null markiert, sodass Clients den Vertrag sehen, bevor create-Mutationen einen Laufzeitfehler erreichen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, graphql
Bereich
api, databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.