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): fix duplicate xid error for multiple xid fields. #7546

Merged
merged 2 commits into from
Mar 11, 2021

Conversation

JatinDev543
Copy link
Contributor

@JatinDev543 JatinDev543 commented Mar 11, 2021

We were getting duplicate xid error for the multiple xid fields if typeName+xidName+xidValue is same for those fields. The reason for this is that we need to generate unique query variables for the xids field while doing mutation rewriting and for that we use a map to variable names.
we were using below key for that map
key = typ.FieldOriginatedFrom(xidName) + xidName + xidVal
This was generating same key for different xid fields. For example in below type we have two fields with id fields

type ABC {
    ab: String! @id
    abc: String! @id
}

And below mutation try to set them such that key = typ.FieldOriginatedFrom(xidName) + xidName + xidVal will be same for both of them i.e. ABC+ab+cd=ABC+abc+d=ABCabcd

mutation {
		addABC(input: [{ ab: "cd", abc: "d" }]) {
		  aBC {
		        ab
		        abc
		       }
		  }
	 }

This error also occur in multiple types.
We now added "." between values to separate typename and xidname , and the xidValue.This will ensure unique keys for xid fields across types.
key = typ.FieldOriginatedFrom(xidName) + "." + xidName + "." + xidVal


This change is Reviewable

@JatinDev543 JatinDev543 requested a review from pawanrawal as a code owner March 11, 2021 05:28
@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Mar 11, 2021
// }
// }
// }
// The two generated kes for this case will be
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Copy link
Contributor

@vmrajas vmrajas left a comment

Choose a reason for hiding this comment

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

LGTM.
Nicely written tests covering a wide range of cases.

@JatinDev543 JatinDev543 changed the title added fix for duplicate xid error and tests fix(GRAPHQL): fix duplicate xid error for multiple xid fields. Mar 11, 2021
@JatinDev543 JatinDev543 merged commit 5c700d0 into release/v21.03 Mar 11, 2021
@JatinDev543 JatinDev543 deleted the jatin/GRAPHQL-1080 branch March 11, 2021 11:56
aman-bansal pushed a commit that referenced this pull request Mar 15, 2021
We were getting duplicate xid error for the multiple xid fields if typeName+xidName+xidValue is same for those fields. The reason for this is that we need to generate unique query variables for the xids field while doing mutation rewriting and for that we use a map to variable names.
we were using below key for that map
key = typ.FieldOriginatedFrom(xidName) + xidName + xidVal
This was generating same key for different xid fields. For example in below type we have two fields with id fields

type ABC {
    ab: String! @id
    abc: String! @id
}
And below mutation try to set them such that key = typ.FieldOriginatedFrom(xidName) + xidName + xidVal will be same for both of them i.e. ABC+ab+cd=ABC+abc+d=ABCabcd

mutation {
		addABC(input: [{ ab: "cd", abc: "d" }]) {
		  aBC {
		        ab
		        abc
		       }
		  }
	 }
This error also occur in multiple types.
We now added "." between values to separate typename and xidname , and the xidValue.This will ensure unique keys for xid fields across types.
key = typ.FieldOriginatedFrom(xidName) + "." + xidName + "." + xidVal
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