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

Customise which mutations / queries are generated

Open mikerudge opened this issue 4 years ago • 3 comments

We are looking for a way to customise which CRUD operations are created on a per model basis. For example, We might not want to offer a delete mutations at all on a certain model.

I know I could restrict the API to only super admins or something, by using the

/// @PrismaAppSync.mutation: '@@adminsOnly'

However, we would love to be able to have the generated docs etc correctly show that the delete mutation should not be used.

mikerudge avatar Sep 24 '21 09:09 mikerudge

Giving more flexibility around the CRUD operations is something I’d be interested in supporting in the future.

The team at Prisma have been working on ways to support custom fields and models directives https://github.com/prisma/prisma/issues/3102. Ideally, I would like to wait for this to be released before offering more advanced ways to customise the output.

// something like this for example, would be great:
model Post @aws_auth(cognito_groups: ["admin"]) @crud({ delete: false }) {
    title
}

Another option (in case support for custom directives takes too long to arrive) is to update the current implementation based AST comments (as per what you’ve suggested).

I am currently focusing on a pretty big rewrite of the Client API. Once done, I’ll give this another look.

maoosi avatar Sep 24 '21 12:09 maoosi

Sounds good! I think if you are thinking of going that route it might be worth aligning it to the amplify model directive.

something like

model Post @crud(queries: { get: "post" }, mutations: null, subscriptions: null) {
  id: ID!
  title: String!
  tags: [String!]!
}

mikerudge avatar Sep 24 '21 12:09 mikerudge

Ah yes, good reference indeed!

maoosi avatar Sep 24 '21 12:09 maoosi