Not connect related models

i tried to connect to models. They not connected

      const { itemId, ...localVar } = input 
    return db.image.update({ 
        data: { ...localVar, item: { connect: { id: itemId } }},
      where: { id },         

Could you show us your schema.prisma file?

They actually look like they’re connected correctly, but I think what you’re trying to do is resolve the field item in your GraphQL query?

You can do this in two ways:

You have to select the item fields:

Or you can add a Type resolver for item.

1 Like

Does you have this at the bottom of your file?

export const Image = {
  item: (_obj, { root }) =>
    db.image.findOne({ where: { id: } }).item(),
1 Like

Have you tried to “hardcode” the same values you send in GraphQL as input, but just in the Primsa update?

  where: { id: 1 },
  data: { {title: 'rose', url: 'https', item: { connect: { id: 1 } }},

This way you can test and confirm your Prisma statement works and if so, then look at th inputs vars from gql to see how they map.

I assume both Item with id of 1 exists as does Image with id of 1.

If Item with id 1 does not yet exist, then it will; need to be created beforehand – or the is a preview feature in Prisma to: connectOrCreate

Note: connectOrCreate is a preview feature. To enable this feature, add the following to your schema.prisma file and re-generate the client,

thank’s! I added:
and it’s work!

1 Like