为什么 TYPE_ADDED_TO_INTERFACE 被视为重大更改?

Why is TYPE_ADDED_TO_INTERFACE considered a breaking change?

我正在使用 GraphQL 的 Apollo Server 实现以及 Apollo 引擎,特别是检查架构差异是否包含任何重大更改的功能。我想更好地理解为什么 TYPE_ADDED_TO_INTERFACE 被认为是一个破坏性的变化,如果有人可以提供一个 graphql 查询的例子,结果会破坏?

我正在使用 apollo/2.9.0 darwin-x64 node-v10.10.0 通过 apollo service:check 命令执行架构检查。

例如,如果我有这个模式:

interface Animal {
  id: ID
}

type Dog implements Animal {
  id: ID
  favoriteToy: String
}

然后将其添加到架构中:

type Cat implements Animal {
  id: ID
}

这被认为是一个重大变化。为什么?

我可以看到,如果有人正在查询所有 Animal 个对象,并且在查询中有一个 ... on Dog 片段,他们将开始返回 Cat 个对象只有接口字段,直到它们还添加了 ... on Cat 片段。那是什么被认为是破坏?

让一个类型实现一个它以前没有实现的接口应该不会破坏现有的查询。就您的观点而言,即使省略了内联片段,结果仍然有效(如果没有选择接口字段,它们可能会导致返回空对象,但这仍然是一个有效的响应)。

但是,我可以预见这种变化会导致特定客户出现问题。比如我们在使用Apollo客户端时,经常会创建一个IntrospectionFragmentMatcher专门帮助客户端正确缓存union或者interface字段的结果

To support result validation and accurate fragment matching on unions and interfaces, a special fragment matcher called the IntrospectionFragmentMatcher can be used. If there are any changes related to union or interface types in your schema, you will have to update the fragment matcher accordingly.

换句话说,以这种方式更改架构可能会破坏客户端缓存行为。我怀疑对于执行 schema-based code-generation 的客户端,例如 apollo-android,这也可能导致一些运行时异常。