Skip to content

Commit debcdc3

Browse files
sungam3rleebyron
andauthored
Improve clarity of built-in directives (#633)
* Improve clarity of standard directives * can be -> should be * should -> can * formatting * merge notes about standard directives to **built-in directives** * typo * review * Move built-in section above custom section * Generalize message and repeat in introspection section * Use term definitions * Apply suggestions from code review Co-authored-by: Ivan Maximov <[email protected]> * may omit built-ins for brevity Co-authored-by: Lee Byron <[email protected]> Co-authored-by: Lee Byron <[email protected]>
1 parent 6c81ed8 commit debcdc3

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

spec/Section 2 -- Language.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,7 @@ fragments and operations.
11951195

11961196
As future versions of GraphQL adopt new configurable execution capabilities,
11971197
they may be exposed via directives. GraphQL services and tools may also provide
1198-
additional [custom directives](#sec-Type-System.Directives.Custom-Directives)
1199-
beyond those described here.
1198+
any additional *custom directive* beyond those described here.
12001199

12011200
**Directive order is significant**
12021201

spec/Section 3 -- Type System.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,10 @@ A GraphQL schema describes directives which are used to annotate various parts
18751875
of a GraphQL document as an indicator that they should be evaluated differently
18761876
by a validator, executor, or client tool such as a code generator.
18771877

1878+
**Built-in Directives**
1879+
1880+
:: A *built-in directive* is any directive defined within this specification.
1881+
18781882
GraphQL implementations should provide the `@skip` and `@include` directives.
18791883

18801884
GraphQL implementations that support the type system definition language must
@@ -1885,23 +1889,25 @@ GraphQL implementations that support the type system definition language should
18851889
provide the `@specifiedBy` directive if representing custom scalar
18861890
definitions.
18871891

1888-
When representing a GraphQL schema using the type system definition language,
1889-
built in directives (any defined in this specification) should be omitted for
1890-
brevity. Custom directives in use must be specified.
1892+
When representing a GraphQL schema using the type system definition language
1893+
any *built-in directive* may be omitted for brevity.
1894+
1895+
When introspecting a GraphQL service all provided directives, including
1896+
any *built-in directive*, must be included in the set of returned directives.
18911897

18921898
**Custom Directives**
18931899

1894-
GraphQL services and client tooling may provide additional directives beyond
1895-
those defined in this document. Directives are the preferred way to extend
1896-
GraphQL with custom or experimental behavior.
1897-
1898-
Note: When defining a directive, it is recommended to prefix the directive's
1899-
name to make its scope of usage clear and to prevent a collision with directives
1900-
which may be specified by future versions of this document (which will not
1901-
include `_` in their name). For example, a custom directive used by Facebook's
1902-
GraphQL service should be named `@fb_auth` instead of `@auth`. This is
1903-
especially recommended for proposed additions to this specification which can
1904-
change during the [RFC process](https://github.com/graphql/graphql-spec/blob/main/CONTRIBUTING.md).
1900+
:: GraphQL services and client tooling may provide any additional
1901+
*custom directive* beyond those defined in this document. Directives are the
1902+
preferred way to extend GraphQL with custom or experimental behavior.
1903+
1904+
Note: When defining a *custom directive*, it is recommended to prefix the
1905+
directive's name to make its scope of usage clear and to prevent a collision
1906+
with *built-in directive* which may be specified by future versions of this
1907+
document (which will not include `_` in their name). For example, a
1908+
*custom directive* used by Facebook's GraphQL service should be named `@fb_auth`
1909+
instead of `@auth`. This is especially recommended for proposed additions to
1910+
this specification which can change during the [RFC process](https://github.com/graphql/graphql-spec/blob/main/CONTRIBUTING.md).
19051911
For example a work in progress version of `@live` should be named `@rfc_live`.
19061912

19071913
Directives must only be used in the locations they are declared to belong in.
@@ -1986,9 +1992,9 @@ repeatable directives.
19861992
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
19871993
```
19881994

1989-
The `@skip` directive may be provided for fields, fragment spreads, and
1990-
inline fragments, and allows for conditional exclusion during execution as
1991-
described by the if argument.
1995+
The `@skip` *built-in directive* may be provided for fields, fragment spreads,
1996+
and inline fragments, and allows for conditional exclusion during execution as
1997+
described by the `if` argument.
19921998

19931999
In this example `experimentalField` will only be queried if the variable
19942000
`$someTest` has the value `false`.
@@ -2006,9 +2012,9 @@ query myQuery($someTest: Boolean!) {
20062012
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
20072013
```
20082014

2009-
The `@include` directive may be provided for fields, fragment spreads, and
2010-
inline fragments, and allows for conditional inclusion during execution as
2011-
described by the if argument.
2015+
The `@include` *built-in directive* may be provided for fields, fragment
2016+
spreads, and inline fragments, and allows for conditional inclusion during
2017+
execution as described by the `if` argument.
20122018

20132019
In this example `experimentalField` will only be queried if the variable
20142020
`$someTest` has the value `true`
@@ -2035,8 +2041,8 @@ directive @deprecated(
20352041
) on FIELD_DEFINITION | ENUM_VALUE
20362042
```
20372043

2038-
The `@deprecated` directive is used within the type system definition language
2039-
to indicate deprecated portions of a GraphQL service's schema, such as
2044+
The `@deprecated` *built-in directive* is used within the type system definition
2045+
language to indicate deprecated portions of a GraphQL service's schema, such as
20402046
deprecated fields on a type or deprecated enum values.
20412047

20422048
Deprecations include a reason for why it is deprecated, which is formatted using
@@ -2059,10 +2065,10 @@ type ExampleType {
20592065
directive @specifiedBy(url: String!) on SCALAR
20602066
```
20612067

2062-
The `@specifiedBy` directive is used within the type system definition language
2063-
to provide a *scalar specification URL* for specifying the behavior of
2064-
[custom scalar types](#sec-Scalars.Custom-Scalars). The URL should point to a
2065-
human-readable specification of the data format, serialization, and
2068+
The `@specifiedBy` *built-in directive* is used within the type system
2069+
definition language to provide a *scalar specification URL* for specifying the
2070+
behavior of [custom scalar types](#sec-Scalars.Custom-Scalars). The URL should
2071+
point to a human-readable specification of the data format, serialization, and
20662072
coercion rules. It must not appear on built-in scalar types.
20672073

20682074
In this example, a custom scalar type for `UUID` is defined with a URL pointing

spec/Section 4 -- Introspection.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ Fields
429429

430430
### The __Directive Type
431431

432-
The `__Directive` type represents a Directive that a service supports.
432+
The `__Directive` type represents any Directive that a service supports.
433+
434+
This includes both any *built-in directive* and any *custom directive*.
433435

434436
Fields
435437

0 commit comments

Comments
 (0)