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

Intercept every request

Open michalgebauer opened this issue 7 years ago • 3 comments

Hi there,

Is there a way how to intercept every request call? For example in case response contains errors I want to deal with them in generic way.

thanks

michalgebauer avatar Sep 19 '18 15:09 michalgebauer

Do we have any update on intercepting the request?

Davakumar avatar May 26 '20 03:05 Davakumar

Any update ?

vitorcamachoo avatar May 31 '21 18:05 vitorcamachoo

Tagging @jasonkuhrt who has merged recent commits in this project.

A more robust middleware would be extremely valuable. In addition to global error handling, this would enable generating proper telemetry data (i.e. spans qualified by GraphQL operation names).

Are there any plans to support this? If not, is there a more robust Node.js library alternative?

This issue is duplicated by:

  • https://github.com/prisma-labs/graphql-request/issues/255
  • https://github.com/prisma-labs/graphql-request/issues/297

namoscato avatar Nov 26 '21 17:11 namoscato

I'm trying this technique of "monkey patching" fetch as shown here: https://blog.logrocket.com/intercepting-javascript-fetch-api-requests-responses/

This works for all my fetch requests except those made via this graphql-request library. Is this lib not using fetch under the hood? It seems like it does (cross-fetch), but I can't figure out what's not working here. Anyone have any ideas why not?

jamiechong avatar Oct 17 '22 23:10 jamiechong

If you update to latest version the middlewares might solve your problem. Request and response.

It did for me.

mmussmann avatar Oct 18 '22 06:10 mmussmann

There is middleware now: https://github.com/jasonkuhrt/graphql-request/blob/main/examples/other-middleware.ts.

jasonkuhrt avatar Apr 16 '23 14:04 jasonkuhrt