(中继)根据该查询的结果重新运行查询的正确语法是什么
(Relay) What is the correct syntax to re-run a query based on the result of that query
假设我有一个获取 advisors
的查询。该查询 returns 连接到该顾问的顾问列表 id
。现在我想重新运行首先获得顾问的查询,其中 n
数量的 id
s,并获得那些顾问。我只需要这样做一次,而不是递归。
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 }} />
</>
);
};
答案是创建一个片段并将其拼接成...
父组件
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 }} />
</>
);
};
在子组件上
export default createFragmentContainer(TableComponent, graphql`
fragment BottomCardTable_advisor on Advisor {
assignments: assignments (first: 100) {
edges {
node {
id
primaryName
primaryEmail
assignedOn
type
}
}
}
}
`);
假设我有一个获取 advisors
的查询。该查询 returns 连接到该顾问的顾问列表 id
。现在我想重新运行首先获得顾问的查询,其中 n
数量的 id
s,并获得那些顾问。我只需要这样做一次,而不是递归。
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 }} />
</>
);
};
答案是创建一个片段并将其拼接成...
父组件
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 }} />
</>
);
};
在子组件上
export default createFragmentContainer(TableComponent, graphql`
fragment BottomCardTable_advisor on Advisor {
assignments: assignments (first: 100) {
edges {
node {
id
primaryName
primaryEmail
assignedOn
type
}
}
}
}
`);