News for hackers. Stuff that matters.
Re:GraphQL Live Queries with live directive by satvikpendem on Monday January 16, 2023 @03:13PM (#34404964)
I love GraphQL, it makes generating types for any language very easy, with one schema, and you don't have to worry about the shape of the response on either the server or the client due to such types. If you don't need multiple clients and are using TypeScript, you could use trpc though (and with Rust I also know of rspc).

This article is interesting, however it seems `@live` isn't part of the official specification. Also, you can use something like TanStack Query to synchronize server state, which works with GraphQL as well as regular REST, or you can use a GraphQL client directly like Apollo or urql, which also does the same syncing, so I'm not sure for what purpose this directive serves exactly. Maybe it's for languages that don't have a good server side syncing library?

Re:GraphQL Live Queries with live directive by notrab on Monday January 16, 2023 @03:35PM (#34405169)
The purpose of the `@live` query is that it uses server-sent events to update the client state with any new changes that happen on the server. It's correct that you can use something like Tanstack Query, useSWR, React Apollo, or even fetch to poll the server again but that requires fetching all of the data that was previously fetched to update the client state. Instead with SSE, you get a diff in the format of JSON Patch that you can use to apply any changes to the current state without refetching everything.

There are many implementations of Live Queries (some that just use polling under the hood) but we really like the concept of using JSON Patch with SSE.

Re:GraphQL Live Queries with live directive by notrab on Monday January 16, 2023 @03:41PM (#34405234)
I should add that using regular queries with Apollo, URQL, etc. is perfectly fine. If you're building an app that requires realtime data then `@live` queries can be really useful. The data can update in realtime without refreshing and there's no need for WebSockets!

There are limitations to server-sent events, but `@live` queries is a perfect fit imo.

Re:GraphQL Live Queries with live directive by smurda on Monday January 16, 2023 @03:25PM (#34405075)
Longer thread - Subscriptions RFC: Are Subscriptions and Live Queries the same thing?

https://github.com/graphql/graphql-spec/issues/284

Re:GraphQL Live Queries with live directive by revskill on Monday January 16, 2023 @03:24PM (#34405072)
I'm still not sure about benefit of GraphQL over welled designed Restful API.
Re:GraphQL Live Queries with live directive by fbjork on Tuesday January 17, 2023 @04:34AM (#34410669)
We chose GraphQL at Grafbase for a few reasons:

- The client can ask for the data it needs, which also improves performance by reducing bandwidth

- Aggregating data from multiple data sources with a single request

- Widely adopted and loved by frontend and mobile developers