Skip to main content

Make root query operation type optional

At a glance​

Timeline​


This change would make the root query operation type optional, consistent with mutation and subscription. 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 just mutation or subscription. This becomes especially apparent for micro services. Such services are forced to expose dummy query fields, with real world examples such as _, version, helloWorld, or dontQueryMe.

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 in schema { 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).