prisma-appsync icon indicating copy to clipboard operation
prisma-appsync copied to clipboard

Atomic Operations

Open DregondRahl opened this issue 4 years ago • 2 comments

Tested out the new release so far things are working great with the createMany options and such. I'm currently working with Atomic Operations for a Inventory project and noticed it could be implemented in this generator.

https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#atomic-number-operations

I roughly tried it and it works, but opens up an issue when doing update operations where everything need to use "set:" since GraphQL does not support Union Types.

What are your thoughts on this?

DregondRahl avatar Jun 28 '21 15:06 DregondRahl

With Atomic Operations, the GraphQL structure will probably have to differ slightly from Prisma Client API. One clean way to differentiate atomic operation from classic updates could be something like this:

mutation {
  updateManyPosts(
    operations: {
      views: { increment: 1 }
    }
  )
}

Then add a custom validation in Prisma-AppSync Client to prevent using both operations and data at once.

How did you implement it on your end?

maoosi avatar Jun 29 '21 07:06 maoosi

I implemented it similar to how prisma does it, but that does the problem I mentioned where id have to use "set:" when adding a value. Your way sounds great with a good validation, alternative would be to have a different resolver itself?

I think your idea would work best for more consistency with create and update.

DregondRahl avatar Jun 29 '21 13:06 DregondRahl