Howdy folks. I’m experimenting with using schema directives to express data sources, access control rules, and the like, e.g.:
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:
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.