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 internal Aliases name generation #7009

Merged
merged 2 commits into from
Dec 14, 2020

Conversation

minhaj-shakeel
Copy link
Contributor

@minhaj-shakeel minhaj-shakeel commented Nov 27, 2020

This PR modifies how the internal graph aliases are generated in case of multiple aliases of same field in the query.
For the given graphql query:

query {
      queryAuthor {
        name
        p1: posts(filter: {isPublished: true}){
          title
          text
        }
        p2: posts(filter: {isPublished: true}){
          title
          text
        }
      }
    }

earlier it was rewritten into:

query {
      queryAuthor(func: type(Author)) {
        name : Author.name
        posts : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        posts1 : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }

Now it is changed to:

query {
      queryAuthor(func: type(Author)) {
        name : Author.name
        posts : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        posts.1 : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }

Notice that new alias for second posts query is posts.1 instead of posts1. This is done to avoid issues in case if the Author have any field named posts1. Now posts.1 cannot be a field of Author as it results in a syntax error.


This change is Reviewable

@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Nov 27, 2020
@netlify
Copy link

netlify bot commented Nov 27, 2020

Deploy preview for dgraph-docs ready!

Built with commit 5fa1c59

https://deploy-preview-7009--dgraph-docs.netlify.app

@minhaj-shakeel minhaj-shakeel changed the title feat fix(GraphQL): fix internal Aliases name generation Nov 27, 2020
@minhaj-shakeel minhaj-shakeel merged commit 953f656 into master Dec 14, 2020
@minhaj-shakeel minhaj-shakeel deleted the minhaj/modify-unique-alias-generation branch December 14, 2020 05:29
abhimanyusinghgaur added a commit that referenced this pull request Dec 14, 2020
The test broke after merging #7009 in master.
abhimanyusinghgaur pushed a commit that referenced this pull request Dec 14, 2020
This PR modifies how the internal graph aliases are generated in case of multiple aliases of same field in the query.
For the given graphql query:
```
query {
      queryAuthor {
        name
        p1: posts(filter: {isPublished: true}){
          title
          text
        }
        p2: posts(filter: {isPublished: true}){
          title
          text
        }
      }
    }
```
earlier it was rewritten into:
```
query {
      queryAuthor(func: type(Author)) {
        name : Author.name
        posts : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        posts1 : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }
```
Now it is changed to:
```
query {
      queryAuthor(func: type(Author)) {
        name : Author.name
        posts : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        posts.1 : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }
```

(cherry picked from commit 953f656)
abhimanyusinghgaur added a commit that referenced this pull request Dec 14, 2020
The test broke after merging #7009 in master.

(cherry picked from commit 09274fb)
abhimanyusinghgaur added a commit that referenced this pull request Dec 14, 2020
* fix(GraphQL): fix internal Aliases name generation (#7009)

This PR modifies how the internal graph aliases are generated in case of multiple aliases of same field in the query.
For the given graphql query:
```
query {
      queryAuthor {
        name
        p1: posts(filter: {isPublished: true}){
          title
          text
        }
        p2: posts(filter: {isPublished: true}){
          title
          text
        }
      }
    }
```
earlier it was rewritten into:
```
query {
      queryAuthor(func: type(Author)) {
        name : Author.name
        posts : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        posts1 : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }
```
Now it is changed to:
```
query {
      queryAuthor(func: type(Author)) {
        name : Author.name
        posts : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        posts.1 : Author.posts @filter(eq(Post.isPublished, true)) {
          title : Post.title
          text : Post.text
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }
```

(cherry picked from commit 953f656)

* chore: fix a broken test (#7130)

The test broke after merging #7009 in master.

(cherry picked from commit 09274fb)

Co-authored-by: minhaj-shakeel <minhaj@dgraph.io>
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