In an upcoming release of Prisma and Prisma Cloud we will introduce a change to simplify the nested mutation for to-one relations. This introduces a small breaking change in the API that you should be aware of if you are currently using the Prisma Cloud Development Cluster in production.
To understand the change, take a look at the following data schema and the generated API before and after the change:
type Checkin {
id: ID! @unique
time: DateTime!
location: Location
}
type Location {
id: ID! @unique
lat: Float!
lng: Float!
}
mutation before {
updateCheckin(where: { id:"cjdvp1t2bfajf0186ka1t5po4" }
data:{
time: "2018"
location: {
update: {
where:{ id: "the existing id" }
data: { lat:3, lng:4 }
}
}
}){
id
}
}
mutation after {
updateCheckin(where: { id:"cjdvp1t2bfajf0186ka1t5po4" }
data:{
time: "2018"
location: {
update: { lat:3, lng:4 }
}
}){
id
}
}
As you can see, the id for the nested update mutation is redundant because Prisma can infer it from the parent node.
Nice
Hey @sorenbs @marktani 馃憢
Just to be sure, a mutation with one-to-many will also change about the API?
For example, if the model Location contains a field checkins: [Checkin!]!, the new syntax will be available?
And about the old syntax, it will generate an error or can we continue to use both?
Thanks,
Just to be sure, a mutation with one-to-many will also change about the API?
The API will not change for to-many relations. Only for to-one relations, as described in the original post.
And about the old syntax, it will generate an error or can we continue to use both?
Once the cluster you are working with (either the development cluster, or your own cluster) is upgraded to a version that contains this change, and you try to run the "Before" mutation from the original post, you will receive an error. From then on, only the "After" mutation is supported.
Ok good, thanks for the confirmation @marktani 馃憤
@marktani
As discuss together, I consider that we can have one-to-many, but also many-to-one, depends on the direction of how you see the relation.
So if in my example, I add the field checkins: [Checkin!]! to the Location model, is the new API syntax to make a mutation for the Checkin model is still available? (even if it looks like a many-to-one relation?)
The new API applies to all to-one relations. So also the one part of a one-to-many or many-to-one relation is affected by the change described in the original post.
Will it work for upsert to-one relation too?
@Huvik , @johannpinson the change is now available on the unstable channel, you can check it out!
This change has been rolled out in 1.3.3 馃檪
Most helpful comment
This change has been rolled out in
1.3.3馃檪