Skip to content

fix(GraphQL): Linking of xids for deep mutations #6172

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

Merged
merged 8 commits into from
Aug 17, 2020

Conversation

pawanrawal
Copy link
Contributor

@pawanrawal pawanrawal commented Aug 13, 2020

For nested add mutations, the linking of nodes for xids wasn't working properly. Level 1 and 2 are linked properly but level 2 and beyond were not. This PR aims to fix that.
See https://discuss.dgraph.io/t/grandchild-is-not-attached-to-child-when-using-addtype/9224 for more details.

TODO

  • Needs more testing for different combination of deeply nested id and xids.

This change is Reviewable

Docs Preview: Dgraph Preview

@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Aug 13, 2020
Copy link
Contributor

@harshil-goel harshil-goel left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 5 unresolved discussions (waiting on @pawanrawal)


graphql/resolve/mutation_rewriter.go, line 987 at r1 (raw file):

	var parentFrags []*mutationFragment

	// TODO - Find out when is withAdditionalDeletes true?

it's true when you do a "set" update mutation or add mutation.


graphql/resolve/mutation_rewriter.go, line 996 at r1 (raw file):

			if deepXID > 2 {
				// TODO - Find out why do we do this only when deepXID > 2. Also, this check can be
				// moved above with the xid != nil check.

We don't have to do this for if deepXID is 1, as it is a part of firstPass itself, no need to create new frags.


graphql/resolve/mutation_rewriter.go, line 1107 at r1 (raw file):

			res := make(map[string]interface{}, 1)
			res["uid"] = srcUID
			this := fmt.Sprintf("_:%s", variable)

Can we reuse addInverseLink function? That would check if parentTyp is nil too.


graphql/resolve/mutation_rewriter.go, line 1109 at r1 (raw file):

			this := fmt.Sprintf("_:%s", variable)
			if srcField.Type().ListType() != nil {
				res[parentTyp.DgraphPredicate(srcField.Name())] =

parentTyp can be nil, can cause an error.


graphql/resolve/mutation_rewriter.go, line 1115 at r1 (raw file):

					map[string]interface{}{"uid": this}
			}
			// addInverseLink(res, srcField.Inverse(), this)

No need.

@pawanrawal pawanrawal marked this pull request as ready for review August 17, 2020 08:42
Copy link
Contributor

@abhimanyusinghgaur abhimanyusinghgaur left a comment

Choose a reason for hiding this comment

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

We should add some e2e test for this too. Maybe a 4 level deep mutation with xids, and lists of xids with multiple children in each list, and hasInverses.

Reviewed 1 of 3 files at r1, 2 of 2 files at r2.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @MichaelJCompton and @pawanrawal)


graphql/resolve/add_mutation_test.yaml, line 2280 at r2 (raw file):

- setjson: |
        {"uid":"uid(Comment16)"}
      cond: "@if(eq(len(Comment16), 1) AND eq(len(Comment14), 0))"

This condition seems repetitive, but doesn't seem to do anything anyways.

Copy link
Contributor Author

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

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

I'll add the e2e tests in a separate PR.

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @abhimanyusinghgaur, @harshil-goel, and @MichaelJCompton)


graphql/resolve/add_mutation_test.yaml, line 2280 at r2 (raw file):

Previously, abhimanyusinghgaur (Abhimanyu Singh Gaur) wrote…
- setjson: |
        {"uid":"uid(Comment16)"}
      cond: "@if(eq(len(Comment16), 1) AND eq(len(Comment14), 0))"

This condition seems repetitive, but doesn't seem to do anything anyways.

Yeah, will have to have a look at it separately and if we can avoid it.


graphql/resolve/mutation_rewriter.go, line 987 at r1 (raw file):

Previously, harshil-goel (Harshil Goel) wrote…

it's true when you do a "set" update mutation or add mutation.

Done.


graphql/resolve/mutation_rewriter.go, line 996 at r1 (raw file):

Previously, harshil-goel (Harshil Goel) wrote…

We don't have to do this for if deepXID is 1, as it is a part of firstPass itself, no need to create new frags.

Done.


graphql/resolve/mutation_rewriter.go, line 1107 at r1 (raw file):

Previously, harshil-goel (Harshil Goel) wrote…

Can we reuse addInverseLink function? That would check if parentTyp is nil too.

Done.


graphql/resolve/mutation_rewriter.go, line 1109 at r1 (raw file):

Previously, harshil-goel (Harshil Goel) wrote…

parentTyp can be nil, can cause an error.

Done.


graphql/resolve/mutation_rewriter.go, line 1115 at r1 (raw file):

Previously, harshil-goel (Harshil Goel) wrote…

No need.

Done.

@pawanrawal pawanrawal merged commit 806a8df into master Aug 17, 2020
@pawanrawal pawanrawal deleted the pawanrawal/three-level-deep-xid branch August 17, 2020 11:08
pawanrawal added a commit that referenced this pull request Aug 17, 2020
For nested add mutations, the linking of nodes for xids wasn't working properly. Level 1 and 2 are linked properly but level 2 and beyond were not. This PR aims to fix that.
See https://discuss.dgraph.io/t/grandchild-is-not-attached-to-child-when-using-addtype/9224 for more details.

(cherry picked from commit 806a8df)
pawanrawal added a commit that referenced this pull request Aug 17, 2020
For nested add mutations, the linking of nodes for xids wasn't working properly. Level 1 and 2 are linked properly but level 2 and beyond were not. This PR aims to fix that.
See https://discuss.dgraph.io/t/grandchild-is-not-attached-to-child-when-using-addtype/9224 for more details.

(cherry picked from commit 806a8df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/graphql Issues related to GraphQL support on Dgraph.
Development

Successfully merging this pull request may close these issues.

3 participants