i've been trying how to make my query system work but i don't know how.
Im using React D3 Tree, im fetching 4 queryes from Apollo Graphql:
-enterprises -factories -areas -nodes
each one is dependant, for example factories need enterprise id to fetch or areas need factory id.
This is the code i have at the moment
// Query Calls
const { data: enterprises } = useQuery(getEnterprises);
const { data: factories } = useQuery(getFactories, {
variables: {
"enterprise_id": enterprises?.enterprises[0].id,
},
skip: !enterprises || !enterprises.enterprises || enterprises.enterprises.length === 0,
});
const { data: areas, } = useQuery(getAreas, {
variables: {
"factory_id": factories?.factories[0].id,
},
skip: !factories || !factories.factories || factories.factories.length === 0,
});
const { data: nodes, loading: loading2 } = useQuery(getNodes, {
variables: {
"area_id": areas?.areas[0].id,
},
skip: !areas || !areas.areas || areas.areas.length === 0,
});
This aproach works but im only fetching the first of each and i want to fetch all data, i tried to use functions that return mapped queries but throws error because the argument is undefined.
Any help will be apreciated