Skip to content

Commit 188cb06

Browse files
committed
Graphql formatting consistency
Fixes #50
1 parent 6832558 commit 188cb06

File tree

5 files changed

+378
-213
lines changed

5 files changed

+378
-213
lines changed

Section 2 -- Language.md

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ viewer. Some typical examples of global fields:
5959
```graphql
6060
# `me` could represent the currently logged in user.
6161
query getMe {
62-
me { /* ... */ }
62+
me {
63+
# ...
64+
}
6365
}
6466

6567
# `user` represents one of many users in a graph of data.
6668
query getZuck {
67-
user(id: 4) { /* ... */ }
69+
user(id: 4) {
70+
# ...
71+
}
6872
}
6973
```
7074

@@ -77,8 +81,8 @@ fetching data from some user object:
7781
```graphql
7882
query getZuck {
7983
user(id: 4) {
80-
id,
81-
firstName,
84+
id
85+
firstName
8286
lastName
8387
}
8488
}
@@ -90,11 +94,11 @@ nested types. All queries must specify down to scalar fields.
9094
```graphql
9195
query getZuck {
9296
user(id: 4) {
93-
id,
94-
firstName,
95-
lastName,
97+
id
98+
firstName
99+
lastName
96100
birthday {
97-
month,
101+
month
98102
day
99103
}
100104
}
@@ -114,8 +118,8 @@ specific size:
114118
```graphql
115119
{
116120
user(id: 4) {
117-
id,
118-
name,
121+
id
122+
name
119123
profilePic(size: 100)
120124
}
121125
}
@@ -126,8 +130,8 @@ Many arguments can exist for a given field:
126130
```graphql
127131
{
128132
user(id: 4) {
129-
id,
130-
name,
133+
id
134+
name
131135
profilePic(width: 100, height: 50)
132136
}
133137
}
@@ -163,9 +167,9 @@ the resulting object will not have duplicate keys:
163167
```graphql
164168
{
165169
user(id: 4) {
166-
id,
167-
name,
168-
smallPic: profilePic(size: 64),
170+
id
171+
name
172+
smallPic: profilePic(size: 64)
169173
bigPic: profilePic(size: 1024)
170174
}
171175
}
@@ -189,7 +193,7 @@ Since the top level of a query is a field, it also can be given an alias:
189193
```graphql
190194
{
191195
zuck: user(id: 4) {
192-
id,
196+
id
193197
name
194198
}
195199
}
@@ -269,8 +273,8 @@ of a particular device:
269273
```graphql
270274
query getZuckProfile($devicePicSize: Int) {
271275
user(id: 4) {
272-
id,
273-
name,
276+
id
277+
name
274278
profilePic(size: $devicePicSize)
275279
}
276280
}
@@ -299,13 +303,13 @@ as well as friends of some user:
299303
query noFragments {
300304
user(id: 4) {
301305
friends(first: 10) {
302-
id,
303-
name,
306+
id
307+
name
304308
profilePic(size: 50)
305-
},
309+
}
306310
mutualFriends(first: 10) {
307-
id,
308-
name,
311+
id
312+
name
309313
profilePic(size: 50)
310314
}
311315
}
@@ -318,14 +322,14 @@ a parent fragment or query.
318322
```graphql
319323
query withFragments {
320324
user(id: 4) {
321-
friends(first: 10) { ...friendFields },
325+
friends(first: 10) { ...friendFields }
322326
mutualFriends(first: 10) { ...friendFields }
323327
}
324328
}
325329

326330
fragment friendFields on User {
327-
id,
328-
name,
331+
id
332+
name
329333
profilePic(size: 50)
330334
}
331335
```
@@ -338,17 +342,20 @@ spreads.
338342
For example:
339343

340344
```graphql
341-
query withNestedFragments
342-
{
345+
query withNestedFragments {
343346
user(id: 4) {
344-
friends(first: 10) { ...friendFields },
345-
mutualFriends(first: 10) { ...friendFields }
347+
friends(first: 10) {
348+
...friendFields
349+
}
350+
mutualFriends(first: 10) {
351+
...friendFields
352+
}
346353
}
347354
}
348355

349356
fragment friendFields on User {
350-
id,
351-
name,
357+
id
358+
name
352359
...standardProfilePic
353360
}
354361

@@ -378,18 +385,22 @@ For example in this query on the Facebook data model:
378385
```graphql
379386
query FragmentTyping {
380387
profiles(handles: ["zuck", "cocacola"]) {
381-
handle,
382-
...userFragment,
388+
handle
389+
...userFragment
383390
...pageFragment
384391
}
385392
}
386393

387394
fragment userFragment on User {
388-
friends { count }
395+
friends {
396+
count
397+
}
389398
}
390399

391400
fragment pageFragment on Page {
392-
likers { count }
401+
likers {
402+
count
403+
}
393404
}
394405
```
395406

@@ -429,14 +440,18 @@ was demonstrated in the `query FragmentTyping` example. We could accomplish the
429440
same thing using inline fragments.
430441

431442
```graphql
432-
query InlineFragmentTyping {
443+
query inlineFragmentTyping {
433444
profiles(handles: ["zuck", "cocacola"]) {
434-
handle,
445+
handle
435446
... on User {
436-
friends { count }
437-
},
447+
friends {
448+
count
449+
}
450+
}
438451
... on Page {
439-
likers { count }
452+
likers {
453+
count
454+
}
440455
}
441456
}
442457
}
@@ -466,11 +481,11 @@ definition.
466481
For example, the following query:
467482

468483
```graphql
469-
query HasConditionalFragment($condition: Boolean) {
470-
...MaybeFragment @include(if: $condition)
484+
query hasConditionalFragment($condition: Boolean) {
485+
...maybeFragment @include(if: $condition)
471486
}
472487

473-
fragment MaybeFragment on Query {
488+
fragment maybeFragment on Query {
474489
me {
475490
name
476491
}
@@ -480,11 +495,11 @@ fragment MaybeFragment on Query {
480495
Will have identical runtime behavior as
481496

482497
```graphql
483-
query HasConditionalFragment($condition: Boolean) {
484-
...MaybeFragment
498+
query hasConditionalFragment($condition: Boolean) {
499+
...maybeFragment
485500
}
486501

487-
fragment MaybeFragment on Query @include(if: $condition) {
502+
fragment maybeFragment on Query @include(if: $condition) {
488503
me {
489504
name
490505
}

0 commit comments

Comments
 (0)