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

feat: pass res to contextResolver #79

Merged
merged 1 commit into from
Oct 1, 2020
Merged

feat: pass res to contextResolver #79

merged 1 commit into from
Oct 1, 2020

Conversation

smeijer
Copy link
Contributor

@smeijer smeijer commented Sep 30, 2020

I've exposed the response object to the context creator. This enables me to log events once the request has been completed.

I use this to log response times:

initialize({
  context: async ({ req, res }) => {
    const start = new Date().getTime();

    res.once('finish', () => {
      const duration = Date.now() - start;
      console.log(`graphql request took ${duration}ms`);
    });

    return { ... };
  }
});

This will enable us to use the response object in the function that creates the context. This can for example be used to bind (logging) events with `res.once('finish', () => {})`
@theodorDiaconu theodorDiaconu merged commit 018d98f into cult-of-coders:master Oct 1, 2020
@theodorDiaconu
Copy link
Contributor

Released 0.10.1

@smeijer smeijer deleted the patch-1 branch October 1, 2020 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants