Is it possible to call multiple queries with useQuery?
See original GitHub issueHi, In advance thank you great library.
In our product, there is the a page which needs data from 2 or 3 GraphQL queries and we want to call multiple queries with one useQuery().
export const Curriculums = ({ children }) => {
const { data, error } = useQuery(QUERY_CURRICULUMS)
/* We want to call useQuery as below
const { data, error } = useQuery([
QUERY_CURRICULUMS,
QUERY_COURSES,
QUERY_LESSONS
]
)
*/
if (error) {
throw error
}
return children(data)
}
Is it possible to do the same things as compose() method defined in react-apollo?
https://www.apollographql.com/docs/react/react-apollo-migration#compose-to-render-composition
Or should we call useQuery with each queries?
Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:22
Top Results From Across the Web
Multiple queries in a single component with useQuery hook
Is it possible to run more than one query with the useQuery hook a single component? Independent queries, in fact. useQuery seems to...
Read more >multiple usequeries in a single component - Stack Overflow
Indeed you can use multiple queries const queryMultiple = () => { const res1 = useQuery(Get_Doctor); const res2 = useQuery(GET_Branch); ...
Read more >How to use Apollo useQuery with multiple queries
How to handle multiple queries in a single query via the Apollo useQuery hook ... Thanks to the way we create queries in...
Read more >How to handle multiple queries with React-Query - JS-HowTo
1- Multiple independent queries. React-Query comes with a hook called useQueries, This hook can be used to fetch a variable number of queries....
Read more >How to use Apollo useQuery with multiple queries - Reddit
Hi Everyone! I have just finished writing my latest blog post about how to use Apollo useQuery with multiple queries. It includes multiple...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a simple solution that worked for me.
I am simply renaming the fields useQuery is giving me in the first call, so that they can live in the same scope, otherwise the second query will overwrite the first.
compose
just calls multiple HOCs together, but it doesn’t anything else, in fact you have to map the result of the queries manually to avoid them from being overridden by the next query.What you want to do is compose multiple
useQuery
into your own custom hook: