-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does the code-gen support stream service? #31
Comments
Streaming is not supported today, but only because we have yet to find a situation where it'd be useful with react-query's API. I'd be very interested in working with you to better understand your use-case so we can see if there's a react-query API (perhaps, useInfiniteQuery that could be a good fit for your use-case). If you'd like to do that, could you possible provide an example (similar to https://github.com/bufbuild/connect-query/blob/main/examples/react/basic/src/example.tsx perhaps) of how you might envision something like this working? |
I wanted to incorporate connect/disconnect/reconnect into a single React hook so I wrote the following:
And it would be used as:
|
I just noticed that my previous post missed my opening comments to the issue. You could treat a stream much like how Tk demonstrates wrapping a websocket connection but you still need to handle reconnects. I am taking a different approach and merging Connect's support for React Query and ES by creating a React hook that takes advantage of the |
@seamusv Thanks very much for sharing! I'll try it out next time I need to handle streaming endpoints. I felt@dimitropoulos 's point is valid and I ended up simply handling the generated connect-es streaming endpoint like this before dispatching the message to the global store. const launchWatcher = async () => {
console.log(`Starting watcher ${watcherId}...`);
try {
const stream = myapp.watchServerEvents({});
let counter = 0;
for await (const response of stream) {
counter++;
console.log(`Message ${counter} from watcher ${watcherId}:`, response.message);
handleWatchServerEventMessages(response.message);
}
} catch (error) {
console.error(`Error occurred in launch watcher ${watcherId}:`, error);
}
}; |
I have a
But the generated
SampleService_connectquery.ts
is empty.The code-gen works for unary calls.
Is streaming supported? Thanks!
The text was updated successfully, but these errors were encountered: