graphql / graphql-spec

GraphQL is a query language and execution engine tied to any backend service.
https://spec.graphql.org
14.31k stars 1.12k forks source link

[Validation] "root types exist" should be a formal validation #218

Open rmosolgo opened 8 years ago

rmosolgo commented 8 years ago

A GraphQL schema must have a query root, but mutation and subscription roots are optional. If a schema doesn't have a mutation root, mutation operations are invalid. Same for subscription: if there's no subscription root type, we should reject a document with an operation on subscription.

We have this validation in graphql-ruby now (thanks @cjoudrey) but we didn't at first, because I was literally reading the spec and implementing the rules one-by-one.

Should that rule be in the spec? If so, I'm happy to try writing up (I think I have a bow tie around here somewhere 😆 ).

stubailo commented 8 years ago

As a side note I think it's reasonable to have a server with only mutation or subscription types, I'm not sure why Query is singled out as being required.

rwe commented 7 years ago

Agreed. We've been bitten by this when exposing mutation-only schemas for backend services. The workaround is to create an empty query type, but I'm not sure what the rationale is for that to be explicitly required unlike mutationType or subscriptionType. Does queryType have any other special characteristics?

To be clear, the issue at hand is the non-nullability of the queryType field in the Introspection schema: