Description
Problem
The spec, as it is currently, is ambiguous when defining how a union type should be handled when used to fulfill an interface.
An object field type is a valid sub‐type if it is an Object type and the interface field type is either an Interface type or a Union type and the object field type is a possible type of the interface field type.
Due to this, implementations of the spec do not allow the use of a union to fulfill an interface even though all members implements said interface. See issue graphql-js #1488.
Solution
A union should be considered an implementation of an interface if and only if each member type in the union implements said interface.
Examples
Consider the following schema:
type Query {
test: MyConnection
}
interface Node {
id: ID
}
interface Connection {
nodes: [Node]
}
type NodeA implements Node {
id: ID
}
type NodeB implements Node {
id: ID
}
union MyNode =
| NodeA
| NodeB
type MyConnection implements Connection {
nodes: [MyNode]
}
The above schema fails validation as MyNode
does not directly implement Node
even though all members do.
Concerns
I'm not aware of any concerns if this change was approved as it is additive and fixes an ambiguity in the spec. Existing schema would remain unaffected.
There may be issues unknown to me due to my incomplete understanding of the entire spec, so let me know if I missed anything.