Skip to content

Commit e736f78

Browse files
authored
Add a style guide to the specification (#1003)
1 parent e407b57 commit e736f78

5 files changed

+80
-23
lines changed

STYLE_GUIDE.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
**This document is a work in progress.**
2+
3+
# GraphQL Specification Style Guide
4+
5+
This document outlines the styles used in the GraphQL spec to aid editorial and
6+
consistency. The writing style portions are inspired by the AP style guide. When
7+
making changes to the GraphQL specification, please aim to be consistent with
8+
this style guide.
9+
10+
## Auto-Formatting
11+
12+
The GraphQL specification is formatted using the `prettier` tool, so you should
13+
not need to think about gaps between paragraphs and titles, nor about word
14+
wrapping - this is handled for you.
15+
16+
## Headings
17+
18+
The GraphQL specification uses two types of headings: numbered headings and
19+
unnumbered headings. All headings should be written in Title Case (see below).
20+
21+
### Numbered Headings
22+
23+
Lines beginning with a `#` will become numbered headings in the spec-md output.
24+
25+
```
26+
# H1
27+
## H2
28+
### H3
29+
#### H4
30+
##### H5
31+
```
32+
33+
### Unnumbered Headings
34+
35+
Unnumbered headings are added to split large blocks of text up without impacting
36+
the spec numbering system. In the output are styled similarly to an H4. An
37+
unnumbered heading is a line on its own that is bolded:
38+
39+
```md
40+
\*\*This Is an Example of an Unnumbered Heading\*\*
41+
```
42+
43+
### Title Case
44+
45+
Title case is used for headings. Every word in a heading (including words after
46+
hyphens) should be capitalized, with the following exceptions:
47+
48+
- articles: a, an, the
49+
- conjunctions under 4 letters in length: for, and, nor, but, or, yet, so, as,
50+
if
51+
- prepositions under 4 letters in length: in, at, to, on, off, of, for, vs., per
52+
- directive names and type names are unchanged: @include, @specifiedBy,
53+
\_\_EnumValue, \_\_Schema
54+
55+
All elements in hyphenated words follow the same rules, e.g. headings may
56+
contain `Non-Null`, `Context-Free`, `Built-in` (`in` is a preposition, so is not
57+
capitalized).

spec/GraphQL.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ specification can be found at permalinks that match their
2626
working draft release can be found at
2727
[https://spec.graphql.org/draft](https://spec.graphql.org/draft).
2828

29-
**Copyright notice**
29+
**Copyright Notice**
3030

3131
Copyright © 2015-2018, Facebook, Inc.
3232

spec/Section 2 -- Language.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ significant way, for example a {StringValue} may contain white space characters.
164164
No {Ignored} may appear _within_ a {Token}, for example no white space
165165
characters are permitted between the characters defining a {FloatValue}.
166166

167-
**Byte order mark**
167+
**Byte Order Mark**
168168

169169
UnicodeBOM :: "Byte Order Mark (U+FEFF)"
170170

@@ -306,7 +306,7 @@ mutation {
306306
}
307307
```
308308

309-
**Query shorthand**
309+
**Query Shorthand**
310310

311311
If a document contains only one operation and that operation is a query which
312312
defines no variables and has no directives applied to it then that operation may
@@ -439,7 +439,7 @@ Many arguments can exist for a given field:
439439
}
440440
```
441441

442-
**Arguments are unordered**
442+
**Arguments Are Unordered**
443443

444444
Arguments may be provided in any syntactic order and maintain identical semantic
445445
meaning.
@@ -1130,7 +1130,7 @@ curly-braces `{ }`. The values of an object literal may be any input value
11301130
literal or variable (ex. `{ name: "Hello world", score: 1.0 }`). We refer to
11311131
literal representation of input objects as "object literals."
11321132

1133-
**Input object fields are unordered**
1133+
**Input Object Fields Are Unordered**
11341134

11351135
Input object fields may be provided in any syntactic order and maintain
11361136
identical semantic meaning.
@@ -1207,7 +1207,7 @@ size `60`:
12071207
}
12081208
```
12091209

1210-
**Variable use within Fragments**
1210+
**Variable Use Within Fragments**
12111211

12121212
Variables can be used within fragments. Variables have global scope with a given
12131213
operation, so a variable used within a fragment must be declared in any
@@ -1282,7 +1282,7 @@ As future versions of GraphQL adopt new configurable execution capabilities,
12821282
they may be exposed via directives. GraphQL services and tools may also provide
12831283
any additional _custom directive_ beyond those described here.
12841284

1285-
**Directive order is significant**
1285+
**Directive Order Is Significant**
12861286

12871287
Directives may be provided in a specific syntactic order which may have semantic
12881288
interpretation.

spec/Section 5 -- Validation.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ or development-time tool should report validation errors and not allow the
1919
formulation or execution of requests known to be invalid at that given point in
2020
time.
2121

22-
**Type system evolution**
22+
**Type System Evolution**
2323

2424
As GraphQL type system schema evolves over time by adding new types and new
2525
fields, it is possible that a request which was previously valid could later
@@ -251,7 +251,7 @@ query getName {
251251

252252
### Subscription Operation Definitions
253253

254-
#### Single root field
254+
#### Single Root Field
255255

256256
**Formal Specification**
257257

@@ -910,7 +910,7 @@ fragment inlineNotExistingType on Dog {
910910
}
911911
```
912912

913-
#### Fragments On Composite Types
913+
#### Fragments on Composite Types
914914

915915
**Formal Specification**
916916

@@ -987,7 +987,7 @@ Field selection is also determined by spreading fragments into one another. The
987987
selection set of the target fragment is combined into the selection set at the
988988
level at which the target fragment is referenced.
989989

990-
#### Fragment spread target defined
990+
#### Fragment Spread Target Defined
991991

992992
**Formal Specification**
993993

@@ -1008,7 +1008,7 @@ is a validation error if the target of a spread is not defined.
10081008
}
10091009
```
10101010

1011-
#### Fragment spreads must not form cycles
1011+
#### Fragment Spreads Must Not Form Cycles
10121012

10131013
**Formal Specification**
10141014

@@ -1093,7 +1093,7 @@ fragment ownerFragment on Human {
10931093
}
10941094
```
10951095

