# How to reference types in DQL schema definition?

**URL:** <https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042>\
**Category:** Dgraph\
**Tags:** schema, dql\
**Created:** [October 20, 2020, 4:54pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042 "2020-10-20T16:54:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tron](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tron/32/5155_2.png) [@tron](https://discuss.dgraph.io/u/tron)\
**Post date:** [October 20, 2020, 4:54pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042/1 "2020-10-20T16:54:17Z")

</div>

Suppose my DQL schema has two nodes with a `name` predicate…

```auto
type User {
  name
}

type Pet {
  name
}

```

Many examples in the Dgraph documentation define a single index that is shared between types:

```auto
name: string @index(hash) .

```

So how would I declare a `hash` index for `User.name` and a `term` index for `Pet.name`? My first thought was to try this…

```auto
User.name: string @index(hash) .
Pet.name: string @index(term) .

```

…but the `/alter` endpoint returns an error:

```auto
Schema does not contain a matching predicate for field name in type User

```

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [October 20, 2020, 5:28pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042/2 "2020-10-20T17:28:03Z")

</div>

> [@tron](#):
>
> …but the `/alter` endpoint returns an error:

Cuz your schema needs to be like this

```auto
type User {
  User.name
}

type Pet {
  Pet.name
}

User.name: string @index(hash) .
Pet.name: string @index(term) .

```

DQL Schema is different from GraphQL Schema. In GraphQL this pattern comes automatically, in DQL you have to do it manually.

---

<div class="post-metadata">

**Author:** ![tron](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tron/32/5155_2.png) [@tron](https://discuss.dgraph.io/u/tron)\
**Post date:** [October 20, 2020, 5:47pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042/3 "2020-10-20T17:47:35Z")

</div>

Thank you, @MichelDiz. That worked perfectly.

For anyone else that may find this post helpful, it’s noteworthy to point out that the above schema doesn’t require `User.name` as the predicate in queries—you just use `name`:

```auto
{
  user(func: type(User)) {
    name // User.name doesn't work here
  }
}

```

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [October 20, 2020, 6:00pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042/4 "2020-10-20T18:00:16Z")

</div>

> [@tron](#):
>
> For anyone else that may find this post helpful, it’s noteworthy to point out that the above schema doesn’t require `User.name` as the predicate in queries—you just use `name` :

I think something is off here then. If I want to access my GraphQL schema (without any mapped predicates) values I have to use the type dotted notation in DQL. In other words, for me it is opposite:

```auto
{
  user(func: type(User)) {
    User.name // name doesn't work here
  }
}

```

---

<div class="post-metadata">

**Author:** ![tron](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tron/32/5155_2.png) [@tron](https://discuss.dgraph.io/u/tron)\
**Post date:** [October 20, 2020, 6:12pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042/5 "2020-10-20T18:12:20Z")

</div>

> I think something is off here then.

You’re right, I made a mistake. I inadvertently created a user on the mutate tab of Ratel like this:

```auto
{
  set {
    _:user <dgraph.type> "User" .
    _:user <name> "Tron" .
  }
}

```

This is what I should have done:

```auto
{
  set {
    _:user <dgraph.type> "User" .
    _:user <User.name> "Tron" .
  }
}

```

Sorry for the confusion. I’m still trying to get my Dgraph sea legs.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [October 20, 2020, 6:23pm UTC](https://discuss.dgraph.io/t/how-to-reference-types-in-dql-schema-definition/11042/6 "2020-10-20T18:23:38Z")

</div>

oh, yes, I imported 7 million quads of data and then realized I made a similar mistake 😬

It is good to see someone else using both graphql and DQL together. I will watch you for any future topics.
