hayes / pothos

Pothos GraphQL is library for creating GraphQL schemas in typescript using a strongly typed code first approach
https://pothos-graphql.dev
ISC License
2.36k stars 164 forks source link

Prisma plugin should support async query parameter #971

Open knpwrs opened 1 year ago

knpwrs commented 1 year ago

Given the following code:

    playlists: t.relatedConnection('uploadLists', {
      cursor: 'createdAt_id',
      authScopes: privateAuthScopes,
      query: async (_args, context) => {
        const userId = (await context.session)?.appUserId;
        invariant(userId, 'No userId');

        return {
          where: { type: UploadListType.PLAYLIST, author: { id: userId } },
        };
      },
    }),

I get the following error:

image

It would be great if query could be async for when query parameters need to use external resources.

hayes commented 1 year ago

This might be possible at some point but adds a lot of complexity/overhead to handle properly. It's critical for performance to allow this to resolve synchronously. It's possible to write the logic that builds the queries to handle this, but doing the simple.thing of just making everything async and using awaits throughout ends up being too inefficient. Open to PRs, but I probably don't have time to look I to something like this until after 4.0 ships