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

Response Interceptor? #932

Closed
gauravmakkar opened this issue Apr 2, 2018 · 5 comments
Closed

Response Interceptor? #932

gauravmakkar opened this issue Apr 2, 2018 · 5 comments

Comments

@gauravmakkar
Copy link

I need to store every API response somewhere in the logging database. How to intercept GraphQL API response?

@abernix
Copy link
Member

abernix commented Oct 18, 2018

We may still tweak parts of this API but with Apollo Server 2.2.0-alpha.0, this should be possible with:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [
    {
      requestDidStart({ request }) {
        console.log(request);
        return {
          willSendResponse({ response }) {
            console.log(response);
          },
        };
      },
    },
  ],
});

Fixed by #1795.

Let us know how it works!

@kartikjain26
Copy link

@abernix This works but strips the response headers (null in this case) which contains traceId (as sent from the server) for logging purpose.

@abernix
Copy link
Member

abernix commented Jul 17, 2019

@kartikjain26 I don't understand how this would be stripping anything. If there's a bug, please open a new issue with a runnable reproduction, per the instructions when opening the issue. Thanks!

@kartikjain26
Copy link

@abernix Thanks, but I was able to extract response headers in didReceiveResponse hook.
Also we are actively working on apollo server but I guess the documentation is not very exhaustive. Is that being currently worked upon ?

@abernix
Copy link
Member

abernix commented Jul 28, 2019

If you find the documentation is specifically lacking on a particular topic, please submit a concrete issue with what information is missing. Merely stating that the documentation is not exhaustive doesn't give us an idea where we should focus our attention. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants