You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apollo Link State中__typename取值规则?Todo示例值来源解析

Let's break down your questions clearly and concisely:

Where does the TodoItem value come from?

The TodoItem here is a custom local type name you define in your Apollo Link State schema.

In the Todo example, you must have declared a type named TodoItem in the local schema when setting up clientState (Apollo Link State's core configuration). It would look something like this:

type TodoItem {
  id: ID!
  text: String!
  completed: Boolean!
}

This type defines the structure of your local todo items. When creating a new todo object in the resolver, you specify __typename: "TodoItem" to tell Apollo Client exactly which local type this object corresponds to.

Can this value be set arbitrarily, or are there specific requirements?

You cannot set this value arbitrarily—it has strict rules to follow:

  • It must exactly match the name of the type you defined in your local schema. Apollo Client uses __typename to normalize data in its cache and resolve fields correctly. If the name doesn't match, the cache won't recognize the object, leading to issues like missing data or failed queries.
  • If you're combining local state with a remote GraphQL API, avoid naming conflicts with remote type names unless you intentionally want to reuse a remote type (in which case the __typename must match the remote type's name exactly).
  • __typename is a core identifier for Apollo Client's cache system. Using an incorrect or random value will break cache normalization and cause unexpected behavior, such as null results when querying local state or mismatched field resolutions.

内容的提问来源于stack exchange,提问作者deadcoder0904

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:16:15