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

Lifecycle hooks for websocket connections #1363

Closed
hampuskraft opened this issue Oct 13, 2020 · 1 comment
Closed

Lifecycle hooks for websocket connections #1363

hampuskraft opened this issue Oct 13, 2020 · 1 comment

Comments

@hampuskraft
Copy link

hampuskraft commented Oct 13, 2020

[Deleted for privacy reasons]

@benjie
Copy link
Member

benjie commented Oct 13, 2020

You can read about our server hooks support here:

https://www.graphile.org/postgraphile/plugins/#writing-your-own-plugins

We already expose the onOperation hook from the websocket server here:

https://github.com/graphile/postgraphile/blob/3b01d529e7fdc79e14a0bde0bf133e963ecdc088/src/postgraphile/pluginHook.ts#L57

And you can see an example of it in use here:

https://github.com/graphile/persisted-operations/blob/ee2e404ccc5e4f7f7ffe65215a97ac5e6e0fc08e/src/index.ts#L255-L263


However, for your derivative stream I think you're actually after something completely separate to that. I suspect you're just not familiar with wrapping an async iterator, which goes a little something like this:

async function* doSomethingWith(asyncIterator, context) {
  console.log("Subscription started");
  try {
    for await (const val of asyncIterator) {
      yield val
    }
  } finally {
    console.log("Subscription ended");
  }
}

(See #1218 (comment) for where doSomethingWith would be called from.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants