How can I update relation data in a graphql Mutation?

I have a products.sdl.ts with the following:

type Product {
    id: String!
    title: String!
    categories: [CategoriesOnProduct]!

  type Query {
    products: [Product!]! @requireAuth
    product(id: String!): Product @requireAuth

  input CreateProductInput {
    title: String!

  input UpdateProductInput {
    title: String

  type Mutation {
    createProduct(input: CreateProductInput!): Product! @requireAuth
    updateProduct(id: String!, input: UpdateProductInput!): Product!
    deleteProduct(id: String!): Product! @requireAuth

I would like to update the categories when updating a Product, but I’m new to GraphQL and can’t seem to grasp how to do that. I tried to add it to the UpdateProductInput but it says it cannot recognize the CategoriesOnProduct.

Does anyone have an example I can refer to?

Hi @ched-dev

Have a look at Prisma’s documentation on “nested writes”.

You can connect or create related records using the syntax they describe.