Skip to content

Commit

Permalink
Graphql formatting consistency
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
leebyron committed Jul 15, 2015
1 parent 6832558 commit 188cb06
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 213 deletions.
109 changes: 62 additions & 47 deletions Section 2 -- Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ viewer. Some typical examples of global fields:
```graphql
# `me` could represent the currently logged in user.
query getMe {
me { /* ... */ }
me {
# ...
}
}

# `user` represents one of many users in a graph of data.
query getZuck {
user(id: 4) { /* ... */ }
user(id: 4) {
# ...
}
}
```

Expand All @@ -77,8 +81,8 @@ fetching data from some user object:
```graphql
query getZuck {
user(id: 4) {
id,
firstName,
id
firstName
lastName
}
}
Expand All @@ -90,11 +94,11 @@ nested types. All queries must specify down to scalar fields.
```graphql
query getZuck {
user(id: 4) {
id,
firstName,
lastName,
id
firstName
lastName
birthday {
month,
month
day
}
}
Expand All @@ -114,8 +118,8 @@ specific size:
```graphql
{
user(id: 4) {
id,
name,
id
name
profilePic(size: 100)
}
}
Expand All @@ -126,8 +130,8 @@ Many arguments can exist for a given field:
```graphql
{
user(id: 4) {
id,
name,
id
name
profilePic(width: 100, height: 50)
}
}
Expand Down Expand Up @@ -163,9 +167,9 @@ the resulting object will not have duplicate keys:
```graphql
{
user(id: 4) {
id,
name,
smallPic: profilePic(size: 64),
id
name
smallPic: profilePic(size: 64)
bigPic: profilePic(size: 1024)
}
}
Expand All @@ -189,7 +193,7 @@ Since the top level of a query is a field, it also can be given an alias:
```graphql
{
zuck: user(id: 4) {
id,
id
name
}
}
Expand Down Expand Up @@ -269,8 +273,8 @@ of a particular device:
```graphql
query getZuckProfile($devicePicSize: Int) {
user(id: 4) {
id,
name,
id
name
profilePic(size: $devicePicSize)
}
}
Expand Down Expand Up @@ -299,13 +303,13 @@ as well as friends of some user:
query noFragments {
user(id: 4) {
friends(first: 10) {
id,
name,
id
name
profilePic(size: 50)
},
}
mutualFriends(first: 10) {
id,
name,
id
name
profilePic(size: 50)
}
}
Expand All @@ -318,14 +322,14 @@ a parent fragment or query.
```graphql
query withFragments {
user(id: 4) {
friends(first: 10) { ...friendFields },
friends(first: 10) { ...friendFields }
mutualFriends(first: 10) { ...friendFields }
}
}

fragment friendFields on User {
id,
name,
id
name
profilePic(size: 50)
}
```
Expand All @@ -338,17 +342,20 @@ spreads.
For example:

```graphql
query withNestedFragments
{
query withNestedFragments {
user(id: 4) {
friends(first: 10) { ...friendFields },
mutualFriends(first: 10) { ...friendFields }
friends(first: 10) {
...friendFields
}
mutualFriends(first: 10) {
...friendFields
}
}
}

fragment friendFields on User {
id,
name,
id
name
...standardProfilePic
}

Expand Down Expand Up @@ -378,18 +385,22 @@ For example in this query on the Facebook data model:
```graphql
query FragmentTyping {
profiles(handles: ["zuck", "cocacola"]) {
handle,
...userFragment,
handle
...userFragment
...pageFragment
}
}

fragment userFragment on User {
friends { count }
friends {
count
}
}

fragment pageFragment on Page {
likers { count }
likers {
count
}
}
```

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

```graphql
query InlineFragmentTyping {
query inlineFragmentTyping {
profiles(handles: ["zuck", "cocacola"]) {
handle,
handle
... on User {
friends { count }
},
friends {
count
}
}
... on Page {
likers { count }
likers {
count
}
}
}
}
Expand Down Expand Up @@ -466,11 +481,11 @@ definition.
For example, the following query:

```graphql
query HasConditionalFragment($condition: Boolean) {
...MaybeFragment @include(if: $condition)
query hasConditionalFragment($condition: Boolean) {
...maybeFragment @include(if: $condition)
}

fragment MaybeFragment on Query {
fragment maybeFragment on Query {
me {
name
}
Expand All @@ -480,11 +495,11 @@ fragment MaybeFragment on Query {
Will have identical runtime behavior as

```graphql
query HasConditionalFragment($condition: Boolean) {
...MaybeFragment
query hasConditionalFragment($condition: Boolean) {
...maybeFragment
}

fragment MaybeFragment on Query @include(if: $condition) {
fragment maybeFragment on Query @include(if: $condition) {
me {
name
}
Expand Down

0 comments on commit 188cb06

Please sign in to comment.