Open
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:
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:
data-api-builder/src/Service.Tests/CosmosTests/MutationTests.cs
Lines 148 to 162 in 007d84c
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.