Closed
Description
Some AST node types, such as the UnionTypeDefinitionNode
and the EnumTypeDefinitionNode
, have annotations that say their fields/values are optional. For instance, UnionTypeDefinitionNode
has an optional frozenlist for the types that the union contains. However, according to the GraphQL spec, unions have to contain at least one unique member type, so it doesn't seem like the list would ever be None
. Is there a case that I've missed?
Metadata
Metadata
Assignees
Labels
No labels
Activity
Cito commentedon Jun 25, 2020
Good question, @LWprogramming. The simple answer is that GraphQL-core is just a port of GraphQL.js where these are defined as optional in Flow and TypeScript. But the reason for that is not obvious to me either.
Generally, the Node types are more relaxed because you want to be able to parse invalid documents, and then let the validator complain about violation of the specs. So the parser would parse
union x
as a Node with an empty types list.However, I think you're right in that the types should never be
None
. Also, it looks like the GraphQL spec validation rules are not enforced except that GraphQL-Core (but not GraphQL.js) checks that the member types of the union have the right types when building the GraphQLUnion (similar for the value of Enums). But uniqueness and not-emptyness are not checked.I have passed on these questions to the GraphQL.js issue tracker now.
Lists in AST nodes should not be optional (#98)
Cito commentedon Jul 5, 2020
After discussion there, the questions above can be answered as follows:
type.validate_schema()
, but this is only happens when a schema is executed viagraphql()
orgraphql_sync()
. This will probably changed in future versions of GraphQL.js, separating schema validation from query execution.None
.Remove null check
Implement type/union suppression (#859)