graphql-spec icon indicating copy to clipboard operation
graphql-spec copied to clipboard

RFC: "Root" Types clarity → "Operation Type"

Open leebyron opened this issue 2 years ago • 2 comments

This attempts to clarify some naming conventions in the spec and makes one meaningful syntax change.

This changes SchemaDefinition to have a zero-or-more list of OperationTypeDefinition rather than one-or-more. It removes some language that refers to this "at least one" requirement as well.

Why? Because schema can be extended with SchemaExtension. This brings this into consistency with other elements of the type definition language where definitions allow providing zero items for aspects that require one at the point of schema validation. This was overlooked before since most people use the default names, but it is not required to do so, and sometimes you need to supply the schema definition for explicitness, but are within the context of a single file that is a subset of a full schema where other operation types are defined elsewhere.

Specifically, this example used to not parse, and now should:

schema {}

What has not changed is that schema are required to provide a query root type. A schema without this operation type will not pass validation, and would later need something like this to become valid:

extend schema { query: MyQueryType }

The bulk of this change edits naming of some concepts in an attempt to improve clarity:

  • Renames OperationType to OperationKind. This was already inconsistently used throughout the spec doc, but now is consistently using "kind". This avoids overloading the term "type".

  • Renames RootOperationTypeDefinition to OperationTypeDefinition. We use "root" in an overloaded way and this was redundant. This improves the text to be a well defined provider of the type for a root selection set of an operation, so this shorter name is less redundant and easier to read. This also renames "default root type name" to "default operation type name" for consistency.

  • Replaces "root field" with "root selection set". A root field is a holdover concept from a 10yr old version of GraphQL. More accurately today these are "fields on the root selection set". This makes the latter well defined. I searched for "root" to make sure it refers only to a well defined "root selection set". This our last and only remaining use of the term "root".

  • Minor editorial change where we only use a the form {`query`} when referring to the actual keyword rather than the concept

leebyron avatar Feb 09 '23 20:02 leebyron

Deploy Preview for graphql-spec-draft ready!

Name Link
Latest commit e546c74eb87b836248be8ce2235d1e0a903135d8
Latest deploy log https://app.netlify.com/sites/graphql-spec-draft/deploys/63e566a4e8ee73000833c7aa
Deploy Preview https://deploy-preview-1015--graphql-spec-draft.netlify.app/draft
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Feb 09 '23 20:02 netlify[bot]

The argument for this change has a symmetric argument for allowing empty type and interface definitions, a la:

type MyType {}
interface MyInterface {}

mjmahone avatar Mar 02 '23 18:03 mjmahone