maoosi/prisma-appsync

Options to omit delete, deleteMany, disconnect nested operations from ModelRelationsInput

cjjenkinson opened this issue · 1 comments

We are running Prisma AppSync on production with a large number of models and we're currently having to make use of the before hooks to prevent anyone from potentially running nested disconnect / delete operations within inputs where they should not.

Related issue / potential solution

E.g a generated update mutation for a model is fine:

mutation MyMutation {
  updateWorkspace(where: {
    id: "clczmfegk00020klbw7d4snv6"
  }, 
    data: {
      name: "Updated"
    }
  ) {
    name
    id
  }
}

The same operation can also include other nested write operations like this

mutation MyMutation {
  updateWorkspace(where: {
    id: "clczmfegk00020klbw7d4snv6"
  }, 
    data: {
      name: "Updated",
      inboxes: {
        deleteMany: {
          where: {
            id: {
              equals: "some-id"
            }
          }
        }
      }
    }
  ) {
    name
    id
  }
}

It would be useful if we could disable these paths from being generated in the ModelRelationsInput so they don't show up on the GraphQL query console as it exposes us to operations we can't keep tabs on. For instance we disable all delete resolvers by default only opening up ones carefully with permissions.

Here is how we are working around it

 'before:**': (params: BeforeHookParams) => {
    const operations = ['delete', 'deleteMany', 'disconnect'];

    const sensitiveOperations = Object.values(params?.args?.data)
      .filter((dataKey: any) => {
        const key = Object.keys(dataKey);
        const omittedKeys = key.find((k) => operations.includes(k))

        if (omittedKeys) return true
        
        return false
      })

    if (sensitiveOperations.length >= 1) {
      throw new CustomError('Operation not allowed', {
        type: "FORBIDDEN"
      })
    }

    return params;
maoosi commented

Let's track this issue in #125