Apply dgraph directives directly in the GraphQL schema

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:

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

schema patch to traverse the graph from Text to Person:

<Person .name>: uid @reverse .

Possible clean solution

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

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:

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

would error out because

When used at the query root, the count index is required.

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

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/

1 Like

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.