TanStackT
TanStack3y ago
2 replies
spotty-amber

Register query functions react-query

Hey team -- curious how to register functions in react-query. Can we force register them?

Particularly seeing this issue in my app:

1. In our "new project" flow, a user creates a new project, with a mutation, which we store in the cache like so:

queryClient.setQueryData(
  QueryCacheKeys.project(newProject.id),
  newProject,
);


2. User uploads a file in our onboarding flow, which runs a background processing task to parse the file and extract certain pieces of data from it. That data is stored in our DB on the project table. When the function has completed, sends a webhook to the client which then calls this line:

queryClient.refetchQueries(QueryCacheKeys.project(projectId));

3. I see an error saying "missing query function for query key ["project", UUID].

My best guess is that by step 3, the useProject has not been called, so react-query doesn't know about it. Is that correct? Is there a way for it to force register the hook?
Was this page helpful?