Skip to content

Commit 7cd3eca

Browse files
committed
GravatarCommit: 3f1f9f5759704ca9ed153c98558236a66af75153 [3f1f9f5]
Parents: 529257b8d3 Author: Lee Byron <[email protected]> Date: 2 October 2015 at 9:10:21 AM SGT [RFC] Type condition optional on inline fragments. Implements graphql/graphql-spec#100
1 parent 117e98a commit 7cd3eca

10 files changed

+242
-28
lines changed

executor.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ func doesFragmentConditionMatch(eCtx *ExecutionContext, fragment ast.Node, ttype
390390

391391
switch fragment := fragment.(type) {
392392
case *ast.FragmentDefinition:
393-
conditionalType, err := typeFromAST(eCtx.Schema, fragment.TypeCondition)
393+
typeConditionAST := fragment.TypeCondition
394+
if typeConditionAST == nil {
395+
return true
396+
}
397+
conditionalType, err := typeFromAST(eCtx.Schema, typeConditionAST)
394398
if err != nil {
395399
return false
396400
}
@@ -400,19 +404,24 @@ func doesFragmentConditionMatch(eCtx *ExecutionContext, fragment ast.Node, ttype
400404
if conditionalType.Name() == ttype.Name() {
401405
return true
402406
}
403-
404407
if conditionalType, ok := conditionalType.(Abstract); ok {
405408
return conditionalType.IsPossibleType(ttype)
406409
}
407410
case *ast.InlineFragment:
408-
conditionalType, err := typeFromAST(eCtx.Schema, fragment.TypeCondition)
411+
typeConditionAST := fragment.TypeCondition
412+
if typeConditionAST == nil {
413+
return true
414+
}
415+
conditionalType, err := typeFromAST(eCtx.Schema, typeConditionAST)
409416
if err != nil {
410417
return false
411418
}
412419
if conditionalType == ttype {
413420
return true
414421
}
415-
422+
if conditionalType.Name() == ttype.Name() {
423+
return true
424+
}
416425
if conditionalType, ok := conditionalType.(Abstract); ok {
417426
return conditionalType.IsPossibleType(ttype)
418427
}

kitchen-sink.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ query namedQuery($foo: ComplexFooType, $bar: Bar = DefaultBarValue) {
1212
}
1313
}
1414
}
15+
... @skip(unless: $foo) {
16+
id
17+
}
18+
... {
19+
id
20+
}
1521
}
1622
}
1723

0 commit comments

Comments
 (0)