【发布时间】:2021-01-11 22:38:56
【问题描述】:
我正在尝试分两步加载有关类型的信息(因为我在 secondQuery 中要求的信息需要一些时间才能加载):
组件:
const MyComponent = ({startDate}) => {
const firstQuery = useQuery(
GET_INFO_PART_ONE,
{
variables: {startDate}
}
);
const secondQuery = useQuery(
GET_INFO_PART_TWO,
{
variables: {startDate}
}
);
}
查询:
export const GET_INFO_PART_ONE = gql`
query getInfoPartOne(
$startDate: DateTime!
) {
infoPageResults(
startDate: $startDate
) {
edges {
info {
infoID
infoFieldOne
infoFieldTwo
infoFieldThree
}
}
}
}
`;
export const GET_INFO_PART_TWO = gql`
query getInfoPartTwo(
$startDate: DateTime!
) {
infoPageResults(
startDate: $startDate
) {
edges {
info {
infoID
infoFieldFour{
netRate
}
}
}
}
}
`;
当我这样做并且两个查询都解决时,缓存的 ROOT_QUERY 包含我期望的数据,其中 infoPageResults 包含一个边数组,其中每个边的 info __typename 包括在 GET_INFO_PART_ONE 和 @987654325 中指定的字段@查询。然后,我希望上述组件中的 firstQuery.data.infoPageResults.edges 包含从第二个查询加载的字段。
问题
在 firstQuery 和 secondQuery 都完成加载后,firstQuery.data.infoPageResults.edges 不包含 secondQuery 加载的字段,即使缓存的值看起来像我预期的那样。
- 我对查询挂钩的工作方式有什么明显的误解吗?
- 有没有更好的策略分两步将附加字段加载到 _typename 上?
【问题讨论】:
标签: graphql apollo-client