# Apply dgraph directives directly in the GraphQL schema

**URL:** <https://discuss.dgraph.io/t/apply-dgraph-directives-directly-in-the-graphql-schema/9387>\
**Category:** GraphQL\
**Created:** [August 12, 2020, 4:06pm UTC](https://discuss.dgraph.io/t/apply-dgraph-directives-directly-in-the-graphql-schema/9387 "2020-08-12T16:06:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luscha](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/luscha/32/3588_2.png) [@Luscha](https://discuss.dgraph.io/u/Luscha)\
**Post date:** [August 12, 2020, 4:06pm UTC](https://discuss.dgraph.io/t/apply-dgraph-directives-directly-in-the-graphql-schema/9387/1 "2020-08-12T16:06:34Z")

</div>

I think it is quite common to have to patch the schema generated by GraphQL with some dgraph internal directives.  
The most simple case is adding the reverse directive to an edge.

Right now I think the only way is to have a separate file with all the patches and apply it after the push of the GraphQL Schema.

Although it’s not much effort I was wondering if you have already thought to a possible built-in solution.  
Example:

```auto
type Person {
   name: Text!
}
type Text {
   string: String!
}

```

schema patch to traverse the graph from Text to Person:

```auto
<Person .name>: uid @reverse .

```

Possible clean solution

```auto
type Person {
   name: Text! @dgraphDirective([reverse])
}
type Text {
   string: String!
}

```

---

<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:** [August 12, 2020, 4:18pm UTC](https://discuss.dgraph.io/t/apply-dgraph-directives-directly-in-the-graphql-schema/9387/2 "2020-08-12T16:18:11Z")

</div>

Use Case:

Now that DQL can be executed on Slash endpoint, but I have to modify the schema through graphql, there is no way to do this:

```auto
{
  directors(func: gt(count(director.film), 5)) {
    totalDirectors : count(uid)
  }
}

```

would error out because

> When used at the query root, the [count index](https://dgraph.io/docs/query-language/count/#count-index) is required.

But I have no way of adding that count index. Hmm…

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [December 14, 2020, 7:44am UTC](https://discuss.dgraph.io/t/apply-dgraph-directives-directly-in-the-graphql-schema/9387/3 "2020-12-14T07:44:41Z")

</div>

Hey @amaster507

Did you figure out a way to achieve what you were looking for here?

@Luscha

Have you looked at the `@dgraph` directive and does that work for you? [https://dgraph.io/docs/master/graphql/dgraph/](https://dgraph.io/docs/master/graphql/dgraph/)

---

<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:** [December 14, 2020, 8:02pm UTC](https://discuss.dgraph.io/t/apply-dgraph-directives-directly-in-the-graphql-schema/9387/4 "2020-12-14T20:02:21Z")

</div>

I was trying to find a work around to get counts. Now that we have the GraphQL count aggregate queries and fields, that work around is no longer needed. I never spent too much time on it, this was before users could modify the Slash Dgraph schema which is allowed now depending on Slash mode.
