I get different results for the same query in DQL and graphql

On Dgraph I get different results for queries, that should return the same result.
For the DQL Query

{
  user(func: has(name))  {
    name
    email
  }
}

I get the response

{2 items
data:{1 item
user:[2 items
0:{2 items
name:"Bastin"
email:"paintgun_test@current.com"
}
1:{2 items
name:"Bastin"
email:"paintgun_test@current.com"
}
]
}
extensions:{3 items
server_latency:{5 items
parsing_ns:73296
processing_ns:1964700
encoding_ns:51482
assign_timestamp_ns:1213398
total_ns:3435353
}
txn:{2 items
start_ts:47868611
hash:"532c654fd0f4ebc463460b3e6dddc444ced5f5fc95037caaca0d0c86865ed536"
}
metrics:{1 item
num_uids:{3 items
_total:4
email:2
name:2
}
}
}
}

For the graphql query:

query MyQuery {
  queryUser {
    name
    email
    id
    spaces {
      id
    }
  }
}

I get

{
  "data": {
    "queryUser": [
      {
        "name": "Bastin",
        "email": "Bastin@we.be",
        "id": "0x1a4c4ba7c0",
        "spaces": []
      }
    ]
  },
  "extensions": {
    "touched_uids": 4,
    "tracing": {
      "version": 1,
      "startTime": "2023-04-08T20:18:51.654328696Z",
      "endTime": "2023-04-08T20:18:51.655804953Z",
      "duration": 1476212,
      "execution": {
        "resolvers": [
          {
            "path": [
              "queryUser"
            ],
            "parentType": "Query",
            "fieldName": "queryUser",
            "returnType": "[User]",
            "startOffset": 187532,
            "duration": 1284447,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 232491,
                "duration": 1237743
              }
            ]
          }
        ]
      }
    }
  }
}

I also donā€™t see the other 2 users in

If you wanna work with DQL in your GraphQL Graph Model. You have to prefix all predicates with the Type of the object. For example. The Type is User in GraphQL. Right? All new entries in the DQL side, whether submitted via RDF or JSON, must have the prefix ā€˜Userā€™.

e.g:

{
     User.name: "Bastin"
     User.email: "paintgun_test@current.com"
}

I have a User Type, yes.
How would the GraphQL query look like?
And why donā€™t I get the user with ā€œemailā€: ā€œBastin@we.beā€ in the DQL Query?

It doesnā€™t. The prefix is due to GraphQL Graph modeling. If you insert some data via GraphQL, you have to use the prefix in the DQL side. Cuz GraphQL add them to the data(node).

Cuz your query should be like

{
  user(func: has(User.name))  {
    User.name
    User.email
  }
}
1 Like

Have a look at the GraphQL - DQL interoperability doc at GraphQL and DQL schemas - GraphQL dql it should help you to understand how Dgraph stores predicates for a GraphQL schema.

There are some points of attention. First how your data has been created. If you used data import or DQL mutations to populate the graph that you want to use with a GraphQL API, be sure that each node has a dgraph.type predicate with the correct GraphQL type name and that node predicates are created as Michel explained.
Let us know if you managed to get your data correctly created. Happy to help further if needed.

1 Like