Description
GraphQL has unfortunate name overloading. I will call:
- “A schema” is a collection of type system definitions, typically parsed from one or more
TypeSystemExtensionDocument
- “A schema definition“ is the syntax element
SchemaDefinition
that starts with theschema
keyword
Spec divination
SchemaExtension
starts with the extend schema
keywords and has validation rules:
Schema extensions have the potential to be invalid if incorrectly defined.
- The Schema must already be defined.
- […]
“Schema” in the first rule is capitalized but not a link. My interpretation of this rule is: a SchemaDefinition
must exist.
Separately, Default Root Operation Type Names specifies:
While any type can be the root operation type for a GraphQL operation, the type system definition language can omit the schema definition when the query, mutation, and subscription root types are named
"Query"
,"Mutation"
, and"Subscription"
respectively.Likewise, when representing a GraphQL schema using the type system definition language, a schema definition should be omitted if it only uses the default root operation type names.
Unfortunately this is written from the point of view of SDL authors (or authoring tools), and only suggests by implication what’s expected of tools reading SDL. My interpretation is: in the absence of a SchemaDefinition
, root operations are defined based on which type Query {…}
, type Mutation {…}
, or type Subscription {…}
are defined.
1.0 beta 1 behavior
Based on the above, I implemented apollo-compiler 1.0.0-beta.1 such that:
Schema::schema_definition
is anOption
, set toSome
ifSchemaDefinition
exists. It contains stuff from thatSchemaDefinition
and anySchemaExtension
- The
Schema::root_operation
method looks either atschema_definition
if it’sSome
, or at which object types exist if it’sNone
Test case
type Query { field: Int }
extend schema @someDirective
directive @someDirective on SCHEMA
1.0.0-beta.1 records an error for extend schema
without a schema
definition, and sets Schema::schema_definition
to None
. The extension and its directive application are ignored.
Reportedly, the behavior of some other tools is that type Query
creates a sort of implicit schema definition, which means that "the schema is defined" for the purpose of extend schema
validation, so the extension and its directive application are accounted for.
What behavior do we want?