swr icon indicating copy to clipboard operation
swr copied to clipboard

graphql-request and @defer directive

Open avisra opened this issue 2 years ago • 1 comments

Bug report

Description / Observed Behavior

I am trying to use the graphql-request library as recommended in the documentation. If my graphql query contains the @defer directive in it, SWR does not seem to know how to map/handle the response.

Expected Behavior

I would expect to see the data rendered from the initial query, and when the deferred data comes back, for it to then update the UX.

avisra avatar Jan 28 '22 19:01 avisra

When using Prisma's graphql-request library with useSWR (following documentation) things work as expected under common scenarios. However, we would like to utilize the @defer directive within GraphQL to asynchronously return data as it is available from the GraphQL server. Using other graphql clients, this works okay. But we would really like to use SWR with graphql-request to keep the build size down (and because we love SWR and are familiar with it).

When using the @defer directive, the GraphQL server returns back a multipart/mixed stream. and I don't think SWR knows how to handle this response.

avisra avatar Feb 05 '22 16:02 avisra