Skip to content
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

[RFC] Type condition optional on inline fragments. #100

Merged
merged 1 commit into from
Oct 2, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions spec/Appendix B -- Grammar Summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ Argument : Name : Value

FragmentSpread : ... FragmentName Directives?

InlineFragment : ... on TypeCondition Directives? SelectionSet
InlineFragment : ... TypeCondition? Directives? SelectionSet

FragmentDefinition : fragment FragmentName on TypeCondition Directives? SelectionSet
FragmentDefinition : fragment FragmentName TypeCondition Directives? SelectionSet

FragmentName : Name but not `on`

TypeCondition : NamedType
TypeCondition : on NamedType

Value[Const] :
- [~Const] Variable
Expand Down
24 changes: 21 additions & 3 deletions spec/Section 2 -- Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ otherwise the field's name.

FragmentSpread : ... FragmentName Directives?

FragmentDefinition : fragment FragmentName on TypeCondition Directives? SelectionSet
FragmentDefinition : fragment FragmentName TypeCondition Directives? SelectionSet

FragmentName : Name but not `on`

Expand Down Expand Up @@ -519,7 +519,7 @@ produce the same response object.

#### Type Conditions

TypeCondition : NamedType
TypeCondition : on NamedType

Fragments must specify the type they apply to. In this example, `friendFields`
can be used in the context of querying a `User`.
Expand Down Expand Up @@ -578,7 +578,7 @@ will be present and `friends` will not.

#### Inline Fragments

InlineFragment : ... on TypeCondition Directives? SelectionSet
InlineFragment : ... TypeCondition? Directives? SelectionSet

Fragments can be defined inline within a selection set. This is done to
conditionally include fields based on their runtime type. This feature of
Expand All @@ -603,6 +603,24 @@ query inlineFragmentTyping {
}
```

Inline fragments may also be used to apply a directive to a group of fields.
If the TypeCondition is omitted, an inline fragment is considered to be of the
same type as the enclosing context.

```graphql
query inlineFragmentNoType($expandedInfo: Boolean) {
user(handle: "zuck") {
id
name
... @include(if: $expandedInfo) {
firstName
lastName
birthday
}
}
}
```


### Input Values

Expand Down
6 changes: 6 additions & 0 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ fragment inlineFragment on Dog {
name
}
}

fragment inlineFragment on Dog {
... @include(if: true) {
name
}
}
```

and the following do not validate:
Expand Down
2 changes: 1 addition & 1 deletion spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CollectFields(objectType, selectionSet, visitedFragments):
* Append all items in {fragmentGroup} to {groupForResponseKey}.
* If {selection} is an inline fragment:
* Let {fragmentType} be the type condition on {selection}.
* If {doesFragmentTypeApply(objectType, fragmentType)} is false, continue
* If {fragmentType} is not {null} and {doesFragmentTypeApply(objectType, fragmentType)} is false, continue
with the next {selection} in {selectionSet}.
* Let {fragmentSelectionSet} be the top-level selection set of {selection}.
* Let {fragmentGroupedFields} be the result of calling {CollectFields(objectType, fragmentSelectionSet)}.
Expand Down