Skip to content

Commit 435ad86

Browse files
committed
Merge pull request #100 from facebook/inline-fragment-op-type
[RFC] Type condition optional on inline fragments.
2 parents d81fd1e + 664fc0e commit 435ad86

4 files changed

+31
-7
lines changed

spec/Appendix B -- Grammar Summary.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ Argument : Name : Value
113113

114114
FragmentSpread : ... FragmentName Directives?
115115

116-
InlineFragment : ... on TypeCondition Directives? SelectionSet
116+
InlineFragment : ... TypeCondition? Directives? SelectionSet
117117

118-
FragmentDefinition : fragment FragmentName on TypeCondition Directives? SelectionSet
118+
FragmentDefinition : fragment FragmentName TypeCondition Directives? SelectionSet
119119

120120
FragmentName : Name but not `on`
121121

122-
TypeCondition : NamedType
122+
TypeCondition : on NamedType
123123

124124
Value[Const] :
125125
- [~Const] Variable

spec/Section 2 -- Language.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ otherwise the field's name.
431431

432432
FragmentSpread : ... FragmentName Directives?
433433

434-
FragmentDefinition : fragment FragmentName on TypeCondition Directives? SelectionSet
434+
FragmentDefinition : fragment FragmentName TypeCondition Directives? SelectionSet
435435

436436
FragmentName : Name but not `on`
437437

@@ -519,7 +519,7 @@ produce the same response object.
519519

520520
#### Type Conditions
521521

522-
TypeCondition : NamedType
522+
TypeCondition : on NamedType
523523

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

579579
#### Inline Fragments
580580

581-
InlineFragment : ... on TypeCondition Directives? SelectionSet
581+
InlineFragment : ... TypeCondition? Directives? SelectionSet
582582

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

606+
Inline fragments may also be used to apply a directive to a group of fields.
607+
If the TypeCondition is omitted, an inline fragment is considered to be of the
608+
same type as the enclosing context.
609+
610+
```graphql
611+
query inlineFragmentNoType($expandedInfo: Boolean) {
612+
user(handle: "zuck") {
613+
id
614+
name
615+
... @include(if: $expandedInfo) {
616+
firstName
617+
lastName
618+
birthday
619+
}
620+
}
621+
}
622+
```
623+
606624

607625
### Input Values
608626

spec/Section 5 -- Validation.md

+6
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ fragment inlineFragment on Dog {
650650
name
651651
}
652652
}
653+
654+
fragment inlineFragment on Dog {
655+
... @include(if: true) {
656+
name
657+
}
658+
}
653659
```
654660

655661
and the following do not validate:

spec/Section 6 -- Execution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CollectFields(objectType, selectionSet, visitedFragments):
7777
* Append all items in {fragmentGroup} to {groupForResponseKey}.
7878
* If {selection} is an inline fragment:
7979
* Let {fragmentType} be the type condition on {selection}.
80-
* If {doesFragmentTypeApply(objectType, fragmentType)} is false, continue
80+
* If {fragmentType} is not {null} and {doesFragmentTypeApply(objectType, fragmentType)} is false, continue
8181
with the next {selection} in {selectionSet}.
8282
* Let {fragmentSelectionSet} be the top-level selection set of {selection}.
8383
* Let {fragmentGroupedFields} be the result of calling {CollectFields(objectType, fragmentSelectionSet)}.

0 commit comments

Comments
 (0)