Skip to content

Commit

Permalink
Spec compliant @skip/@include.
Browse files Browse the repository at this point in the history
Commit:
47f87fa701cb33fc1fb0ca65b4668c7a14a5ad11 [47f87fa]
Parents:
9e5d959353
Author:
Lee Byron <[email protected]>
Date:
5 April 2016 at 1:00:00 PM SGT

remove non spec compliant test

Commit:
07e627adda2b236e720ec352b21eb3043170c60f [07e627a]
Parents:
cf5b2340f9
Author:
Lee Byron <[email protected]>
Date:
5 April 2016 at 1:09:42 PM SGT
  • Loading branch information
sogko committed May 31, 2016
1 parent 95bc032 commit 15268b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 105 deletions.
100 changes: 2 additions & 98 deletions directives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,104 +418,6 @@ func TestDirectivesWorksOnAnonymousInlineFragmentUnlessTrueIncludesAnonymousInli
}
}

func TestDirectivesWorksOnFragmentIfFalseOmitsFragment(t *testing.T) {
query := `
query Q {
a
...Frag
}
fragment Frag on TestType @include(if: false) {
b
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"a": "a",
},
}
result := executeDirectivesTestQuery(t, query)
if len(result.Errors) != 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}

func TestDirectivesWorksOnFragmentIfTrueIncludesFragment(t *testing.T) {
query := `
query Q {
a
...Frag
}
fragment Frag on TestType @include(if: true) {
b
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"a": "a",
"b": "b",
},
}
result := executeDirectivesTestQuery(t, query)
if len(result.Errors) != 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}

func TestDirectivesWorksOnFragmentUnlessFalseIncludesFragment(t *testing.T) {
query := `
query Q {
a
...Frag
}
fragment Frag on TestType @skip(if: false) {
b
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"a": "a",
"b": "b",
},
}
result := executeDirectivesTestQuery(t, query)
if len(result.Errors) != 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}

func TestDirectivesWorksOnFragmentUnlessTrueOmitsFragment(t *testing.T) {
query := `
query Q {
a
...Frag
}
fragment Frag on TestType @skip(if: true) {
b
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"a": "a",
},
}
result := executeDirectivesTestQuery(t, query)
if len(result.Errors) != 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}

func TestDirectivesWorksWithSkipAndIncludeDirectives_IncludeAndNoSkip(t *testing.T) {
query := `{ a, b @include(if: true) @skip(if: false) }`
expected := &graphql.Result{
Expand Down Expand Up @@ -548,6 +450,7 @@ func TestDirectivesWorksWithSkipAndIncludeDirectives_IncludeAndSkip(t *testing.T
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}

func TestDirectivesWorksWithSkipAndIncludeDirectives_NoIncludeAndSkip(t *testing.T) {
query := `{ a, b @include(if: false) @skip(if: true) }`
expected := &graphql.Result{
Expand All @@ -563,6 +466,7 @@ func TestDirectivesWorksWithSkipAndIncludeDirectives_NoIncludeAndSkip(t *testing
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}

func TestDirectivesWorksWithSkipAndIncludeDirectives_NoIncludeOrSkip(t *testing.T) {
query := `{ a, b @include(if: false) @skip(if: false) }`
expected := &graphql.Result{
Expand Down
12 changes: 5 additions & 7 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ func collectFields(p CollectFieldsParams) map[string][]*ast.Field {
}

if fragment, ok := fragment.(*ast.FragmentDefinition); ok {
if !shouldIncludeNode(p.ExeContext, fragment.Directives) ||
!doesFragmentConditionMatch(p.ExeContext, fragment, p.RuntimeType) {
if !doesFragmentConditionMatch(p.ExeContext, fragment, p.RuntimeType) {
continue
}
innerParams := CollectFieldsParams{
Expand Down Expand Up @@ -372,7 +371,7 @@ func shouldIncludeNode(eCtx *ExecutionContext, directives []*ast.Directive) bool
return defaultReturnValue
}
if skipIf, ok := argValues["if"].(bool); ok {
if skipIf {
if skipIf == true {
return false
}
}
Expand All @@ -395,12 +394,11 @@ func shouldIncludeNode(eCtx *ExecutionContext, directives []*ast.Directive) bool
if err != nil {
return defaultReturnValue
}
if includeIf, ok := argValues["if"]; ok {
if boolIncludeIf, ok := includeIf.(bool); ok {
return boolIncludeIf
if includeIf, ok := argValues["if"].(bool); ok {
if includeIf == false {
return false
}
}
return defaultReturnValue
}
return defaultReturnValue
}
Expand Down

0 comments on commit 15268b7

Please sign in to comment.