I have a queries file that looks like this:
import {gql} from \'react-apollo\';
const queries = {
getApps: gql`
{
apps {
id
name
The Emergence of Apollo Client useQuery Hooks; have changed everything. If you are reading this in 2020 or beyond; I am pretty much sure that you likely be using Apollo client useQuery hook. You can call useQuery Hook as many times as you want to execute the both queries. You can learn more about useQuery hooks in its official documentation https://www.apollographql.com/docs/react/data/queries/ I find it so useful in my recent project. E.g
const queries = {
getApps: gql`
{
apps {
id
name
}
}
`,
getSubjects: gql`
{
subjects {
id
name
}
}
`
};
const { loading, error, data } = useQuery(queries);
const { loading:getSubjectsLoading, error:getSubjectsError, data:getSubjects } = useQuery(getSubjects);
if (loading || getSubjectsLoading) return "Loading...";
if (error || getSubjectsError ) return Error :(
;
console.log(data);
console.log(getSubjects);