Azure / Azure/data-api-builder

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

Open
#1,238 1 comment 1 reaction 0 assignees View on GitHub
cosmos graphql
Dominant language
C#
Stars
1.5k
Forks
370
Avg merge
3d 17h
Merged PRs (30d)
8

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.