决明子泡水喝有什么好处| 外来猫进家有什么预兆| 先锋霉素又叫什么| momax是什么牌子| 黄芪和枸杞泡水喝有什么作用| 一什么荷花| 猫砂是干什么用的| 马甲线长什么样| 低聚木糖是什么| 五月初七是什么星座| 老梗是什么意思| 甲状腺结节挂什么科| 膝盖疼吃什么药好| 肝功高是什么原因引起的| 黄芪的功效是什么| 什么是前庭功能| 火是什么意思| 橙子皮泡水喝有什么好处| 下一个台风什么时候来| 胃热吃什么药最有效| 辄是什么意思| 假如时光倒流我能做什么| 心气虚吃什么食物补| 小苏打是什么| 稚嫩是什么意思| 男性生殖系统感染吃什么药| 大葱什么时候播种| 失聪是什么意思| kkb什么意思| 纤维是什么意思| 舌钉有什么用| 梦见春梦是什么意思| 吉利丁片是什么做的| 皮炎是什么| 明月照沟渠是什么意思| 梦见下大雨是什么征兆| av是什么| 一个既一个旦念什么| 乳糖酶是什么| 脑神经检查做什么检查| 水晶粉是什么原料做的| 头皮发麻什么原因| 混社会的人一般干什么| 民政局是干什么的| mrcp是什么检查| 黄芪不能和什么一起吃| 什么什么的太阳| 牙龈痛吃什么药| 什么的水流| 氨纶是什么面料| 2004年是什么年| 1956属什么生肖| 正常人为什么会得梅毒| 地板砖什么颜色好看| 什么是买手店| 女人气血不足吃什么补| 乌黑乌黑的什么| nadh是什么| 孩子张嘴睡觉是什么原因| 副营长是什么军衔| 辣椒炒肉用什么肉| 杭州都有什么区| 肚子为什么胀气| 幽门螺旋杆菌抗体阳性是什么意思| 1968属什么生肖| 钾低会出现什么症状| 声音有磁性是什么意思| 鸡打瞌睡吃什么药| energy是什么牌子| 什么风大雨| sport什么品牌| 县公安局长什么级别| 腿容易麻是什么原因| 一马平川是什么生肖| 血管瘤是什么样子的| 脚板麻木是什么原因| 42是什么意思| 九浅一深是什么意思| 上次闰六月是什么时候| 鹅蛋炒什么好吃| 菠萝是什么季节的水果| 车前草长什么样| 什么时候测血压最准| 吃什么盐最好| 梦见狮子是什么预兆| 岔气是什么意思| 变卖是什么意思| 宫颈肥大有什么危害| 儿童看牙齿挂什么科| boby是什么意思| 湿疹吃什么食物| 杜冷丁是什么| 什么时候开始数伏| 牙龈上火吃什么药| 十点半是什么时辰| 副检察长什么级别| 为什么耳屎是湿的| 身上冷是什么原因| 藏拙是什么意思| 柏拉图爱情是什么意思| 右肺中叶索条什么意思| 2月19日什么星座| 心衰有什么症状| 怀孕的肚子是什么样的| 自汗吃什么中成药| 全麦粉和小麦粉的区别是什么| 腰椎退行性变是什么意思| 储备是什么意思| 小孩子眼睛眨得很频繁是什么原因| 为什么低血糖| 什么是义务兵| 卵巢增大是什么原因引起的| 产后抑郁症有什么表现症状| 什么是根管治疗牙齿| 高考四百分左右能上什么学校| 什么是红斑狼疮病| 肚子胀气吃什么通气| 望穿秋水的意思是什么| 禄蠹是什么意思| 病灶是什么意思| 加德纳菌阳性是什么意思| 六月一号什么星座| 宫寒应该吃什么怎样调理| 左卵巢囊性结构是什么意思| 日语牙白什么意思| 三八妇女节送什么好| 是什么样的| 改姓需要什么手续| 隆字五行属什么| 小便出血是什么原因| 梦见摘丝瓜有什么预兆| 射手座的幸运色是什么| 坐骨神经有什么症状| 1994年属什么生肖| ysl是什么品牌| 拉拉秧学名叫什么| 五行木是什么颜色| 神经纤维瘤是什么病| 雪梨是什么梨| 吃大枣有什么好处| 先下手为强是什么意思| 上海有什么特产| 肝功能挂什么科| 芥子是什么意思| 瘦西湖为什么叫瘦西湖| 什么样的空气| 17楼五行属什么| 精囊在什么位置| a1什么意思| 献血后吃什么| 织物是什么材质| 菲薄是什么意思| 粉尘螨是什么东西| 荷字五行属什么| 肝内小囊肿是什么意思| 来月经适合吃什么水果| 胃炎吃什么药| 白完念什么| 切尔西是什么意思| 韩语欧巴是什么意思| 海关锁是什么意思| dr检查是什么| 太阳指什么生肖| 为什么不能拜女娲娘娘| 9527是什么意思| 八五年属什么生肖| 角先生是什么| 渡人渡己什么意思| 经常掏耳朵有什么危害| 七喜是什么饮料| 退行性变是什么意思| 做梦梦到和别人吵架是什么意思| gdp指的是什么| 为什么睡觉会流口水| 标准差是什么| 经常出鼻血是什么原因| 什么黄河| 吃什么能降甘油三酯| 交配是什么意思| 丰富的近义词和反义词是什么| 全国政协常委什么级别| 女性尿道炎吃什么药| 不义之财是什么意思| 加湿器有什么作用| 姑息性化疗什么意思| 鞠婧祎什么星座| 补充微量元素吃什么| 犯罪心理学属于什么专业| 咳嗽挂号挂什么科| 清真不吃什么肉| 跃字五行属什么| 玉米淀粉是什么| 18K金什么意思| 脸上皮肤痒是什么原因| 梦见家被偷了什么预兆| 8月19号是什么星座| 生殖科是检查什么的| 眼镜发明之前眼镜蛇叫什么| 打升白针有什么副作用| 洄游是什么意思| 白细胞满视野是什么意思| 红艳桃花是什么意思| 什么是半月板损伤| 疳积有什么症状| 手足口病是什么原因引起的| 蒙脱石是什么东西| 晨五行属什么| 再创佳绩是什么意思| 外贸原单是什么意思| 开门是什么意思| 电解液是什么| 戒定真香是什么意思| 1992年属什么| 爆菊是什么意思| design是什么牌子| 15年婚姻是什么婚| 大腿后侧疼痛什么原因| 对什么有益英语| 小米粥和什么搭配最好| 甲沟炎是什么引起的| 蛋白质用什么试剂鉴定| 安置房和商品房有什么区别| 什么时候不能喷芸苔素| 低氧血症是什么意思| 去脂肪粒最有效的药膏叫什么| 17592a是什么尺码男装| 同学生日送什么礼物| 盆腔积液什么意思| 血糖偏高能吃什么水果| 掌中宝是什么部位| 湿气重是什么原因引起的| 80岁属什么生肖| 和衣是什么意思| 能量守恒是什么意思| 紫菜是什么植物| 肝右叶占位是什么意思| 订盟是什么意思| 晚来天欲雪能饮一杯无什么意思| 什么时候同房容易怀孕| 麻酱是什么做的| 女人颧骨高有什么说法| 生理期量少是什么原因| 宫颈炎盆腔炎吃什么药效果最好| 狗懒子是什么意思| 英雄难过美人关是什么意思| 床头朝向有什么讲究| 耳蜗是什么| 经常掉头发是什么原因| 何首乌长什么样子图片| 脑卒中是什么病| 沙中土是什么生肖| 直辖市是什么级别| 乌龟王八甲鱼鳖有什么区别| 骨量偏高是什么原因| 西红柿什么时候吃最好| 支气管炎吃什么| 观音菩萨属什么生肖| 珍珠奶茶的珍珠是什么做的| 抗凝血是什么意思| 周瑜属什么生肖| 蚂蚁喜欢吃什么| 为什么不建议开眼角| 什么叫肾阴虚和肾阳虚| 红枣和什么不能一起吃| 百度