1096-
#### Fragment spread is possible
1096+
#### Fragment Spread Is Possible
10971097

10981098
**Formal Specification**
10991099

@@ -1118,7 +1118,7 @@ type matches the type condition. They also are spread within the context of a
11181118
parent type. A fragment spread is only valid if its type condition could ever
11191119
apply within the parent type.
11201120

1121-
##### Object Spreads In Object Scope
1121+
##### Object Spreads in Object Scope
11221122

11231123
In the scope of an object type, the only valid object type fragment spread is
11241124
one that applies to the same type that is in scope.
@@ -1181,7 +1181,7 @@ that if one inspected the contents of the {CatOrDogNameFragment} you could note
11811181
that no valid results would ever be returned. However we do not specify this as
11821182
invalid because we only consider the fragment declaration, not its body.
11831183

1184-
##### Object Spreads In Abstract Scope
1184+
##### Object Spreads in Abstract Scope
11851185

11861186
Union or interface spreads can be used within the context of an object type
11871187
fragment, but only if the object type is one of the possible types of that
@@ -1266,7 +1266,7 @@ fragment sentientFragment on Sentient {
12661266
is not valid because there exists no type that implements both {Pet} and
12671267
{Sentient}.
12681268

1269-
**Interface Spreads in implemented Interface Scope**
1269+
**Interface Spreads in Implemented Interface Scope**
12701270

12711271
Additionally, an interface type fragment can always be spread into an interface
12721272
scope which it implements.
@@ -1447,7 +1447,7 @@ input object field is optional.
14471447
GraphQL services define what directives they support. For each usage of a
14481448
directive, the directive must be available on that service.
14491449

1450-
### Directives Are In Valid Locations
1450+
### Directives Are in Valid Locations
14511451

14521452
**Formal Specification**
14531453

@@ -1473,7 +1473,7 @@ query @skip(if: $foo) {
14731473
}
14741474
```
14751475

1476-
### Directives Are Unique Per Location
1476+
### Directives Are Unique per Location
14771477

14781478
**Formal Specification**
14791479

@@ -1853,7 +1853,7 @@ fragment isHouseTrainedFragment on Dog {
18531853
This document is not valid because {queryWithExtraVar} defines an extraneous
18541854
variable.
18551855

1856-
### All Variable Usages are Allowed
1856+
### All Variable Usages Are Allowed
18571857

18581858
**Formal Specification**
18591859

@@ -1971,7 +1971,7 @@ query listToNonNullList($booleanList: [Boolean]) {
19711971
This would fail validation because a `[T]` cannot be passed to a `[T]!`.
19721972
Similarly a `[T]` cannot be passed to a `[T!]`.
19731973

1974-
**Allowing optional variables when default values exist**
1974+
**Allowing Optional Variables When Default Values Exist**
19751975

19761976
A notable exception to typical variable type compatibility is allowing a
19771977
variable definition with a nullable type to be provided to a non-null location

spec/Section 7 -- Response.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ If the `data` entry in the response is present (including if it is the value
6666
{null}), the `errors` entry must be present if and only if one or more _field
6767
error_ was raised during execution.
6868

69-
**Request errors**
69+
**Request Errors**
7070

7171
:: A _request error_ is an error raised during a _request_ which results in no
7272
response data. Typically raised before execution begins, a request error may
@@ -79,7 +79,7 @@ If a request error is raised, the `data` entry in the response must not be
7979
present, the `errors` entry must include the error, and request execution should
8080
be halted.
8181

82-
**Field errors**
82+
**Field Errors**
8383

8484
:: A _field error_ is an error raised during the execution of a particular field
8585
which results in partial response data. This may occur due to an internal error
@@ -92,7 +92,7 @@ is produced (see [Handling Field Errors](#sec-Handling-Field-Errors)). The
9292
`data` entry in the response must be present. The `errors` entry should include
9393
this error.
9494

95-
**Error result format**
95+
**Error Result Format**
9696

9797
Every error must contain an entry with the key `message` with a string
9898
description of the error intended for the developer as a guide to understand and

0 commit comments

Comments
 (0)