k0ff33
11/28/2018, 2:50 PMtype Product { name: String!, category: [ProductCategory!]! }
and type ProductCategory { name: String! @unique }
I’d like to do mutation { createProduct( data: { name: "New product", category: { createOrConnect: { name: "Category A" } } }) }
and make sure the same mutation works when creating “New Product 2” without checking if “Category A” exists. I’ve tried defining both create and connect but that doesn’t work. Thanks!nikolasburk
upsert
operation though which does the same thing without a relation. Note that the code snippet you showed also can not work:
mutation {
createProduct(
data: {
name: "New product"
category: { createOrConnect: { name: "Category A" } }
}
)
}
In order to connect
, you'd need to provide a unique
property as well (e.g. id
).nikolasburk
k0ff33
11/28/2018, 2:55 PMProductCategory
type name
is unique so this would theoretically work.k0ff33
11/28/2018, 2:56 PMupsert
but as you mentioned it doesn’t create the relation. I’ll open a feature request on Github 🙂.Craig
11/28/2018, 3:07 PMk0ff33
11/28/2018, 3:07 PMk0ff33
11/28/2018, 3:14 PMmavilein commented 27 days ago
We implemented this a few weeks ago. Closing therefore.So is that feature in the API @nikolasburk or it’s a different one? I don’t see
upsert
in the mutation arguments like described in the docs: https://www.prisma.io/docs/prisma-graphql-api/reference/mutations-qwe2/#nested-mutations