2 Replies
Hi @Jestem_Kamil. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Currently, Wasp doesn't have built-in support for real-time queries in the traditional sense. Wasp's query system is designed around a request-response model where data is fetched when requested and then automatically refreshed when related entities are modified through actions.
Current Query Behavior
When you use queries in Wasp, they work like this:
1. You declare a query in your
.wasp
file and specify which entities it uses
2. You implement the query in JavaScript/TypeScript
3. You can then use the query in your React components with the useQuery
hook
Wasp automatically handles cache invalidation when entities are modified through actions. For example, if you have a getTasks
query and a createTask
action that both use the Task
entity, when createTask
is called, Wasp will automatically refresh the getTasks
query data in the background Docs > Tutorial > 6. Modifying Data.
Planned Real-time Features
There are open issues in the Wasp GitHub repository discussing the addition of real-time data updates:
1. Issue #1454 discusses adding support for real-time data updates using websockets, where the server would send update events to clients when operations are invoked Adding support for real-time data updates.
2. Issue #144 mentions adding support for sockets between client and server, which would allow users to react live to events happening on the server Add support for sockets (client <-> server).
Current Workarounds
Until native real-time support is added to Wasp, you have a few options:
1. Rely on Wasp's automatic query invalidation (which requires a user action to trigger)
2. Implement polling with the useQuery
hook (setting a refetch interval)
3. Implement your own websocket solution using libraries like Socket.io
The Wasp team is aware of the need for real-time features and is working on solutions, potentially drawing inspiration from other systems like Supabase and Directus that have implemented similar real-time functionality.
I hope this helps clarify the current state of real-time queries in Wasp!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Jestem_Kamil, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Hey Jestem, can you be more specific? 🙂