# Creating schema directives that annotate types and fields

**URL:** <https://community.apollographql.com/t/creating-schema-directives-that-annotate-types-and-fields/617>\
**Category:** Schema Design\
**Tags:** server, federation, directives\
**Created:** [June 29, 2021, 9:22pm UTC](https://community.apollographql.com/t/creating-schema-directives-that-annotate-types-and-fields/617 "2021-06-29T21:22:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donald\_Ball](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/donald_ball/32/426_2.png) [@Donald\_Ball](https://community.apollographql.com/u/Donald_Ball)\
**Post date:** [June 29, 2021, 9:22pm UTC](https://community.apollographql.com/t/creating-schema-directives-that-annotate-types-and-fields/617/1 "2021-06-29T21:22:25Z")

</div>

Howdy folks. I’m experimenting with using schema directives to express data sources, access control rules, and the like, e.g.:

```auto
type Evidence @key(fields: "uuid") @auth(role: "view-evidence") @sql(basis: "SavedEvidence") {
  uuid: ID!
  eid: String
  type: EvidenceType @sql(column: "evidenceType")
}

```

This is an example of a federated subgraph I’m interested in writing, where the `@sql` directive describes the data source and the `@auth` directive describes the access control requirement.

I’m using the javascript `apollo-server` package with the `@apollo/federation` extension. My primary question is: in my schema directive visitors, what’s the best thing to _do_ with these data? The two primary choices seem to be: store the directive metadata on the objects that comprise the schema, or store them in a sidebar data structure. I’m moderately inclined towards the former option for succinctness and locality, but I would expect, in that case, that the apollo schema object should provide public accessors to obtain references to the types and fields. All I’m seeing now are underscore fields of questionable longevity:

```auto
schema._typeMap.Evidence._fields.uuid

```

Have other folk done anything interesting along these lines? It feels like a common and useful pattern, but the lack of prior art and obvious affordances makes me wonder if this is actually the right way to go or if e.g. it might be better to express the schema and its annotations in a more expressive data structure and generate the graphql schema in a reduction.
