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: Make GraphQL errors spec compliant #3040

Merged
merged 8 commits into from
Sep 20, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Sep 19, 2024

Relevant issue(s)

Resolves #3039
Resolves #3041

Description

This PR fixes an issue with response errors not being spec compliant.

It also adds a GQLError type to the client package.

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 here https://github.com/sourcenetwork/defradb-third-party-test

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

  • MacOS

@nasdf nasdf added the bug Something isn't working label Sep 19, 2024
@nasdf nasdf added this to the DefraDB v0.14 milestone Sep 19, 2024
@nasdf nasdf self-assigned this Sep 19, 2024
@nasdf nasdf force-pushed the nasdf/fix/gql-error-response branch from f112cfa to 2497113 Compare September 19, 2024 18:02
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 75.80645% with 15 lines in your changes missing coverage. Please review.

Project coverage is 79.47%. Comparing base (55e56a5) to head (2535659).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
http/client.go 36.36% 6 Missing and 1 partial ⚠️
client/db.go 88.24% 1 Missing and 1 partial ⚠️
http/errors.go 50.00% 1 Missing and 1 partial ⚠️
internal/request/graphql/parser.go 33.33% 1 Missing and 1 partial ⚠️
internal/db/request.go 75.00% 1 Missing ⚠️
internal/db/store.go 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3040      +/-   ##
===========================================
- Coverage    79.49%   79.47%   -0.02%     
===========================================
  Files          336      336              
  Lines        26075    26074       -1     
===========================================
- Hits         20727    20721       -6     
- Misses        3878     3881       +3     
- Partials      1470     1472       +2     
Flag Coverage Δ
all-tests 79.47% <75.81%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
cli/request.go 75.86% <100.00%> (-1.19%) ⬇️
client/errors.go 59.72% <100.00%> (+5.03%) ⬆️
http/handler_store.go 82.63% <100.00%> (+0.42%) ⬆️
http/openapi.go 98.10% <ø> (ø)
http/utils.go 81.82% <ø> (-7.66%) ⬇️
internal/db/subscriptions.go 82.00% <100.00%> (ø)
internal/db/request.go 82.76% <75.00%> (ø)
internal/db/store.go 70.59% <50.00%> (ø)
client/db.go 91.30% <88.24%> (-8.70%) ⬇️
http/errors.go 30.43% <50.00%> (+0.43%) ⬆️
... and 2 more

... and 12 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 55e56a5...2535659. Read the comment docs.

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

@nasdf nasdf requested review from fredcarle and a team September 19, 2024 19:58
@@ -290,14 +296,33 @@ type GQLResult struct {
//
// If there are values in this slice the request will likely not have run to completion
// and [Data] will be nil.
Errors []error `json:"errors,omitempty"`
Errors []GQLError `json:"errors,omitempty"`

// Data contains the resultant data produced by the GQL request.
//
// It will be nil if any errors were raised during execution.
Data any `json:"data"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: If you add a Marshal/Unmarshal func for GQLResult you could probably drop the new types and functions. It might also be nicer for users of the Go client.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just add a custom Marshal/Unmarshal func for GQLError instead .

Copy link
Member Author

Choose a reason for hiding this comment

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

I would just add a custom Marshal/Unmarshal func for GQLError instead .

I think the custom marshalling only works if its on the GQLResult and we want to keep errors as the generic error type.

I've refactored it to use a custom marshaller and added some tests to make sure our http server returns proper responses.

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. The Marshal/Unmarshal change is nice.

@nasdf nasdf force-pushed the nasdf/fix/gql-error-response branch from f420c8d to 2535659 Compare September 20, 2024 21:55
@nasdf nasdf merged commit d872a0c into sourcenetwork:develop Sep 20, 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.

client GQLResult is not spec compliant GraphQL response errors are not spec compliant
3 participants