graphql-go / graphql-go/graphql

Create custom directives

Open
#315 12 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

Is there a way to create custom directives? I was looking to implement authentication using directives by following this [blog post](https://blog.graph.cool/graphql-directive-permissions-authorization-made-easy-54c076b5368e), but could not figure out how to define a custom directive from the source code or godocs.

Here is an example from the blog post.
```
type Vehicle {
id: ID!
year: Int!
make: String!
model: Int!
askingPrice: Float
costBasis: Float @hasRole(role: “MANAGER”)
numberOfOffers: Int @isAuthenticated
}
```

It would be nice to be able to define an `isAuthenticated` directive that will determine whether or not a field should resolve.

Is there currently a way to implement this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.