docs/1.14/04-Reference/04-Server_side-Subscriptions/01-Overview.md
A server-side subscription is equivalent in power to normal GraphQL subscriptions. That means they have the same API, e.g. allowing to provide the same filters in order to only get notified for the events you are interested in.
When a server-side subscription is set up, Prisma will monitor data changes and execute the associated query when applicable, just like normal GraphQL Subscriptions. The difference is the delivery mechanism.
Server-side subscriptions are designed to work well with modern serverless infrastructure. Currently, Prisma support delivering events via webhooks and in the future we will add support for direct AWS Lambda invocation as well as different queue implementations.
You configure a server-side subscription by adding the subscriptions property in the prisma.yml file for your service.
endpoint: ${env:PRISMA_ENDPOINT}
secret: ${env:PRISMA_SECRET}
datamodel: database/datamodel.graphql
subscriptions:
userChangedEmail:
webhook:
url: http://example.org/sendSlackMessage
headers:
Content-Type: application/json
Authorization: Bearer cha2eiheiphesash3shoofo7eceexaequeebuyaequ1reishiujuu6weisao7ohc
query: |
subscription {
user(where: {
mutation_in: [UPDATED]
}) {
node {
name
email
}
}
}
The userChangedEmail subscription configured above would be triggered by a mutation like this:
mutation {
updateUser(
data: { email: "[email protected]" },
where: { id: "cjcgo976g5twb018740bzyy4q" }
) {
id
}
}