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

refactor: GraphQL order input #3044

Merged
merged 6 commits into from
Sep 24, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Sep 20, 2024

Relevant issue(s)

Resolves #3043

Description

This PR fixes an issue where GQL variables could not be used with ordering input args. The order input type on collections and aggregates has been refactored to a list so that ordering is preserved in all environments.

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 integration tests

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

  • MacOS

@nasdf nasdf added the area/query Related to the query component label Sep 20, 2024
@nasdf nasdf added this to the DefraDB v0.14 milestone Sep 20, 2024
@nasdf nasdf self-assigned this Sep 20, 2024
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 81.53846% with 12 lines in your changes missing coverage. Please review.

Project coverage is 79.50%. Comparing base (228fb99) to head (497160c).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
internal/request/graphql/parser/order.go 78.72% 6 Missing and 4 partials ⚠️
internal/request/graphql/parser/filter.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3044      +/-   ##
===========================================
+ Coverage    79.40%   79.50%   +0.10%     
===========================================
  Files          342      343       +1     
  Lines        26514    26511       -3     
===========================================
+ Hits         21052    21075      +23     
+ Misses        3942     3927      -15     
+ Partials      1520     1509      -11     
Flag Coverage Δ
all-tests 79.50% <81.54%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
internal/request/graphql/parser/commit.go 87.30% <100.00%> (ø)
internal/request/graphql/parser/query.go 90.86% <100.00%> (+4.84%) ⬆️
internal/request/graphql/schema/generate.go 87.97% <100.00%> (ø)
internal/request/graphql/schema/types/commits.go 100.00% <100.00%> (ø)
internal/request/graphql/parser/filter.go 67.69% <33.33%> (-0.58%) ⬇️
internal/request/graphql/parser/order.go 78.72% <78.72%> (ø)

... and 16 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 228fb99...497160c. Read the comment docs.

@nasdf nasdf requested a review from a team September 20, 2024 17:58
Comment on lines 65 to 69
// prepend the current field name, to the parsed condition from the slice
// Eg. order: {author: {name: ASC, birthday: DESC}}
// This results in an array of [name, birthday] converted to
// [author.name, author.birthday].
// etc.
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: The order object in this comment seems invalid as it's an unordered map intending for name and birthday to be in an explicit order.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would have to be order: [{author: {name: ASC}}, {author: {birthday: DESC}}]

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! fixed a few others as well

if len(arg) == 0 {
return nil, nil
}
if len(arg) != 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo: Please add a test for the case where we have more than one argument

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

case 1:
return request.DESC, nil

default:
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo: please add a test that satisfies this.

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 case is technically unreachable because the GQL parsing will fail. I've added a test to demonstrate this. I felt it was better to keep the default case instead of having it undefined, but I can remove it if you have a different preference.

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. Just a couple test todos and a comment to fix before merge.

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

LGTM :)

@nasdf nasdf merged commit 98befd6 into sourcenetwork:develop Sep 24, 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
area/query Related to the query component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQL order argument does not work with variables
3 participants