-
Notifications
You must be signed in to change notification settings - Fork 7
Description
We're implementing a feature in our application that requires executing multiple GraphQL queries that are determined at runtime. Currently, Apollo Client doesn't provide a clean way to handle this use case.
We'd like to propose adding a useQueries
hook that would allow for elegant handling of multiple dynamic queries, similar to:
const visibleSteps = STEPS.filter(isStepVisible);
const results = useQueries(
visibleSteps.map(step => ({
query: step.query,
variables: step.variables
}))
);
While there is a similar feature request (#178) the solution proposed there only addresses running the same query multiple times with different variables.
Our use case requires running completely different queries that are determined at runtime. TanStack Query (formerly React Query) already offers this functionality through their useQueries hook.
It's worth noting that while we could potentially use Apollo Client directly for this purpose, there's currently no way to utilize the cache-and-network
fetch policy in such an implementation, which is a critical requirement for our application's data fetching strategy.
Adding this capability to Apollo Client would significantly improve developer experience for complex applications that need to fetch data from multiple dynamic sources simultaneously while maintaining proper caching behavior.