Skip to content
Discussion options

You must be logged in to vote

Looks like there isn't a direct way to use subscriptions with GraphQL. There were discussions about building something like useStreamQuery but it wasn't implemented. So I came up with my own approach to using subscriptions.

Since most subscriptions are just updates on the data that was already fetched by one of my graphQL queries, Say I have to fetch a list of tasks

My initial Query will look something like this:

const useTasks = () => {
  return useQuery("tasks", fetchTasks)
}

Now, any update on the tasks data will fire a subscription that will give me the modified / new task with an ID. So I add my subscription in useEffect & update the API data directly using queryClient

const onNewTask =

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@andrei-zgirvaci
Comment options

Answer selected by DaniAkash
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@EssamKayal96
Comment options

@EssamKayal96
Comment options

@ikoif
Comment options

@ThomasObenaus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants