nuxt-graphql-client
nuxt-graphql-client copied to clipboard
Allow to add graphql-request request/response middleware
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
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.
@Diizzayy it would be helpful, since we have to modify private field "options" in GraphQLClient