DQL and GraphQL


I got some question about using GraphQL on an existing DGraph :

I’am looking to use both DQL and GraphQL in my project but i have some issue and i’m not sure to understand what is going on.

Let’s say i add a schema using DQL and add the same Schema on the /admin/schema endpoint they should be the “same” right ?

But if i add data using DQL Mutation i can’t query those using GraphQL i’m not sure to unterstand why ?

On the other side if i add data using GraphQL i can see those using DQL ?

Do i have to add custom query to the GraphQL so i can query data created by DQL ?
Or did i misunderstood something ?

Thanks by advance for your help ! :+1:

Hey Grégoire, welcome.

It is perfectly possible to use both, but I would recommend that you plan your Graph Model in GraphQL primarily. Because GraphQL works differently than DQL, it has its own rules and model.

Starting from the idea that you intend to use both languages simultaneously. The main recommendation is to create your Schema in GraphQL only, and it will be automatically created on the DQL side normally. Do not create in one and try to recreate in the other. It can conflict things.

And no, they aren’t the same. GraphQL follows its own way of modeling, naming predicates, and so on. It is an internal “convention” just for GraphQL.

To add data via DQL mutation you have to follow the GraphQL modeling. For example, let’s take the predicate “name”. In GraphQL the predicate has a “prefix” based on its Type. Let’s say that this predicate is part of the “User” type. So in the DQL part, it will be “User.name”. Basicaly all predicates in the DQL part will be named as “${typeAsPrefix}+${predicateName}”.

Yes, just follow the internal “convention”.



This GraphQL query

query {
  queryReview(filter: { comment: {alloftext: "Fantastic"}}) {
    by {
    about {

Will be in DQL

  queryReview(func: alloftext(comment, "Fantastic") ) {
    Review.by {
    Review.about {

PS. You can migrate an existing DQL model to GraphQL using upsert block.


Thanks !

So i erase all my data and add the schema using GraphQL this time :
And start again but the same thing is happening :

i will be really grateful if you take some time to help me out :slight_smile:

Let’s say i have the following Schema :

type WebShow{
    id : ID!
    Nom : String! @id @search
    Saisons : [Saison]
    UrlImg : String
    DateAjout : String @search
    AverageRating : Float
    AverageLength : Float
    NmbrEpisode : Int
    Synopsis : String
    Trailer : String

type Saison{

It will result in the DQL with predicates like this

And so on

if i add some data using DQL JSON Mutation as follow

    "WebShow.DateAjout" :""

I should be able to query using the GraphQL query generated by Dgraph ?
Like so :

query {
    getWebShow(Nom : "anAwsomeName" ){
But i

t seems i’m not able to make it worked !

Did i misunderstood about what you say before ?

Or the issue is comming from my “code”(DQL JSON Mutation or My GraphQL Query)

Thanks for your time !

Don’t forget to add the dgraph.type e.g:

    "WebShow.Nom":" anAwsomeName",
    "WebShow.DateAjout" : "",
    "dgraph.type" : "WebShow"

If you don’t use it, Dgraph won’t be able to tell you where it belongs or not.

Yes, if you don’t forget the “dgraph.type”.

1 Like

Oh that’s much better now :smile:
Thanks for the help !

1 Like

Glad it worked for you!
Happy hacking! If you need more help just ping us.


1 Like