Skip to content

Allow directives without a Go visitor counterpart #588

Closed
@pavelnikolov

Description

@pavelnikolov

There might directives that are there just for decorative purposes to be used by generators or schema validators but not by the GraphQL server at runtime. Therefore, the library should allow arbitrary directives to be added to the GraphQL (i.e. SDL) schema and they should be ignored if there isn't a Go visitor counterpart registered for some of them. Currently if there is a directive without a Go visitor counterpart, for example, in this schema:
```graphql
directive @awesome on FIELD_DEFINITION

type Query {
    hello: String! @awesome
}
```
the following error is returned:
```
panic: no visitors have been registered for directive "awesome" [recovered]
  panic: no visitors have been registered for directive "awesome"
```
Maybe there needs to be a schema option to define the behavior, for example, `graphql.AllowDirectivesWithoutVisitors()` or `graphql.DisallowDirectivesWithoutVisitors()`.
An example of a directive which might need that is the `@key` directive added on `FIELD_DEFINITION` which shows the primary key of an object. It will be used by code generation tools, other directives or a super graph. However, the server would generally ignore this directive so it doesn't need to define a visitor for it.
Another idea to solve this problem is to require visitors for all directives except of a list of special directive exceptions, e.g. `graphql.DirectivesWithoutVisitors("key", "awesome")` etc.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions