Skip to content

Commit e0601a5

Browse files
gburtchris-ramon
authored andcommitted
add a test of ResultCallbackFn
1 parent e2c76fb commit e0601a5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

handler_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,23 @@ func TestHandler_BasicQuery_Pretty(t *testing.T) {
9393
},
9494
},
9595
}
96-
queryString := `query=query HeroNameQuery { hero { name } }`
96+
queryString := `query=query HeroNameQuery { hero { name } }&operationName=HeroNameQuery`
9797
req, _ := http.NewRequest("GET", fmt.Sprintf("/graphql?%v", queryString), nil)
9898

99+
callbackCalled := false
99100
h := handler.New(&handler.Config{
100101
Schema: &testutil.StarWarsSchema,
101102
Pretty: true,
103+
ResultCallbackFn: func(ctx context.Context, params *graphql.Params, result *graphql.Result, responseBody []byte) {
104+
callbackCalled = true
105+
if params.OperationName != "HeroNameQuery" {
106+
t.Fatalf("OperationName passed to callback was not HeroNameQuery: %v", params.OperationName)
107+
}
108+
109+
if result.HasErrors() {
110+
t.Fatalf("unexpected graphql result errors")
111+
}
112+
},
102113
})
103114
result, resp := executeTest(t, h, req)
104115
if resp.Code != http.StatusOK {
@@ -107,6 +118,9 @@ func TestHandler_BasicQuery_Pretty(t *testing.T) {
107118
if !reflect.DeepEqual(result, expected) {
108119
t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
109120
}
121+
if !callbackCalled {
122+
t.Fatalf("ResultCallbackFn was not called when it should have been")
123+
}
110124
}
111125

112126
func TestHandler_BasicQuery_Ugly(t *testing.T) {

0 commit comments

Comments
 (0)