Making Upserts for connected fields


#1

I’m trying to perform a mutation and also update or create a relation.
Here is my graphql schema:

    type Mutation {
      createPlaylist(name: String!, tags: [String!]!): Playlist!
}

type Playlist {
  id: ID!
  name: String!
  songs: [Song!]!
  tags: [Tag!]!
}

type Tag {
  name: String!
  playlists: [Playlist!]!
}

and here is my resolver

function createPlaylist(root, { name, tags, channelsId }, context) {
  let tagUpsetArray = tags.map(value => ({
    where: {
      name: value
    },
    create: {
      name: value
    }
  }));

  return context.prisma.createPlaylist({
    name,
    tags: {
      upsert: tagUpsetArray
    }
  });
}

but I get an error:
Reason: 'tags.upsert' Field 'upsert' is not defined in the input type 'TagCreateManyWithoutPlaylistsInput'. (line 1, column 11):

Please, how can I fix this?
Thanks in anticipation.


#2

Hi @Awebi
Did you check createPlaylist method in playground (localhost:4466)? Is there any upsert mutation?


#3

@andreibacescu93 do you mean in the docs found in the playground?


#4

Hi @Awebi
Yes. There is where you should check.


#5

Hi @andreibacescu93, there is no upset mutation.
But the docs show definitions from my schema.graphql file not the prisma CRUD api


#6

Hi @Awebi
If you want to know if upsert mutation is defined or not, check your prisma CRUD api, at localhost:4466 (default endpoint for prisma service). If it is not there you have to deploy your prisma models. Looks for more details in docs.


#7

Hi @andreibacescu93
There is no upsert in the createPlaylist method. Any idea why that is?


#8

Hi @Awebi
I gave a hint in my last replay (deploy your prisma models and check prisma docs)


#9

Hi @andreibacescu93
I’ve deployed my prisma model, but it didn’t change anything.
There is also nothing about this in the docs.


#10

Hi @Awebi
This is strange. Could you show us what prisma model did you deploy?