Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Commit

Permalink
Fix bug where @include directive is ignored if @Skip is present.
Browse files Browse the repository at this point in the history
Commit:
d6da0bff7f877e6a4fb66119796809f9c207f841 [d6da0bf]
Parents:
136630f8fd
Author:
Dylan Thacker-Smith <[email protected]>
Date:
5 April 2016 at 12:56:27 PM SGT
Committer:
Lee Byron <[email protected]>
Labels:
HEAD
  • Loading branch information
sogko committed May 31, 2016
1 parent 6e675a8 commit 95bc032
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
63 changes: 63 additions & 0 deletions directives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,66 @@ func TestDirectivesWorksOnFragmentUnlessTrueOmitsFragment(t *testing.T) {
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{
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 TestDirectivesWorksWithSkipAndIncludeDirectives_IncludeAndSkip(t *testing.T) {
query := `{ a, b @include(if: true) @skip(if: true) }`
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_NoIncludeAndSkip(t *testing.T) {
query := `{ a, b @include(if: false) @skip(if: true) }`
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_NoIncludeOrSkip(t *testing.T) {
query := `{ a, b @include(if: false) @skip(if: false) }`
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))
}
}
7 changes: 3 additions & 4 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,11 @@ func shouldIncludeNode(eCtx *ExecutionContext, directives []*ast.Directive) bool
if err != nil {
return defaultReturnValue
}
if skipIf, ok := argValues["if"]; ok {
if boolSkipIf, ok := skipIf.(bool); ok {
return !boolSkipIf
if skipIf, ok := argValues["if"].(bool); ok {
if skipIf {
return false
}
}
return defaultReturnValue
}
for _, directive := range directives {
if directive == nil || directive.Name == nil {
Expand Down

0 comments on commit 95bc032

Please sign in to comment.