title: Custom GraphQL Directive Logic Implemention
body: <p>I have a rapidly growing GraphQL schema written in <code>go</code> using the <code>github.com/graphql-go/graphql</code> library and am trying to implement a custom directive for field definitions for authentication.</p>
  
  <p>I'm instantiating the directive object with:</p>
  
  <pre class="lang-golang prettyprint-override"><code>var AuthenticatedDirective = graphql.NewDirective(graphql.DirectiveConfig{
      Name:        "authenticated",
      Description: "Identifies a query or mutation as requiring authentication for resolution",
      Locations:   []string{graphql.DirectiveLocationFieldDefinition},
      Args: graphql.FieldConfigArgument{
          "type": &amp;graphql.ArgumentConfig{
              Type: graphql.NewNonNull(graphql.String),
          },
      },
  })
  </code></pre>
  
  <p>...appending it to the schema by:</p>
  
  <pre class="lang-golang prettyprint-override"><code>var customDirectives = []*graphql.Directive{
      types.AuthenticatedDirective,
  }
  
  func CompileSchema(query *graphql.Object, mutation *graphql.Object) (graphql.Schema, error) {
      return graphql.NewSchema(graphql.SchemaConfig{
          Query:      query,
          Mutation:   mutation,
          Directives: append(graphql.SpecifiedDirectives, customDirectives...),
      })
  }
  </code></pre>
  
  <p>These two combined appropriately creates and injects the directive definition into the schema so that it's available to use, however, there doesn't seem to be a clear way to implement the logic behind processing the directive or assigning it to field definitions.</p>
  
  <p>For instance, if I have a <code>Query</code> field definition like:</p>
  
  <pre class="lang-golang prettyprint-override"><code>// type Query {
  //   me: @authenticated(type: "jwt")
  // }
  "me": &amp;graphql.Field{
      Description: "(Authenticated) Parses and validates the authorization header token and returns the targeted User",
      Type:        types.UserType,
      Resolve:     resolvers.MeResolver,
  },
  </code></pre>
  
  <p>How do I go about assigning the directive to this query field definition and implementing the JWT validation logic via visiting the directive?</p>