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: GraphQL null argument parsing #3013

Merged
merged 5 commits into from
Sep 18, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Sep 16, 2024

Relevant issue(s)

Resolves #3012

Description

This PR fixes an issue where explicitly null GQL inputs would cause a panic.

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).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Added tests

Specify the platform(s) on which this was tested:

  • MacOS

@nasdf nasdf added the bug Something isn't working label Sep 16, 2024
@nasdf nasdf added this to the DefraDB v0.14 milestone Sep 16, 2024
@nasdf nasdf self-assigned this Sep 16, 2024
Copy link

codecov bot commented Sep 16, 2024

Codecov Report

Attention: Patch coverage is 88.71795% with 22 lines in your changes missing coverage. Please review.

Project coverage is 79.33%. Comparing base (2675b2e) to head (555ee59).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
internal/request/graphql/parser/query.go 87.88% 6 Missing and 6 partials ⚠️
internal/request/graphql/parser/filter.go 69.23% 3 Missing and 1 partial ⚠️
internal/request/graphql/parser/commit.go 94.29% 1 Missing and 1 partial ⚠️
internal/request/graphql/parser/mutation.go 94.29% 1 Missing and 1 partial ⚠️
internal/request/graphql/parser/subscription.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3013      +/-   ##
===========================================
- Coverage    79.37%   79.33%   -0.04%     
===========================================
  Files          333      333              
  Lines        25766    25822      +56     
===========================================
+ Hits         20451    20485      +34     
- Misses        3855     3866      +11     
- Partials      1460     1471      +11     
Flag Coverage Δ
all-tests 79.33% <88.72%> (-0.04%) ⬇️

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

Files with missing lines Coverage Δ
internal/planner/mapper/targetable.go 78.67% <100.00%> (+0.89%) ⬆️
internal/request/graphql/parser/commit.go 87.30% <94.29%> (+0.07%) ⬆️
internal/request/graphql/parser/mutation.go 86.84% <94.29%> (-0.66%) ⬇️
internal/request/graphql/parser/subscription.go 79.31% <50.00%> (-6.90%) ⬇️
internal/request/graphql/parser/filter.go 68.27% <69.23%> (-0.42%) ⬇️
internal/request/graphql/parser/query.go 86.24% <87.88%> (-3.11%) ⬇️

... and 14 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 2675b2e...555ee59. Read the comment docs.

@nasdf nasdf force-pushed the nasdf/fix/null-gql-inputs branch from c4b2456 to 62afbad Compare September 17, 2024 00:18
@nasdf nasdf force-pushed the nasdf/fix/null-gql-inputs branch from 62afbad to 3564655 Compare September 17, 2024 01:27
@nasdf nasdf requested a review from a team September 17, 2024 15:40
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Looks good to me Keenan, thanks for sorting this out so quickly. Approving now, but have a tiny todo and a question for you before merge please :)

@@ -110,7 +110,7 @@ func filterObjectToMap(mapping *core.DocumentMapping, obj map[connor.FilterKey]a
for k, v := range obj {
switch keyType := k.(type) {
case *PropertyIndex:
subObj := v.(map[connor.FilterKey]any)
subObj, _ := v.(map[connor.FilterKey]any)
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: This looks like it was accidentally left in after debugging - can it be reverted?

Copy link
Member Author

Choose a reason for hiding this comment

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

This line was causing a panic when the property value is nil. Is there a different way I should be handling the nil value here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. I would prefer a if v != nil wrapper then - it is a much stronger declaration of intent.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

},
testUtils.Request{
Request: `mutation {
create_Users(encrypt: null, input: {name: "Bob"}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: input is not nillable? (I don't see any tests for that)

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch! added a test

@@ -0,0 +1,110 @@
// Copyright 2024 Democratized Data Foundation
Copy link
Contributor

Choose a reason for hiding this comment

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

priase: Thanks for all theses tests Keenan, looks good :)

@nasdf nasdf merged commit 36eacbe into sourcenetwork:develop Sep 18, 2024
41 of 43 checks passed
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.

Explicitly null GraphQL input values cause panic
2 participants