1

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?

Flavien Volken
  • 19,196
  • 12
  • 100
  • 133

1 Answers1

2

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.

  • I am using Webstorm with [a graphql plugin](https://plugins.jetbrains.com/plugin/8097-js-graphql/). The plugin relies on a `.graphqlconfig`, without any settings, the graphql namespace will use the glob `./**/*.graphql` relative to the `.graphqlconfig` file. We can therefore just put a `dgraph.graphql` aside of the `schema.graphql` and it works like a charm. Now if the dgraph team could could provide an official `dgraph.graphql` file it would be even better. – Flavien Volken Nov 04 '19 at 19:43