我正在使用@vue/apollo-composable
and开发一个 vue3 项目@graphql-codegen
。
我的索引页面执行搜索查询。该查询的每个结果在页面上都有一个磁贴。我希望缓存会回答切片查询,但相反,它们总是会错过。
在页面级别,我执行以下查询:
query getTokens($limit: Int!) {
tokens(limit: $limit) {
...tokenInfo
}
}
在我执行的 tile 组件内部:
query getToken($id: uuid!){
token(id: $id) {
...tokenInfo
}
}
片段如下所示:
fragment tokenInfo on token {
id
name
}
期望:缓存将处理 tile 组件内 100% 的查询。(我希望避免将这些数据序列化到 vuex 的失败)。
现实:我收到 n+1 个后端调用。我尝试了一堆排列,包括摆脱片段。如果我发送没有数据的getToken
呼叫,fetchPolicy: 'cache-only'
则返回。
apollo 客户端配置非常基础:
const cache = new InMemoryCache();
const defaultClient = new ApolloClient({
uri: 'http://localhost:8080/v1/graphql',
cache: cache,
connectToDevTools: true,
});
const app = createApp(App)
.use(Store, StateKey)
.use(router)
.provide(DefaultApolloClient, defaultClient);
我还附上了我的 apollo 开发工具的屏幕截图。看起来缓存实际上正在填充规范化数据:
任何帮助将不胜感激!:)