In the first example of the Prisma API docs Mutati...
# prisma-whats-new
t
In the first example of the Prisma API docs Mutations section (https://www.prisma.io/docs/reference/prisma-api/mutations-ol0yuoz6go#overview ), if I want to createPost(), is there any way to connect it to an author if I'm not sure whether the author exists or not? It seems like I would want to use an upsert mutation, but the docs say that's only available in an update mutation. Is it possible to nest an update mutation inside of a create mutation?
n
have you tried it?
t
Once I'm nesting inside of author, I can only connect or create. Inside that I can provide the name of the author. This works fine for either connecting to an existing author or creating a new one. But if I try to use upsert anywhere inside the createPost mutation, I get syntax errors. I also don't have the option to use the updateAuthor mutation from inside the createPost mutation. So, I'm not really sure how to proceed. I could try the updatePost mutation. But that's not really quite what I want.
n
Can you share your service endpoint so I can follow along? 🙂
t
Yep. Thanks! I'm deployed locally, though. I'm totally new to this. Need to figure out how to deploy to prisma cloud first.
n
You can also share your datamodel
t
type Album { id: ID! @unique title: String! artist: Artist! art: String! year: String! rating: Int! owner: User! } type Artist { id: ID! @unique name: String! @unique works: [Album!]! } type User { id: ID! @unique username: String! @unique collection: [Album!]! }
n
so which mutation are you then trying?
t
phillip-gray-ccefc1/album-collector-api/dev
createAlbum()
If the artist already exists, I have no issues. But for this demo project, I want to create an interface where you can type in the name of an artist as part of the create album form, and if the artist doesn't exist, a new one will be created. If the artist does exist, the album will be associated with their works.
So, I'm trying to figure out how to do all that in one nested createAlbum mutation
n
Thanks a lot for bringing this up, @thephilgray. I think adding the
upsert
as a nested mutation inside
createX
is a great idea. I created this feature request, including the current workarounds that I am aware of: https://github.com/graphcool/prisma/issues/2194
t
Awesome. Thanks!
n
You should be able to apply the first one I mentioned 🙂 Let me know if you have any questions about it!
t
It worked great! I also ended up implementing the same workaround solution for another similar feature. Thanks, again!