Lets say I have a query that gets an advisors
. That query returns a list of advisor id
s that are connected to that advisor. Now I want to rerun the query that got the advisor in the first place, with the n
number of id
s, and get those advisors. I only need to do this once, and not recursively.
const query = graphql`
query AdvisorProfileQuery($id: ID!) {
advisor: node(id: $id) {
... on Advisor {
name
assignments (first: 100) {
edges {
node {
id <---- i want these ids and plug them back into the query to just get "name" of the list of ids
}
}
}
}
}
}
`;
const QueryRenderer = LoadingQueryRenderer(AdvisorProfile, query);
export default ({ i18n }) => {
const { id } = useParams();
return (
<>
<QueryRenderer params={{ id: id }} />
</>
);
};
Answer was to create a fragment and splat it in...
Parent component
const query = graphql`
query AdvisorProfileQuery($id: ID!) {
advisor: node(id: $id) {
... on Advisor {
... BottomCardTable_advisor
name
}
}
}
`;
const QueryRenderer = LoadingQueryRenderer(AdvisorProfile, query);
export default ({ i18n }) => {
const { id } = useParams();
return (
<>
<QueryRenderer params={{ id: id }} />
</>
);
};
on child component
export default createFragmentContainer(TableComponent, graphql`
fragment BottomCardTable_advisor on Advisor {
assignments: assignments (first: 100) {
edges {
node {
id
primaryName
primaryEmail
assignedOn
type
}
}
}
}
`);