diff --git a/http/handler_ccip_test.go b/http/handler_ccip_test.go index 43797b622d..1888effe37 100644 --- a/http/handler_ccip_test.go +++ b/http/handler_ccip_test.go @@ -67,7 +67,7 @@ func TestCCIPGet_WithValidData(t *testing.T) { resHex, err := hex.DecodeString(strings.TrimPrefix(ccipRes.Data, "0x")) require.NoError(t, err) - assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}]}}`, string(resHex)) + assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}, {"name": "adam"}]}}`, string(resHex)) } func TestCCIPGet_WithSubscription(t *testing.T) { @@ -153,7 +153,7 @@ func TestCCIPPost_WithValidData(t *testing.T) { resHex, err := hex.DecodeString(strings.TrimPrefix(ccipRes.Data, "0x")) require.NoError(t, err) - assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}]}}`, string(resHex)) + assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}, {"name": "adam"}]}}`, string(resHex)) } func TestCCIPPost_WithInvalidGraphQLRequest(t *testing.T) { @@ -210,5 +210,11 @@ func setupDatabase(t *testing.T) client.DB { err = col.Create(ctx, doc) require.NoError(t, err) + doc2, err := client.NewDocFromJSON([]byte(`{"name": "adam"}`), col.Definition()) + require.NoError(t, err) + + err = col.Create(ctx, doc2) + require.NoError(t, err) + return cdb } diff --git a/http/handler_store.go b/http/handler_store.go index 990a623a62..3d2cef63de 100644 --- a/http/handler_store.go +++ b/http/handler_store.go @@ -284,8 +284,11 @@ func (s *storeHandler) ExecRequest(rw http.ResponseWriter, req *http.Request) { var request GraphQLRequest switch { case req.URL.Query().Get("query") != "": + request.Query = req.URL.Query().Get("query") + request.OperationName = req.URL.Query().Get("operationName") + variablesFromQuery := req.URL.Query().Get("variables") if variablesFromQuery != "" { var variables map[string]any diff --git a/http/handler_store_test.go b/http/handler_store_test.go index e548cbc5ab..71a1d8b4e3 100644 --- a/http/handler_store_test.go +++ b/http/handler_store_test.go @@ -98,11 +98,19 @@ func TestExecRequest_WithInvalidQuery_HasSpecCompliantErrors(t *testing.T) { func TestExecRequest_HttpGet_WithOperationName(t *testing.T) { cdb := setupDatabase(t) - query := `query UserQuery { + query := ` + query UserQuery { User { name } - }` + } + query UserQueryWithDocID { + User { + _docID + name + } + } + ` operationName := "UserQuery" encodedQuery := url.QueryEscape(query) @@ -123,8 +131,6 @@ func TestExecRequest_HttpGet_WithOperationName(t *testing.T) { resData, err := io.ReadAll(res.Body) require.NoError(t, err) - t.Log(string(resData)) - var gqlResponse map[string]any err = json.Unmarshal(resData, &gqlResponse) require.NoError(t, err) @@ -132,6 +138,18 @@ func TestExecRequest_HttpGet_WithOperationName(t *testing.T) { // errors should be omitted _, ok := gqlResponse["errors"] assert.False(t, ok) + + // Compare the response data to the expected output + expectedJSON := `{ + "data": { + "User": [ + {"name": "bob"}, + {"name": "adam"} + ] + } + }` + assert.JSONEq(t, expectedJSON, string(resData)) + } func TestExecRequest_HttpGet_WithVariables(t *testing.T) { @@ -171,4 +189,14 @@ func TestExecRequest_HttpGet_WithVariables(t *testing.T) { // errors should be omitted _, ok := gqlResponse["errors"] assert.False(t, ok) + + // Compare the response data to the expected output + expectedJSON := `{ + "data": { + "User": [ + {"name": "bob"} + ] + } + }` + assert.JSONEq(t, expectedJSON, string(resData)) }