Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to add graphql-request request/response middleware #322

Open
franzwilding opened this issue Apr 4, 2023 · 2 comments
Open

Allow to add graphql-request request/response middleware #322

franzwilding opened this issue Apr 4, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@franzwilding
Copy link

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 franzwilding added the enhancement New feature or request label Apr 4, 2023
@iBobik
Copy link

iBobik commented May 20, 2023

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.

@mercs600
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants