graphql-request icon indicating copy to clipboard operation
graphql-request copied to clipboard

Support function invocations of the `gql` tag

Open acidoxee opened this issue 2 years ago • 0 comments

Hi there 👋

When trying to use codegen on our app that uses graphql-request, I've tried the latest preset described here with the gql tag exported from graphql-request. Typings are all OK, but the app crashes at runtime:

index.js:514 Uncaught TypeError: chunks.reduce is not a function
    at gql (index.js:514:1)

Sorry about the useless stacktrace, I'm pretty sure it comes from here: https://github.com/prisma-labs/graphql-request/blob/6246ffe47d3a4f849e43a36d4bbfda7518571ebe/src/index.ts#L717

I believe that's because your gql tag only works when called as a tagged template literal, but not as a function, which seems to be the only way to benefit from TS module augmentation and to avoid manually importing TypedDocumentNodes spun by codegen. Do you think supporting both invocation kinds would be possible and something you might want to add to the lib? 🙏

acidoxee avatar Sep 13 '22 08:09 acidoxee