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

feat: Mutation typed input #2167

Merged
merged 24 commits into from
Jan 11, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Jan 5, 2024

Relevant issue(s)

Resolves #2143

Description

This PR adds a typed input object for create and update mutations.

As a side effect of this change the relationship alias has been replaced with the <type>_id input field.

Relational sub-documents cannot be created from mutation input in this implementation.

Related SIP https://github.com/sourcenetwork/SIPs/discussions/10

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?

Make test

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

  • MacOS

@nasdf nasdf added feature New feature or request area/query Related to the query component area/parser Related to the parser components labels Jan 5, 2024
@nasdf nasdf self-assigned this Jan 5, 2024
Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (858e6a6) 74.14% compared to head (4bd619f) 74.22%.

❗ Current head 4bd619f differs from pull request most recent head 876a693. Consider uploading reports for the commit 876a693 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2167      +/-   ##
===========================================
+ Coverage    74.14%   74.22%   +0.07%     
===========================================
  Files          256      256              
  Lines        25399    25465      +66     
===========================================
+ Hits         18831    18899      +68     
+ Misses        5285     5277       -8     
- Partials      1283     1289       +6     
Flag Coverage Δ
all-tests 74.22% <80.33%> (+0.07%) ⬆️

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

Files Coverage Δ
client/document.go 67.60% <100.00%> (+3.53%) ⬆️
client/request/mutation.go 100.00% <ø> (ø)
planner/create.go 64.13% <100.00%> (-3.55%) ⬇️
planner/explain.go 58.99% <ø> (ø)
planner/mapper/mapper.go 87.42% <100.00%> (ø)
planner/mapper/mutation.go 0.00% <0.00%> (ø)
request/graphql/parser/mutation.go 79.82% <93.55%> (+0.05%) ⬆️
planner/update.go 76.24% <57.14%> (-0.23%) ⬇️
request/graphql/schema/errors.go 29.82% <0.00%> (-2.87%) ⬇️
request/graphql/schema/generate.go 86.01% <80.88%> (+0.28%) ⬆️

... 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 858e6a6...876a693. Read the comment docs.

@nasdf nasdf requested a review from a team January 5, 2024 19:35
// for collection create and update mutation operations.
func (g *Generator) buildMutationInputTypes(collections []client.CollectionDefinition) error {
for _, c := range collections {
// Copy the loop variable before usage within the loop or it
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: Note that this will no longer be needed starting with Go 1.22

Copy link
Member

@shahzadlone shahzadlone Jan 9, 2024

Choose a reason for hiding this comment

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

nitpick: Would appreciate a comment here mentioning 1.22 for regex search in the future, so can easily find some of these.

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.

As a side effect of this change the relationship alias has been replaced with the _id input field.

I don't understand what is meant by 'replaced' with the type_id, because before we had both the 'type' alias and 'type_id'.

Why were the alias tests deleted? did we just drop support for aliases (i.e. a whole feature seems to have been dropped)?

IIRC this was a feature that was requested by one of the partners, and was implemented in:

More context:
https://discord.com/channels/427944769851752448/1061831110956421150/1113950104517365900

@nasdf
Copy link
Member Author

nasdf commented Jan 9, 2024

As a side effect of this change the relationship alias has been replaced with the _id input field.

I don't understand what is meant by 'replaced' with the type_id, because before we had both the 'type' alias and 'type_id'.

Why were the alias tests deleted? did we just drop support for aliases (i.e. a whole feature seems to have been dropped)?

IIRC this was a feature that was requested by one of the partners, and was implemented in:

More context: https://discord.com/channels/427944769851752448/1061831110956421150/1113950104517365900

We talked about this briefly in the standup last week. Since the mutation input fields are now typed it is not possible to support relation field aliases (unless we add gql union types).

@fredcarle
Copy link
Collaborator

it is not possible to support relation field aliases

It is possible if we set the mutation type for the foreign object as a gql.ID. But we may want to be able create the foreign document from the on mutation which would require the field to remain an object. We have to decide what we want to do here.

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.

In order to not get this PR hung up by the reverting of the aliasing feature, lets keep the aliasing for now and lets try to reach consensus separately on what we want to do about the possibility of allowing embedded foreign objects.

Without the removal of aliasing, I think this PR can me approved and merged.

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! Awesome work! I love that we now have this implemented.

If you don't mind just adding the 1.22 reference as mentionned by Shahzad before merging.

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.

Sorry just reviewing, thanks for adding alias stuff back. I am mid review will appreciate if possible to wait for me to finish.

// Explain method returns a map containing all attributes of this node that
// are to be explained, subscribes / opts-in this node to be an explainablePlanNode.
func (n *createNode) Explain(explainType request.ExplainType) (map[string]any, error) {
switch explainType {
case request.SimpleExplain:
return n.simpleExplain()
return map[string]any{
dataLabel: n.input,
Copy link
Member

Choose a reason for hiding this comment

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

todo: the name dataLabeldoesn't make sense anymore. Please change to inputLabel

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.

Cheers for this PR! I like it a lot! Left some var renaming todos and in addition have this todo:

In planner/explain.go file we have on line 56:

dataLabel           = "data"

After renaming the variable please don't forget to change the value from"data" to "input".

OR if you want to use request.Input in all those instances and just remove the dataLabel/inputLabel , I am okay with that too :)

@@ -21,6 +21,7 @@ const (

Cid = "cid"
Data = "data"
Copy link
Member

Choose a reason for hiding this comment

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

todo: Please delete this Data variable now, it is now not used anywhere.

return nil, err
}
simpleExplainMap[dataLabel] = data
simpleExplainMap[dataLabel] = n.input
Copy link
Member

Choose a reason for hiding this comment

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

todo: Similar to other suggestions please change the variable name to be more relevant.

Suggested change
simpleExplainMap[dataLabel] = n.input
simpleExplainMap[inputLabel] = n.input

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.

Cheers for doing all the todos!

@nasdf nasdf merged commit 72732f3 into sourcenetwork:develop Jan 11, 2024
26 of 27 checks passed
@fredcarle fredcarle added this to the DefraDB v0.9 milestone Jan 12, 2024
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Jan 22, 2024
## Relevant issue(s)

Resolves sourcenetwork#2143 

## Description

This PR adds a typed input object for create and update mutations.

~~As a side effect of this change the relationship alias has been
replaced with the `<type>_id` input field.~~

Relational sub-documents cannot be created from mutation input in this
implementation.

Related SIP sourcenetwork/SIPs#10

## 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)).
- [x] 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?

Make test

Specify the platform(s) on which this was tested:
- MacOS
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#2143 

## Description

This PR adds a typed input object for create and update mutations.

~~As a side effect of this change the relationship alias has been
replaced with the `<type>_id` input field.~~

Relational sub-documents cannot be created from mutation input in this
implementation.

Related SIP sourcenetwork/SIPs#10

## 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)).
- [x] 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?

Make test

Specify the platform(s) on which this was tested:
- MacOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/parser Related to the parser components area/query Related to the query component feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mutation typed field parameters
3 participants