nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

Allow to add graphql-request request/response middleware

Open franzwilding opened this issue 2 years ago • 2 comments
trafficstars

Your use case

To do things like generic error handling (using the http response object) we would need to add a custom graphql-request middleware. The only way we found to add this middleware is something like:

xport default defineNuxtPlugin(nuxtApp => {
  Object.values(nuxtApp._gqlState.value).forEach(client => {
    client.instance.options.responseMiddleware = response => {
      console.log(response);
    };
  });
});

The solution you'd like

Provide a better way to define graphql-request options

Possible alternatives

Add the original response object to the onError composable, so we can access the http status code or other raw informations.

Additional information

No response

franzwilding avatar Apr 04 '23 14:04 franzwilding

Similar use-case: I use Contember CMS which in all mutations has ok and errorMessage fields. In case of ok ≠ true I would like to print errorMessage for easier development and debugging in production.

I can do it in every call, but it will be better to handle it centrally. For this I would like to attach client-wide callback which can see all responses and optionally throw exception (event if http status is 200) and debug message.

iBobik avatar May 20 '23 15:05 iBobik

@Diizzayy it would be helpful, since we have to modify private field "options" in GraphQLClient

mercs600 avatar Jul 20 '23 11:07 mercs600