Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Allow to know when a query has finished being processed #52

Closed
guigrpa opened this issue Mar 8, 2016 · 4 comments
Closed

Allow to know when a query has finished being processed #52

guigrpa opened this issue Mar 8, 2016 · 4 comments

Comments

@guigrpa
Copy link

guigrpa commented Mar 8, 2016

I've seen #36 but my need is far more simple. I'd love to have a way to know when a GraphQL query has finished being processed, so that my custom-built logging library can "close the story" of the request (I'm using hierarchical stories). I'm not interested in the result of the request, not even if it was successful or threw an error, just in the fact that it ended.

I see two ways to accomplish this:

  1. The middleware returns its main promise:

      expressGraphql = require 'express-graphql'
      graphqlMiddleware = expressGraphql (req) ->
        schema: gqlServer.getSchema()
        rootValue: {story: req.logStory}
    
      expressApp.use '/api/graphql', (req, res) ->
        graphqlMiddleware req, res
        .finally -> req.logStory.close()
  2. The middleware accepts a callback:

      expressApp.use '/api/graphql', expressGraphql (req) ->
        schema: gqlServer.getSchema()
        rootValue: {story: req.logStory}
        done: -> req.logStory.close()

I believe the second alternative is better, since it is simpler and doesn't involve leaking the middleware's implementation details (the fact that it uses promises).

I can propose a PR if you find this idea useful.

@leebyron
Copy link
Contributor

I like the idea of a logger, but I believe this is the wrong layer of abstraction to add such a thing. Instead this should be a feature of graphql-js - there's a task tracking this today at graphql/graphql-js#284

@guigrpa
Copy link
Author

guigrpa commented Mar 11, 2016

Agreed, thanks for your reply

@guigrpa
Copy link
Author

guigrpa commented Mar 15, 2016

@leebyron In case you might be interested, here's the logger lib (and Chrome extension) I've built and want to integrate with a GraphQL/Relay application in production: http://guigrpa.github.io/storyboard/

Storyboard

@leebyron
Copy link
Contributor

leebyron commented Apr 7, 2016

Very cool!

Closing this in favor of graphql/graphql-js#284

@leebyron leebyron closed this as completed Apr 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants