Skip to content

Add Appendix C - Specified Type System Definitions #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
"suggest:format": "echo \"\nTo resolve this, run: $(tput bold)npm run format$(tput sgr0)\" && exit 1",
"build": "./build.sh",
"test:build": "spec-md --metadata spec/metadata.json spec/GraphQL.md > /dev/null",
"watch": "nodemon -e json,md --exec \"npm run build\""
"watch": "nodemon -e json,md --exec \"npm run build\"",
"update-appendix-c": "node scripts/update-appendix-c.mjs; prettier --write \"spec/Appendix C -- Built-in Definitions.md\""
},
"devDependencies": {
"cspell": "5.9.1",
"nodemon": "2.0.20",
"prettier": "2.8.2",
"spec-md": "3.1.0"
"spec-md": "3.1.0",
"graphql": "^17.0.0-alpha.8"
},
"prettier": {
"proseWrap": "always",
Expand Down
22 changes: 22 additions & 0 deletions scripts/update-appendix-c.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { writeFile } from 'node:fs/promises';
import { printIntrospectionSchema, buildSchema } from 'graphql';

const FILE = './spec/Appendix C -- Built-in Definitions.md';

const sdl = printIntrospectionSchema(buildSchema(`type Query { i: Int }`));
const prefix = `
# C. Appendix: Type System Definitions

This appendix lists all the type system definitions mentioned throughout this
specification.

The descriptions are non-normative. Implementations are recommended to use them
for consistency but different descriptions are allowed.

\`\`\`graphql
`

const suffix = `
\`\`\`
`
await writeFile(FILE, prefix + sdl + suffix);
306 changes: 306 additions & 0 deletions spec/Appendix C -- Built-in Definitions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
# C. Appendix: Type System Definitions

This appendix lists all the type system definitions mentioned throughout this
specification.

The descriptions are non-normative. Implementations are recommended to use them
for consistency but different descriptions are allowed.

```graphql
"""
Directs the executor to include this field or fragment only when the `if` argument is true.
"""
directive @include(
"""
Included when true.
"""
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"""
Directs the executor to skip this field or fragment when the `if` argument is true.
"""
directive @skip(
"""
Skipped when true.
"""
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"""
Marks an element of a GraphQL schema as no longer supported.
"""
directive @deprecated(
"""
Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
"""
reason: String! = "No longer supported"
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE

"""
Exposes a URL that specifies the behavior of this scalar.
"""
directive @specifiedBy(
"""
The URL that specifies the behavior of this scalar.
"""
url: String!
) on SCALAR

"""
Indicates exactly one field must be supplied and this field must not be `null`.
"""
directive @oneOf on INPUT_OBJECT

"""
A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.
"""
type __Schema {
description: String

"""
A list of all types supported by this server.
"""
types: [__Type!]!

"""
The type that query operations will be rooted at.
"""
queryType: __Type!

"""
If this server supports mutation, the type that mutation operations will be rooted at.
"""
mutationType: __Type

"""
If this server support subscription, the type that subscription operations will be rooted at.
"""
subscriptionType: __Type

"""
A list of all directives supported by this server.
"""
directives: [__Directive!]!
}

"""
The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.

Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByURL`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
"""
type __Type {
kind: __TypeKind!
name: String
description: String
specifiedByURL: String
fields(includeDeprecated: Boolean = false): [__Field!]
interfaces: [__Type!]
possibleTypes: [__Type!]
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
inputFields(includeDeprecated: Boolean = false): [__InputValue!]
ofType: __Type
isOneOf: Boolean
}

"""
An enum describing what kind of type a given `__Type` is.
"""
enum __TypeKind {
"""
Indicates this type is a scalar.
"""
SCALAR

"""
Indicates this type is an object. `fields` and `interfaces` are valid fields.
"""
OBJECT

"""
Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.
"""
INTERFACE

"""
Indicates this type is a union. `possibleTypes` is a valid field.
"""
UNION

"""
Indicates this type is an enum. `enumValues` is a valid field.
"""
ENUM

"""
Indicates this type is an input object. `inputFields` is a valid field.
"""
INPUT_OBJECT

"""
Indicates this type is a list. `ofType` is a valid field.
"""
LIST

"""
Indicates this type is a non-null. `ofType` is a valid field.
"""
NON_NULL
}

"""
Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.
"""
type __Field {
name: String!
description: String
args(includeDeprecated: Boolean = false): [__InputValue!]!
type: __Type!
isDeprecated: Boolean!
deprecationReason: String
}

"""
Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.
"""
type __InputValue {
name: String!
description: String
type: __Type!

"""
A GraphQL-formatted string representing the default value for this input value.
"""
defaultValue: String
isDeprecated: Boolean!
deprecationReason: String
}

"""
One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.
"""
type __EnumValue {
name: String!
description: String
isDeprecated: Boolean!
deprecationReason: String
}

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.

In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
"""
type __Directive {
name: String!
description: String
isRepeatable: Boolean!
locations: [__DirectiveLocation!]!
args(includeDeprecated: Boolean = false): [__InputValue!]!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maintain the order of fields in the Introspection chapter

Suggested change
isRepeatable: Boolean!
locations: [__DirectiveLocation!]!
args(includeDeprecated: Boolean = false): [__InputValue!]!
locations: [__DirectiveLocation!]!
args(includeDeprecated: Boolean = false): [__InputValue!]!
isRepeatable: Boolean!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we should re-order this in the spec, or in GraphQL-js. We should make it consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the order to match graphql-js semantic ordering instead e274c76

See graphql/graphql-js#4428 (comment) for data about why semantic ordering is probably the safe bet.

}

"""
A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
"""
enum __DirectiveLocation {
"""
Location adjacent to a query operation.
"""
QUERY

"""
Location adjacent to a mutation operation.
"""
MUTATION

"""
Location adjacent to a subscription operation.
"""
SUBSCRIPTION

"""
Location adjacent to a field.
"""
FIELD

"""
Location adjacent to a fragment definition.
"""
FRAGMENT_DEFINITION

"""
Location adjacent to a fragment spread.
"""
FRAGMENT_SPREAD

"""
Location adjacent to an inline fragment.
"""
INLINE_FRAGMENT

"""
Location adjacent to an operation variable definition.
"""
VARIABLE_DEFINITION

"""
Location adjacent to a fragment variable definition.
"""
FRAGMENT_VARIABLE_DEFINITION

"""
Location adjacent to a schema definition.
"""
SCHEMA

"""
Location adjacent to a scalar definition.
"""
SCALAR

"""
Location adjacent to an object type definition.
"""
OBJECT

"""
Location adjacent to a field definition.
"""
FIELD_DEFINITION

"""
Location adjacent to an argument definition.
"""
ARGUMENT_DEFINITION

"""
Location adjacent to an interface definition.
"""
INTERFACE

"""
Location adjacent to a union definition.
"""
UNION

"""
Location adjacent to an enum definition.
"""
ENUM

"""
Location adjacent to an enum value definition.
"""
ENUM_VALUE

"""
Location adjacent to an input object type definition.
"""
INPUT_OBJECT

"""
Location adjacent to an input object field definition.
"""
INPUT_FIELD_DEFINITION
}
```
2 changes: 2 additions & 0 deletions spec/GraphQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ Note: This is an example of a non-normative note.
# [Appendix: Notation Conventions](Appendix%20A%20--%20Notation%20Conventions.md)

# [Appendix: Grammar Summary](Appendix%20B%20--%20Grammar%20Summary.md)

# [Appendix: Builtin Definitions](Appendix%20C%20--%20Built-in%20Definitions.md)