- Updated: March 19, 2026
- 5 min read
Adding GraphQL Subscription Support to the OpenClaw Rating API
To add GraphQL subscription support to the OpenClaw Rating API edge, you need to extend the GraphQL schema, implement a subscription resolver that publishes real‑time rating events, and redeploy the updated service on the UBOS platform.
Introduction
OpenClaw is a lightweight, open‑source rating engine that powers millions of real‑time scoring use‑cases. While its REST endpoints are battle‑tested, many modern applications demand push‑based updates so that UI components can react instantly to new ratings. GraphQL subscriptions fill that gap by providing a WebSocket‑based, event‑driven API.
This tutorial walks you through a complete, step‑by‑step implementation of GraphQL subscription support for the OpenClaw Rating API edge. You’ll see the exact schema changes, resolver code, deployment workflow on UBOS homepage, and testing strategy.
Prerequisites
- Basic familiarity with UBOS platform overview and its container‑based deployment model.
- Node.js ≥ 16, npm ≥ 8, and a local clone of the OpenClaw repository.
- Docker installed (for local testing) and a UBOS account with access to the OpenClaw hosting page.
- Understanding of GraphQL basics – queries, mutations, and subscriptions.
- Optional but recommended: familiarity with OpenAI ChatGPT integration for generating documentation snippets.
Setting up OpenClaw
First, spin up a local OpenClaw instance to serve as a development sandbox.
git clone https://github.com/openclaw/openclaw.git
cd openclaw
docker compose up -d
# Verify the service
curl http://localhost:8080/healthWhen the health endpoint returns OK, you have a running OpenClaw API ready for extension.
Adding GraphQL Subscription Support
Schema Changes
OpenClaw already ships a GraphQL schema for queries and mutations. To enable subscriptions, add a new RatingAdded event type and a ratingAdded subscription field.
type Rating {
id: ID!
itemId: String!
score: Float!
createdAt: String!
}
type RatingAdded {
rating: Rating!
}
type Subscription {
ratingAdded(itemId: String!): RatingAdded!
}Notice the itemId argument – it lets clients filter events for a specific item, reducing unnecessary traffic.
Resolver Implementation
UBOS uses Web app editor on UBOS to manage serverless functions. Create a new file subscriptionResolver.js and wire it to the GraphQL server.
// subscriptionResolver.js
const { PubSub } = require('graphql-subscriptions');
const pubsub = new PubSub();
const RATING_ADDED = 'RATING_ADDED';
// Export the subscription resolver
module.exports = {
Subscription: {
ratingAdded: {
// Filter by itemId
subscribe: (_, { itemId }) => pubsub.asyncIterator(RATING_ADDED),
resolve: (payload, args) => {
if (payload.rating.itemId === args.itemId) {
return { rating: payload.rating };
}
return null; // filtered out
},
},
},
// Helper to publish a new rating
publishRating: (rating) => {
pubsub.publish(RATING_ADDED, { ratingAdded: { rating } });
},
};Next, modify the existing rating creation mutation to call publishRating after persisting the rating.
// ratingMutation.js (excerpt)
const { publishRating } = require('./subscriptionResolver');
module.exports = {
Mutation: {
addRating: async (_, { itemId, score }) => {
const rating = await RatingModel.create({ itemId, score });
// Emit the subscription event
publishRating(rating);
return rating;
},
},
};With these changes, every new rating triggers a GraphQL subscription event that any client subscribed via WebSocket will receive instantly.
Deployment Steps
UBOS simplifies deployment through its Workflow automation studio. Follow these steps:
- Commit your changes to a new Git branch (e.g.,
feature/graphql-subscriptions). - Push the branch to your remote repository.
- In the UBOS dashboard, create a new App and select “Import from Git”.
- Configure the build command:
npm install && npm run build - Set the runtime environment variable
GRAPHQL_SUBSCRIPTIONS=truein the Settings tab. - Enable the WebSocket port (default
4000) under “Network”. - Click “Deploy”. UBOS will build a Docker image, push it to its registry, and spin up a scalable instance.
After deployment, verify the endpoint:
curl -X POST https://your-app.ubos.tech/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ __schema { types { name } } }"}'If the schema includes the ratingAdded subscription, you’re ready to test.
Testing the Subscription
Use a GraphQL client that supports subscriptions, such as Apollo Client or GraphQL Playground.
Subscribe to rating events for a specific item:
subscription OnRatingAdded($itemId: String!) {
ratingAdded(itemId: $itemId) {
rating {
id
score
createdAt
}
}
}In a separate terminal, trigger a new rating via mutation:
mutation AddRating {
addRating(itemId: "movie-123", score: 4.5) {
id
score
}
}The subscription client should instantly receive the new rating payload, confirming real‑time delivery.
Troubleshooting Tips
- WebSocket connection refused: Verify that the WebSocket port (4000) is exposed in the UBOS app settings. Also, ensure your client uses
wss://when the app runs over HTTPS. - No events received: Check that the
publishRatingfunction is called after the rating is persisted. Add aconsole.logbefore publishing to confirm execution. - Filtered events missing: The resolver filters by
itemId. Ensure the subscription argument matches theitemIdof the created rating. - Performance degradation under load: Switch the in‑memory
PubSubto a distributed broker like Redis. UBOS supports Redis as an add‑on; see the Chroma DB integration for a quick start. - Deployment fails with “missing environment variable”: Double‑check that
GRAPHQL_SUBSCRIPTIONSis set and that you have committed the.envfile (or configured variables via the dashboard).
Conclusion and Next Steps
By extending the OpenClaw Rating API with GraphQL subscriptions, you’ve transformed a classic request‑response service into a real‑time data engine. This capability unlocks use‑cases such as live leaderboards, instant feedback loops, and dynamic recommendation engines.
Ready to scale? Consider the following next steps:
- Integrate AI Email Marketing to notify users when their rating crosses a threshold.
- Leverage the AI Video Generator to create personalized video summaries of rating trends.
- Deploy the service to a production cluster using the Enterprise AI platform by UBOS for auto‑scaling and monitoring.
- Explore the UBOS templates for quick start to bootstrap additional micro‑services that consume the subscription feed.
For a complete walkthrough of hosting OpenClaw on UBOS, visit the dedicated OpenClaw hosting page. Happy coding!
Source: Original news article