Server Side Subscriptions for event driven Domain logic with Prisma

prisma

#1

hey, i wanted to make use of server side subscriptions in prisma, to realize some event driven chain like pictured in the docs (order send, order processed, order shipped, etc) But i just do not get the example in the docs https://www.prismagraphql.com/docs/reference/server_side-subscriptions/overview-to1ahf0ob6
I mean, just adding the subscription point and schema? Don´t i need some kind of js to do something? I also do not get how those two files connect to each other or in wich file I acutally place theexamples. On the Graphcool cloud you get a query and a js file, but i do not get how I am supposed to do that in prisma… The sample project with subscriptions also did not work yet :enttäuscht:

Can anybody shed some light on this? I just do not get it :frowning: Or is this not possible with Prisma and I have to use Graphcol-Framework? Do those two work together or is this a different context? Tbh. I don´t get the difference.


#2

These are quite a lot of questions, let me try to answer all of them :slightly_smiling_face:

First of all, there seems to be some general confusion between server-side subscriptions, and client-side subscriptions.

Server-side subscriptions are webhooks that are triggered for a certain mutation. You can create such a server-side subscription by adding the necessary information in the prisma.yml file, just like in the example you linked to. Here, you can add a webhook URL that will be called with a HTTP POST request, when the subscription is triggered. It’s up to you which language to use when implementing that endpoint, and whether that endpoint is a serverless function or an actual server.

Client-side subscriptions in Prisma are using the websocket protocol and therefore require a long-running connection between your client and your server.

This would be the code being triggered at the webhook URL - again, it’s up to you how to implement this. Using AWS Lambda, for example, you can use languages such as JavaScript or Python.

The function component from the Graphcool Framework is not present in Prisma, but it should be fairly straightforward to use a tool like Serverless to setup a serverless function.

Which example are you referring to? If it’s this example, then this is about client-side subscriptions. Could you please provide a bug report here where you describe what doesn’t work in the example?

No, Graphcool Framework and Prisma are two separate tools. Please read this thread to understand the differences. Would love to discuss any further questions about this topic there as well :slightly_smiling_face:


With all this being said, there seems to be a problem with setting up server-side subscriptions currently. This is being discussed in this issue. I just added a note with a workaround there as well.

Hope all of this makes more sense to you now. Please let me know if that’s not the case :slightly_smiling_face:

Best
– Nilan