Fork me on GitHub
#graphql
<
2022-10-28
>
isak14:10:41

Has anyone here made a way to deliver GraphQL subscriptions via webhooks (and not just websockets)? If so, how did you have people register the subscriptions?

isak14:10:48

I guess a mutation is the best you can do

hiredman16:10:47

last I checked the graphql spec was intentionally vague about how subscriptions get delivered

hiredman16:10:20

I don't even know what lacinia has to handle subscriptions by default, but once you get low level enough with lacinia you can use whatever you want for subscriptions (at work we have it setup to write to a core.async), so you could have a subscription that takes a url as an argument and then posts data to the url

gklijs20:10:29

Indeed, like hiredman said it's up to you. So you can use a subscription. https://github.com/Ancient-Dragon/dgs-sse-subscriptions-backend-example is a Netflix DGS example that might help.

isak21:10:42

Right yea, I was thinking more of the registration step, like if there is a good way to re-use the subscription type inside of a mutation or something. It looks like no.

isak21:10:22

E.g.,

mutation {
   registerWebhook(query: subscription { employeesMutated (...) } ) { id }
}

isak21:10:06

So the query would need to be passed as a string or plucked apart as separate fields

isak21:10:23

We have websocket subscriptions working now, just thinking about the best API possible for supporting webhooks since customers are asking for that now

hiredman21:10:28

not sure what you mean?

hiredman21:10:50

like a subscription can take arguments (the url to push to, whatever)

isak21:10:37

Yea, but normally that is done via a websocket individual message, which wouldn't make sense for registering a webhook, you'd probably want a simple 'POST' request

isak21:10:51

But I know what you mean - you can still do it that way. Though it doesn't provide an obvious way to unregister the webhook.

hiredman21:10:06

yeah, all our subscriptions return a subscription id, and we have a separate unsubscribe mutation

isak21:10:08

Ah I see. What transport are you guys using? Websocket?

hiredman21:10:18

the big difference between websockets and webhooks for subscriptions is going to be life times of subscriptions, for websockets the subscription is kind of dead once the connection is dead

hiredman21:10:26

http://socket.io so sort of websockets

hiredman21:10:35

websockets+long polling

isak21:10:48

Ah, cool

hiredman22:10:23

so it is reasonable to assume a subscription over websockets wouldn't outlast a server

hiredman22:10:51

but the life time on webhooks could get weird if you are driving them via lacinia

isak22:10:38

we were going to create a new service to handle those

hiredman22:10:25

yeah, I just mean you won't be able to count on any internal state in lacinia to keep driving the webhooks

gklijs06:10:55

Webhook is not the same as subscription. For webhooks I indeed would expect a mutation to manage them. The actual webhook is out of scope for GraphQL.

1
gklijs06:10:56

I mis read the initial question, sorry.