Update data in realtime without websocket
Answered
Rebon posted this in #help-forum
RebonOP
I have an app that is made up of 2 pages. Admin and user. The user is able to change his status from active to inactive. The admin has a list of all users and their status. The problem that I am facing is that I want is when the user changes his status the pages of the admin gets. updated without refreshing on blurring and focusing back on. I have tried tRPC and cache validation but it didn't work. How can I achieve the real time change?
Will using revalidateInterval cost a lot of money since they are run on the server?
Will using revalidateInterval cost a lot of money since they are run on the server?
Answered by B33fb0n3
you can also subscribe to specific database events. When you use aws amplify graphql, you can directly use these [realtime subscriptions](https://docs.amplify.aws/gen1/javascript/build-a-backend/graphqlapi/subscribe-data/). If you are using for example prisma, you can also subscribe to realtime events [see here](https://v1.prisma.io/docs/1.34/prisma-client/features/realtime-JAVASCRIPT-rsc8/#:~:text=The%20Prisma%20client%20lets%20you,the%20model%20(but%20lowercased).).
7 Replies
@Rebon I have an app that is made up of 2 pages. Admin and user. The user is able to change his status from active to inactive. The admin has a list of all users and their status. The problem that I am facing is that I want is when the user changes his status the pages of the admin gets. updated without refreshing on blurring and focusing back on. I have tried tRPC and cache validation but it didn't work. How can I achieve the real time change?
Will using revalidateInterval cost a lot of money since they are run on the server?
Will using revalidateInterval cost a lot of money since they are run on the server?when you are using a clientside library like swr or react query, then that will be handled by the client. However: your server need to answer the request. So define for example a 1 minute interval and then it should be fine
RebonOP
the current tRPC in built on React query. But I am using db search queries function in the queryfn. Would that cost me function calls in hosting?
@Rebon the current tRPC in built on React query. But I am using db search queries function in the queryfn. Would that cost me function calls in hosting?
yes, your server still need to answer the specific requests
RebonOP
is there a way to only refetch automatic when the data is mutated, and update the ui without refreshing?
@Rebon is there a way to only refetch automatic when the data is mutated, and update the ui without refreshing?
you can also subscribe to specific database events. When you use aws amplify graphql, you can directly use these [realtime subscriptions](https://docs.amplify.aws/gen1/javascript/build-a-backend/graphqlapi/subscribe-data/). If you are using for example prisma, you can also subscribe to realtime events [see here](https://v1.prisma.io/docs/1.34/prisma-client/features/realtime-JAVASCRIPT-rsc8/#:~:text=The%20Prisma%20client%20lets%20you,the%20model%20(but%20lowercased).).
Answer
RebonOP
Okay, I will try to test that out. Thanks a lot ❤️❤️
@Rebon Okay, I will try to test that out. Thanks a lot ❤️❤️
Happy to help. Is your thread solved like that?