graphqlschemadirectivedgraph

Dgraph - graphql where are described the directives on schema?


With the recent support of native GraphQL, dgraph introduced the use of @hasInverse and @search directives. When I write my schema in my editor, the linter warns me about those unknown directive.

enter image description here (Unknown directive "search" and Unknown directive "hasInverse")

I therefore described the directives in a file directive.schema as follow:

enum SearchTypes {
    hash,
    exact,
    regexp,
    term,
    fulltext
}

directive @search(by: [SearchTypes]) on FIELD_DEFINITION
directive @hasInverse(field: __EnumValue) on FIELD_DEFINITION
type DateTime

And the errors are gone… however, I am not very satisfied in redefining directives that may be already provided by dgraph. They can be error prone.

Is there any better alternative to this?


Solution

  • edit : this has now been added to our docs https://graphql.dgraph.io/docs/schema/#schemafragment

    (Michael on of Dgraph's GraphQL developers here. Thanks for the question.)

    Sorry, that's not a great developer experience. We'll be trying to improve that.

    What editor and graphql plug-ins are you using for your schema? Does it have some support to include another file? If so we can publish our base schema and you can include it.

    Otherwise, you have to paste in the required parts much like you've done.