maoosi / prisma-appsync

⚡ Turns your ◭ Prisma Schema into a fully-featured GraphQL API, tailored for AWS AppSync.

Home Page:https://prisma-appsync.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improv: Refactor `getShieldAuthorization` function to run check in parallel

maoosi opened this issue · comments

Problem

Using async shield rules is slow (rule checks are done sequentially):

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms))
}

return await prismaAppSync.resolve({
  event,
  shield: () => {
    return {
      'listPosts{,/**}': {
        rule: async () => {
          await sleep(1000) // this will take 1 sec x number of fields
          return true
        },
      },
    }
  },
})

Solution

Refactor the getShieldAuthorization function to run check in parallel for all fields.