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 custom(dql: ...) with __typename (GRAPHQL-1098) #7569

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

abhimanyusinghgaur
Copy link
Contributor

@abhimanyusinghgaur abhimanyusinghgaur commented Mar 15, 2021

This PR fixes the working of @custom(dql: ...) with __typename and fragments.

Bug Description:

  1. Apply GraphQL schema:
interface Node {
 id: ID!
}
type User implements Node {
 name: String
}
type Token implements Node {
 key: String
}
type Query {
 queryNodeR: [Node] @custom(dql: """
  query {
   queryNodeR(func: type(Node)) {
     dgraph.type
     id: uid
     name: User.name
     key: Token.key
   }
  } """)
}
  1. Add data:
mutation {
 addUser(input: [{name: "User1"}]) {numUids}
 addToken(input: [{key: "Token1"}]) {numUids}
}
  1. Query with both the auto-generated and the custom query and see the difference:
query {
 queryNode {
 id
 __typename
 ... UserFrag
 ... TokenFrag
 }
 queryNodeR {
 id
 __typename
 ... UserFrag
 ... TokenFrag
 }
}
fragment UserFrag on User {
 name
}
fragment TokenFrag on Token {
  key
}
  1. The response being returned was:
{
  "data": {
    "queryNode": [
      {
        "id": "0x2",
        "__typename": "User",
        "name": "User1"
      },
      {
        "id": "0x3",
        "__typename": "Token",
        "key": "Token1"
      }
    ],
    "queryNodeR": [
      {
        "id": "0x2",
        "__typename": "Node",
        "name": "User1",
        "key": null
      },
      {
        "id": "0x3",
        "__typename": "Node",
        "name": null,
        "key": "Token1"
      }
    ]
  }
}

queryNodeR should have had the same result as queryNode.


This change is Reviewable

@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Mar 15, 2021
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

@abhimanyusinghgaur abhimanyusinghgaur merged commit ac0aa76 into release/v21.03 Mar 15, 2021
@abhimanyusinghgaur abhimanyusinghgaur deleted the abhimanyu/custom-dql-fix branch March 15, 2021 13:15
aman-bansal pushed a commit that referenced this pull request Mar 16, 2021
)

This PR fixes the working of `@custom(dql: ...)` with `__typename` and fragments.

Bug Description:
1. Apply GraphQL schema:
```
interface Node {
 id: ID!
}
type User implements Node {
 name: String
}
type Token implements Node {
 key: String
}
type Query {
 queryNodeR: [Node] @Custom(dql: """
  query {
   queryNodeR(func: type(Node)) {
     dgraph.type
     id: uid
     name: User.name
     key: Token.key
   }
  } """)
}
```
2. Add data:
```
mutation {
 addUser(input: [{name: "User1"}]) {numUids}
 addToken(input: [{key: "Token1"}]) {numUids}
}
```
3. Query with both the auto-generated and the custom query and see the difference:
```
query {
 queryNode {
 id
 __typename
 ... UserFrag
 ... TokenFrag
 }
 queryNodeR {
 id
 __typename
 ... UserFrag
 ... TokenFrag
 }
}
fragment UserFrag on User {
 name
}
fragment TokenFrag on Token {
  key
}
```
4. The response being returned was:
```
{
  "data": {
    "queryNode": [
      {
        "id": "0x2",
        "__typename": "User",
        "name": "User1"
      },
      {
        "id": "0x3",
        "__typename": "Token",
        "key": "Token1"
      }
    ],
    "queryNodeR": [
      {
        "id": "0x2",
        "__typename": "Node",
        "name": "User1",
        "key": null
      },
      {
        "id": "0x3",
        "__typename": "Node",
        "name": null,
        "key": "Token1"
      }
    ]
  }
}
```

`queryNodeR` should have had the same result as `queryNode`.
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