4.2亿人贡献:中国货基规模全球排名仅次于美国(附


百度 但是当女协警以满腹委屈的姿态站出来,声称要为自己讨一个清白的时候,至少提醒人们存在着这样的一种可能性,也许事情不是网帖里所说的那样,也许女协警真的是清白的无辜的。

Apollo Client allows you to make local modifications to your GraphQL data by updating the cache, but sometimes it's more straightforward to update your client-side GraphQL data by refetching queries from the server.

In theory, you could refetch every active query after a client-side update, but you can save time and network bandwidth by refetching queries more selectively. The InMemoryCache helps you determine which active queries might have been invalidated by recent cache updates.

Local cache updates and refetching work especially well in combination: your application can display the results of local cache modifications immediately, while also refetching in the background to obtain the very latest data from the server. The UI is then rerendered only if there are differences between local data and refetched data.

Refetching is especially common after a mutation, so mutate functions accept options like refetchQueries and onQueryUpdated to specify which queries should be refetched, and how.

To selectively refetch queries outside of a mutation, you instead use the refetchQueries method of ApolloClient, which is documented here.

client.refetchQueries

This method is new in Apollo Client 3.4.

Refetch options

The client.refetchQueries method take an options object that conforms to the following TypeScript interface:

TypeScript
1interface RefetchQueriesOptions<
2  TCache extends ApolloCache<any>,
3  TResult = Promise<ApolloQueryResult<any>>,
4> {
5  updateCache?: (cache: TCache) => void;
6  include?: Array<string | DocumentNode> | "all" | "active";
7  onQueryUpdated?: (
8    observableQuery: ObservableQuery<any>,
9    diff: Cache.DiffResult<any>,
10    lastDiff: Cache.DiffResult<any> | undefined,
11  ) => boolean | TResult;
12  optimistic?: boolean;
13}

These fields are described below:

Name /
Type
Description
updateCache
(cache: TCache) => void
Optional function that updates cached fields to trigger refetches of queries that include those fields.
include
Array<string | DocumentNode> | "all" | "active"
Optional array specifying queries to refetch. Each element can be either a query's string name or a DocumentNode object.Analogous to the options.refetchQueries array for mutations.Pass "active" (or "all") as a shorthand to refetch all (active) queries.
onQueryUpdated
(observableQuery: ObservableQuery<any>, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => boolean | TResult
Optional callback function that's called once for each ObservableQuery that's either affected by options.updateCache or listed in options.include (or both).If onQueryUpdated is not provided, the default implementation returns the result of calling observableQuery.refetch(). When onQueryUpdated is provided, it can dynamically decide whether (and how) each query should be refetched.Returning false from onQueryUpdated prevents the associated query from being refetched.
optimistic
boolean
If true, the options.updateCache function is executed on a temporary optimistic layer of InMemoryCache, so its modifications can be discarded from the cache after observing which fields it invalidated.Defaults to false, meaning options.updateCache updates the cache in a lasting way.

Refetch results

The client.refetchQueries method collects the TResult results returned by onQueryUpdated, defaulting to TResult = Promise<ApolloQueryResult<any>> if onQueryUpdated is not provided. It combines those results into a single Promise<TResolved[]> using Promise.all(results).

Thanks to the Promise-unwrapping behavior of Promise.all, this TResolved type is often the same type as TResult, except when TResult is a PromiseLike<TResolved> or a boolean.

The returned Promise object has two other useful properties:

Name /
Type
Description
queries
ObservableQuery[]
An array of ObservableQuery objects that were refetched.
results
TResult[]
An array of results that were either returned by onQueryUpdated, or provided by default in the absence of onQueryUpdated, including pending promises.If onQueryUpdated returns false for a given query, no result is provided for that query.If onQueryUpdated returns true, the resulting Promise<ApolloQueryResult<any>> is included in the results array instead of true.

These two arrays parallel each other: they have the same length, and results[i] is the result produced by onQueryUpdated when called with the ObservableQuery found at queries[i], for any index i.

Refetch recipes

Refetching a specific query

To refetch a specific query by name, use the include option by itself:

TypeScript
1await client.refetchQueries({
2  include: ["SomeQueryName"],
3});

The include option can also refetch a specific query using its DocumentNode:

TypeScript
1await client.refetchQueries({
2  include: [SOME_QUERY],
3});

Refetching all queries

To refetch all active queries, pass the "active" shorthand for include:

TypeScript
1await client.refetchQueries({
2  include: "active",
3});

To refetch all queries managed by Apollo Client (even those with no observers, or whose components are currently unmounted), pass "all" for include:

TypeScript
1await client.refetchQueries({
2  include: "all", // Consider using "active" instead!
3});

Refetching queries affected by cache updates

You can refetch queries affected by cache updates performed in the updateCache callback:

TypeScript
1await client.refetchQueries({
2  updateCache(cache) {
3    cache.evict({ fieldName: "someRootField" });
4  },
5});

This refetches any queries that depend on Query.someRootField, without requiring you to know in advance which queries might be included. Any combination of cache operations (writeQuery, writeFragment, modify, evict, etc.) is allowed within updateCache.

Updates performed by updateCache persist in the cache by default. You can perform them in a temporary optimistic layer instead, if you want them to be discarded immediately after client.refetchQueries is done observing them, leaving the cache unchanged:

TypeScript
1await client.refetchQueries({
2  updateCache(cache) {
3    cache.evict({ fieldName: "someRootField" });
4  },
5
6  // Evict Query.someRootField only temporarily, in an optimistic layer.
7  optimistic: true,
8});

Another way to "update" the cache without actually changing cache data is to use cache.modify and its INVALIDATE sentinel object:

TypeScript
1await client.refetchQueries({
2  updateCache(cache) {
3    cache.modify({
4      fields: {
5        someRootField(value, { INVALIDATE }) {
6          // Update queries that involve Query.someRootField, without actually
7          // changing its value in the cache.
8          return INVALIDATE;
9        },
10      },
11    });
12  },
13});

Before client.refetchQueries was introduced, the INVALIDATE sentinel was not very useful, because invalidated queries with fetchPolicy: "cache-first" would typically re-read unchanged results, and therefore decide not to perform a network request. The client.refetchQueries method makes this invalidation system more accessible to application code, so you can control the refetching behavior of invalidated queries.

In all of the examples above, whether we use include or updateCache, client.refetchQueries refetches affected queries from the network and includes the resulting Promise<ApolloQueryResult<any>> results in the Promise<TResolved[]> returned by client.refetchQueries.

If a particular query is included both by include and by updateCache, that query is refetched only once. In other words, the include option is a good way to make sure certain queries are always included, no matter which queries are included by updateCache.

Refetching selectively

In development, you probably want to make sure the appropriate queries are getting refetched, rather than blindly refetching them. To intercept each query before refetching, you can specify an onQueryUpdated callback:

TypeScript
1const results = await client.refetchQueries({
2  updateCache(cache) {
3    cache.evict({ fieldName: "someRootField" });
4  },
5
6  onQueryUpdated(observableQuery) {
7    // Logging and/or debugger breakpoints can be useful in development to
8    // understand what client.refetchQueries is doing.
9    console.log(`Examining ObservableQuery ${observableQuery.queryName}`);
10    debugger;
11
12    // Proceed with the default refetching behavior, as if onQueryUpdated
13    // was not provided.
14    return true;
15  },
16});
17
18results.forEach(result => {
19  // These results will be ApolloQueryResult<any> objects, after all
20  // results have been refetched from the network.
21});

Notice how adding onQueryUpdated in this example did not change the refetching behavior of client.refetchQueries, allowing us to use onQueryUpdated purely for diagnostic or debugging purposes.

If you want to skip certain queries that would otherwise be included, return false from onQueryUpdated:

TypeScript
1await client.refetchQueries({
2  updateCache(cache) {
3    cache.evict({ fieldName: "someRootField" });
4  },
5
6  onQueryUpdated(observableQuery, { complete, result, missing }) {
7    console.log(`Examining ObservableQuery ${
8      observableQuery.queryName
9    } whose latest result is ${JSON.stringify(result)} which is ${
10      complete ? "complete" : "incomplete"
11    }`);
12
13    if (shouldIgnoreQuery(observableQuery)) {
14      return false;
15    }
16
17    // Refetch the query unconditionally from the network.
18    return true;
19  },
20});

In case the ObservableQuery does not provide enough information, you can also examine the latest result for the query, along with information about its completeness and missing fields, using the Cache.DiffResult object passed as the second parameter to onQueryUpdated:

TypeScript
1await client.refetchQueries({
2  updateCache(cache) {
3    cache.evict({ fieldName: "someRootField" });
4  },
5
6  onQueryUpdated(observableQuery, { complete, result, missing }) {
7    if (shouldIgnoreQuery(observableQuery)) {
8      return false;
9    }
10
11    if (complete) {
12      // Update the query according to its chosen FetchPolicy, rather than
13      // refetching it unconditionally from the network.
14      return observableQuery.reobserve();
15    }
16
17    // Refetch the query unconditionally from the network.
18    return true;
19  },
20});

Because onQueryUpdated has the ability to filter queries dynamically, it also pairs well with the bulk include options mentioned above:

TypeScript
1await client.refetchQueries({
2  // Include all active queries by default, which may be ill-advised unless
3  // you also use onQueryUpdated to filter those queries.
4  include: "active";
5
6  // Called once for every active query, allowing dynamic filtering:
7  onQueryUpdated(observableQuery) {
8    return !shouldIgnoreQuery(observableQuery);
9  },
10});

Handling refetch errors

In the examples above, we await client.refetchQueries(...) to find out the final ApolloQueryResult<any> results for all the refetched queries. This combined promise is created with Promise.all, so a single failure rejects the entire Promise<TResolved[]>, potentially hiding other successful results. If this is a problem, you can use the queries and results arrays returned by client.refetchQueries instead of (or in addition to) awaiting the Promise:

TypeScript
1const { queries, results } = client.refetchQueries({
2  // Specific client.refetchQueries options are not relevant to this example.
3});
4
5const finalResults = await Promise.all(
6  results.map((result, i) => {
7    return Promise.resolve(result).catch(error => {
8      console.error(`Error refetching query ${queries[i].queryName}: ${error}`);
9      return null; // Silence this Promise rejection.
10    });
11  })
12});

In the future, just as additional input options may be added to the client.refetchQueries method, additional properties may be added to its result object, supplementing its Promise-related properties and the queries and results arrays.

If you discover that some specific additional client.refetchQueries input options or result properties would be useful, please feel free to open an issue or start a discussion explaining your use case(s).

Corresponding client.mutate options

For refetching after a mutation, client.mutate supports options similar to client.refetchQueries, which you should use instead of client.refetchQueries, because it's important for refetching logic to happen at specific times during the mutation process.

For historical reasons, client.mutate options have slightly different names from the new client.refetchQueries options, but their internal implementation is substantially the same, so you can translate between them using the following table:

client.mutate(options)client.refetchQueries(options)
options.refetchQueries?options.include
options.update?options.updateCache
options.onQueryUpdated?options.onQueryUpdated
options.awaitRefetchQueries?Return a Promise from onQueryUpdated
四不像是指什么动物 手心痒是什么原因 什么泡水喝可降血压 翠字五行属什么 长宽高用什么字母表示
自怨自艾是什么意思 special是什么意思 学籍卡是什么样子图片 克卜勒是什么意思 梦到乌龟是什么意思
肠胃出血有什么症状 抖腿有什么好处 阴历七月是什么星座 什么茶下火 一加一笔变成什么字
橙字五行属什么 食道好像有东西堵着是什么原因 南昌有什么特产 切花是什么意思 绿色心情是什么意思
人格魅力是什么意思hanqikai.com 什么哲理hcv8jop4ns5r.cn 6月6号是什么日子hcv8jop5ns0r.cn 平的反义词是什么onlinewuye.com 品相是什么意思hcv8jop2ns1r.cn
成吉思汗什么意思hcv9jop2ns8r.cn 胎脂是什么原因造成的hcv9jop0ns5r.cn 小儿厌食吃什么药最好hcv9jop2ns0r.cn 在什么后面hcv8jop1ns8r.cn 青枝骨折是什么意思hcv7jop5ns1r.cn
蓝柑是什么水果hcv8jop1ns4r.cn 牙发黑是什么原因怎么办hcv7jop7ns0r.cn 黄五行属性是什么hcv8jop4ns6r.cn 阳虚和阴虚有什么区别hcv8jop8ns2r.cn 上升星座是什么意思hcv8jop6ns4r.cn
引火上身是什么意思hcv7jop9ns1r.cn 灵芝泡水喝有什么好处hcv8jop5ns0r.cn 什么叫npchcv8jop1ns4r.cn 荷花五行属什么96micro.com 早年晚岁总无长是什么意思hcv9jop2ns2r.cn
百度