-
Notifications
You must be signed in to change notification settings - Fork 233
fix: add tests and implement graphql over http cases #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ceaff13
fix: add tests and implement graphql over http cases
jensneuse c7c381a
chore: fix extensions validation
jensneuse a7cb64c
chore: fix validation test assertion
jensneuse 2edb489
chore: address feedback
jensneuse 2bb73cc
Merge branch 'main' into fix/properly-implement-graphql-over-http
jensneuse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package integration | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "io" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/wundergraph/cosmo/router-tests/testenv" | ||
| ) | ||
|
|
||
| func TestGraphQLOverHTTPCompatibility(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testenv.Run(t, &testenv.Config{}, func(t *testing.T, xEnv *testenv.Environment) { | ||
| t.Run("valid request should return 200 OK with valid response", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{"query":"query Find($criteria: SearchInput!) {findEmployees(criteria: $criteria){id details {forename surname}}}","variables":{"criteria":{"nationality":"GERMAN"}}}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusOK, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"data":{"findEmployees":[{"id":1,"details":{"forename":"Jens","surname":"Neuse"}},{"id":2,"details":{"forename":"Dustin","surname":"Deus"}},{"id":4,"details":{"forename":"Björn","surname":"Schwenzer"}},{"id":11,"details":{"forename":"Alexandra","surname":"Neuse"}}]}}`, string(data)) | ||
| }) | ||
| t.Run("malformed JSON should return 400", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{"query":query Find($criteria: SearchInput!) {findEmployees(criteria: $criteria){id details {forename surname}}}","variables":{"criteria":{"nationality":"GERMAN"}}}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusBadRequest, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"errors":[{"message":"error parsing request body"}],"data":null}`, string(data)) | ||
| }) | ||
| t.Run("malformed JSON variant should return 400", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{{"query":query Find($criteria: SearchInput!) {findEmployees(criteria: $criteria){id details {forename surname}}}","variables":{"criteria":{"nationality":"GERMAN"}}}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusBadRequest, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"errors":[{"message":"error parsing request body"}],"data":null}`, string(data)) | ||
| }) | ||
| t.Run("malformed JSON variant #2 should return 400", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusBadRequest, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"errors":[{"message":"error parsing request body"}],"data":null}`, string(data)) | ||
| }) | ||
| t.Run("malformed JSON variables variant should return 400", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{"query":"query Find($criteria: SearchInput!) {findEmployees(criteria: $criteria){id details {forename surname}}}","variables":{"criteria":{"nationality":GERMAN}}}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusBadRequest, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"errors":[{"message":"error parsing request body"}],"data":null}`, string(data)) | ||
| }) | ||
| t.Run("missing variables should return 200 OK with validation errors response", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{"query":"query Find($criteria: SearchInput!) {findEmployees(criteria: $criteria){id details {forename surname}}}"}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusOK, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"errors":[{"message":"Variable \"$criteria\" of required type \"SearchInput!\" was not provided."}],"data":null}`, string(data)) | ||
| }) | ||
| t.Run("mismatching variables although valid JSON should not be 400", func(t *testing.T) { | ||
| header := http.Header{ | ||
| "Content-Type": []string{"application/json"}, | ||
| "Accept": []string{"application/json"}, | ||
| } | ||
| body := []byte(`{"query":"query Find($criteria: SearchInput!) {findEmployees(criteria: $criteria){id details {forename surname}}}","variables":{"whatever":123}`) | ||
| res, err := xEnv.MakeRequest("POST", "/graphql", header, bytes.NewReader(body)) | ||
| require.NoError(t, err) | ||
| require.Equal(t, http.StatusOK, res.StatusCode) | ||
| data, err := io.ReadAll(res.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, `{"errors":[{"message":"Variable \"$criteria\" of required type \"SearchInput!\" was not provided."}],"data":null}`, string(data)) | ||
| }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.