GraphQL query working but DQL not

What I want to do

Use DQL instead of GraphQL in my frontend because of GraphQL’s limitations.
But when using DQL, I only get empty data.

What I did

schema.graphql

type ItemInterface {
    name: String! @id @search(by: [fulltext])
}
type Item {
    _: Int
}

Working GraphQL query at localhost:8080/graphql

query {
  getItem(name: "test") {
    name
  }
}

Returns

{
  "data": {
    "getItem": {
      "name": "test"
    }
}

Not working DQL query at localhost:8080/query

curl -H "Content-Type: application/dql" -X POST localhost:8080/query -d $'
{
  items(func: anyofterms(name, "test")) {
    Item.name
  }
}' | python -m json.tool | less

Returns

{
    "data": {
        "items": []
    }
}

I have tried it with func: eq, with ItemInterface.name instead of Item.name. Nothing works.

Dgraph metadata

dgraph version

Dgraph version : v21.03.0
Dgraph codename : rocket
Dgraph SHA-256 : b4e4c77011e2938e9da197395dbce91d0c6ebb83d383b190f5b70201836a773f
Commit SHA-1 : a77bbe8ae
Commit timestamp : 2021-04-07 21:36:38 +0530
Branch : HEAD
Go version : go1.16.2
jemalloc enabled : true

For Dgraph official documentation, visit https://dgraph.io/docs.
For discussions about Dgraph , visit http://discuss.dgraph.io.
For fully-managed Dgraph Cloud , visit Dgraph Cloud - Fully-managed database-as-a-service - Native GraphQL graph database in the cloud.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2021 Dgraph Labs, Inc.

Edit: Commands used to run Dgraph

dgraph zero --my=127.0.0.1:5080

dgraph alpha --my=127.0.0.1:7080 --zero=127.0.0.1:5080
dgraph alpha --my=127.0.0.1:7081 --zero=127.0.0.1:5080 -o=1

For this case the query should be like

{
  items(func: anyofterms(ItemInterface.name, "test")) {
    ItemInterface.name
  }
}
1 Like