Skip to content
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

fix: Add support for operationName and variables in HTTP GET #3292

Merged
merged 12 commits into from
Dec 5, 2024

Conversation

ChrisBQu
Copy link
Collaborator

@ChrisBQu ChrisBQu commented Dec 4, 2024

Relevant issue(s)

Resolves #3153

Description

I have made it so that operationName and variables are supported by HTTP GET requests. I did this by modifying the ExecRequest function inside http/handler_store.go such that operationName and variables parameters are extracted if they are present.

I added two new tests to http/handler_store_test.go which test this functionality. See:

TestExecRequest_WithValidQuery_HttpGet_WithOperationName_OmitsErrors
and
TestExecRequest_HttpGet_WithVariables_OmitsErrors

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).

How has this been tested?

The platform(s) on which this was tested:

  • Windows

@ChrisBQu ChrisBQu added the bug Something isn't working label Dec 4, 2024
@ChrisBQu ChrisBQu added this to the DefraDB v0.15 milestone Dec 4, 2024
@ChrisBQu ChrisBQu self-assigned this Dec 4, 2024
@ChrisBQu ChrisBQu changed the title Issue 3153 first commit bug: Add support for operationName and variables in HTTP GET Dec 4, 2024
@ChrisBQu ChrisBQu requested a review from a team December 4, 2024 21:36
@ChrisBQu ChrisBQu changed the title bug: Add support for operationName and variables in HTTP GET fix: Add support for operationName and variables in HTTP GET Dec 4, 2024
@ChrisBQu ChrisBQu removed the request for review from a team December 4, 2024 21:52
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments :)

Comment on lines 289 to 292
operationNameFromQuery := req.URL.Query().Get("operationName")
if operationNameFromQuery != "" {
request.OperationName = operationNameFromQuery
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: You could assign directly to request.OperationName. Doing so would have the exact same outcome as what you're doing here.

@@ -93,3 +94,79 @@ func TestExecRequest_WithInvalidQuery_HasSpecCompliantErrors(t *testing.T) {
"message": "Cannot query field \"invalid\" on type \"User\".",
}})
}

func TestExecRequest_WithValidQuery_HttpGet_WithOperationName_OmitsErrors(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The test above that has WithValidQuery_OmitsErrors, has this pattern because it specifically checks that with a valid query, the API returns no error field in the payload (we previously had an empty list for errors). I would suggestion removing WithValidQuery as it's not that relevant to the test and instead of OmitsErrors, maybe have something like ShouldSucceed or something more meaningful. Same for the test bellow.

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 78.09%. Comparing base (e4599e8) to head (616ddc4).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
http/handler_store.go 66.67% 3 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3292   +/-   ##
========================================
  Coverage    78.09%   78.09%           
========================================
  Files          382      382           
  Lines        35371    35383   +12     
========================================
+ Hits         27621    27632   +11     
  Misses        6117     6117           
- Partials      1633     1634    +1     
Flag Coverage Δ
all-tests 78.09% <66.67%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
http/handler_store.go 81.16% <66.67%> (-0.46%) ⬇️

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4599e8...616ddc4. Read the comment docs.

@ChrisBQu ChrisBQu requested a review from fredcarle December 5, 2024 15:55
Comment on lines 138 to 140
// errors should be omitted
_, ok := gqlResponse["errors"]
assert.False(t, ok)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This could be removed as having it in the test suggests that it's important for this test to check that the errors are omitted (it's not). We have a dedicated test for this above.

Comment on lines 189 to 191
// errors should be omitted
_, ok := gqlResponse["errors"]
assert.False(t, ok)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Same as above.

_, ok := gqlResponse["errors"]
assert.False(t, ok)

// Compare the response data to the expected output
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This comment is describing what is already evident just by looking at the code. Was is less evident though is that you are ensuring that the returned user list doesn't include the _docID field from the other operation. The comment should probably convey that.

_, ok := gqlResponse["errors"]
assert.False(t, ok)

// Compare the response data to the expected output
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Similar to above. In this case, something like Ensure only bob is returned based on the provided filter variable. would be more descriptive.

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for taking care of this, Chris :)

@ChrisBQu ChrisBQu merged commit 89f9f41 into sourcenetwork:develop Dec 5, 2024
41 of 43 checks passed
ChrisBQu added a commit to ChrisBQu/defradb that referenced this pull request Feb 21, 2025
…etwork#3292)

## Relevant issue(s)

Resolves sourcenetwork#3153

## Description

I have made it so that operationName and variables are supported by HTTP
GET requests. I did this by modifying the `ExecRequest` function inside
`http/handler_store.go` such that `operationName` and `variables`
parameters are extracted if they are present.

I added two new tests to `http/handler_store_test.go` which test this
functionality. See:

`TestExecRequest_WithValidQuery_HttpGet_WithOperationName_OmitsErrors`
and
`TestExecRequest_HttpGet_WithVariables_OmitsErrors`

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).

## How has this been tested?

The platform(s) on which this was tested:
- Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQL HTTP GET is missing operationName and variables
2 participants