Announcement of GraphQL Subscriptions for Every Data Source
StepZen now supports GraphQL subscriptions for every Data Source! Including REST APIs, Databases (SQL & NoSQL), and other GraphQL APIs. Subscriptions can be created in the same declarative way as any other operation type in StepZen.
What are GraphQL subscriptions?
GraphQL subscriptions are another operation type next to queries and mutations. They can push data from a GraphQL API to a client when data changes or a specific event occurs. This is useful when you are working with streaming or real-time data and want to push data instead of polling the server to receive new data. For example, when you're building a chat application and want to push a notification to a user when a new message is received or when you want to push a new order to a client when a customer places a new order in an e-commerce application.
How to use subscriptions in StepZen
In StepZen, you can define a GraphQL Subscription the same way you define other GraphQL operation types. In a declarative way! When you define a new subscription in your StepZen GraphQL schema, you can use the @materializer
directive to set the query that needs to be watched for changes. StepZen will poll the data source for changes and push the new data to the client when a change occurs.
type Query {
price: Price!
@rest (endpoint: "...")
@dbquery (type: "...")
@graphql (endpoint: "...")
}
type Subscription {
price: Price! @materializer (query: "price")
}
The subscription operation that StepZen will watch for changes can be have any valid field selection, supported by any number of data sources. For example, if you are using a REST API, you can pass a query to the @materializer
directive built on top of an @rest
directive. The same goes for databases (@dbquery
) and other GraphQL APIs (@graphql
).
From the StepZen Dashboard you can see the subscription operation in the GraphQL Explorer. When you use a subscription operation in the GraphQL Explorer you can see the result of the subscription changing when new data is available.
Or use a subscription client to use subscriptions in an application. You can watch a video walkthrough on YouTube, including the usage of a subscription client, by clicking the image below.
Or find more details on using GraphQL subscriptions in StepZen in this blog post. And a complete code example in this GitHub repository
Next Steps?
We're always looking to improve StepZen and continue making updates to our product. We deploy new versions of StepZen weekly, so expect new features to be released regularly.
Follow us on Twitter or join our Discord community to stay updated about our latest developments.