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): multiple queries in a single request should not share the same variables (#5953) #6158

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

abhimanyusinghgaur
Copy link
Contributor

@abhimanyusinghgaur abhimanyusinghgaur commented Aug 11, 2020

Fixes GraphQL-570.

Earlier, sending a query like this:

query ($filter: CountryFilter!){
  qc0: queryCountry(filter: $filter) {
    id
    name
  }
  qc1: queryCountry(filter: $filter) {
    id
    name
  }
}

where $filter is a GraphQL variable as below:

{
	"filter": {
		"id": [
			"0x0"
		]
	}
}

would fetch you results like this:

"data": {
    "qc0": [
      {
        "id": "0x2711",
        "name": "India"
      },
      {
        "id": "0x2712",
        "name": "Australia"
      },
      {
        "id": "0x2713",
        "name": "US"
      }
    ],
    "qc1": []
  }

While you should have got empty results for both the queries as 0x0 is not a uid that exists.

This PR fixes the above bug by doing a deep-copy of field arguments if variables are provided, so avoiding sharing the same memory address across all the queries in a request. Hence, avoiding any bugs that could be caused as a result of modification of that shared memory address.

(cherry picked from commit 58e90aa)


This change is Reviewable

Docs Preview: Dgraph Preview

…he same variables (#5953)

Fixes GraphQL-570.

Earlier, sending a query like this:
```
query ($filter: CountryFilter!){
  qc0: queryCountry(filter: $filter) {
    id
    name
  }
  qc1: queryCountry(filter: $filter) {
    id
    name
  }
}
```
where $filter is a GraphQL variable as below:
```
{
	"filter": {
		"id": [
			"0x0"
		]
	}
}
```
would fetch you results like this:
```
"data": {
    "qc0": [
      {
        "id": "0x2711",
        "name": "India"
      },
      {
        "id": "0x2712",
        "name": "Australia"
      },
      {
        "id": "0x2713",
        "name": "US"
      }
    ],
    "qc1": []
  }
```
While you should have got empty results for both the queries as `0x0` is not a uid that exists.

This PR fixes the above bug by doing a deep-copy of field arguments if variables are provided, so avoiding sharing the same memory address across all the queries in a request. Hence, avoiding any bugs that could be caused as a result of modification of that shared memory address.

(cherry picked from commit 58e90aa)
@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Aug 11, 2020
Copy link
Contributor

@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.

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @manishrjain, @MichaelJCompton, and @vvbalaji-dgraph)

@abhimanyusinghgaur abhimanyusinghgaur merged commit 80e85ab into release/v20.07 Aug 11, 2020
@abhimanyusinghgaur abhimanyusinghgaur deleted the abhimanyu/cherry-pick1 branch August 11, 2020 15:54
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.

2 participants