Make root query operation type optional
At a glance​
- Identifier: #631
- Stage: RFC0: Strawman
- Champion: @victorandree
- PR: Make root query operation type optional
Timeline​
- Added to 2019-12-05 WG agenda
- Mentioned in 2019-12-05 WG notes
- Spec PR created on 2019-10-23 by victorandree
- Commit pushed: Make root query operation type optional on 2019-10-11 by @victorandree
This change would make the root
query
operation type optional, consistent withmutation
andsubscription
. In this proposal, schema introspection would still work as before, by allowing a "default"query
type if one is not defined, exposing only the implicit fields__schema
and__types
(in response to PR feedback).The change is worded so that a "schema must define at least one root operation type.". See below for motivation and alternatives.
See #490 for background on this issue.
Motivation​
Not all GraphQL APIs need a
query
interface but do fine with justmutation
orsubscription
. This becomes especially apparent for micro services. Such services are forced to expose dummy query fields, with real world examples such as_
,version
,helloWorld
, ordontQueryMe
.Alternative: Allow root query operation type to be empty​
Instead of making the root
query
operation type optional, it can be allowed to not have any fields.This has already been proposed (see #606), but would have wider impacts than just making
query
optional. A benefit of this approach is that schema introspection wouldn't need any new treatment.Allowing for only the query root, or others, to be empty would require​ validating that type in the context of how it's used, which seems strange to me (e.g. if a type is only allowed to be empty if it's called
Query
or is used inschema { query: Query }
).Alternative: Don't require​ any root type​
A schema which only defines types without any operations could be useful in some scenarios, where a schema in service A is perhaps stitched or used as the basis for another. To support this, one could drop the requirement "A schema must define at least one root operation type."
I think this would be esoteric and counter to existing requirements enforcing a "useful" schema (for example requiring composite types not to be empty).