Attempting to migrate a pretty small service over to v3 for testing, and for a while directives seemed to be in a weird place.
I originally used attachDirectiveResolvers
, and then SchemaDirectiveVisitor
came out, and that was something on my to-do list to migrate over, as apparently attachDirectiveResolvers
was deprecated.
Now I’m trying to port a few simple directive resolvers over to the current pattern, and here’s where things get confusing for me.
API is confusing, documentation inconsistent
Apollo states to more-or-less do what @graphql-tools
states to use, and it says “schema directives are a legacy feature”, on the migration guide, but that link is dead.
Looking at the documentation for @graphql-tools
, it states a general Schema Directive pattern that relies on using transforms, and in the Apollo docs I see reference to makeExecutableSchema({schemaTransforms})
, but that API doesn’t appear to exist according to the type definitions on makeExecutableSchema
.
On top of that, the pattern used in @graphql-tools
uses transforms, but the documentation on the Apollo side uses visitors, and I don’t see anywhere a clear way to implement my directives coming from either party.
@graphql-tools
states a general pattern for what a schema directive should look like, but actual implementation is specific to the server framework. But when looking at Apollo’s API, it seems to reference tooling present in @graphql-tools
that doesn’t appear to exist anymore.
Thoroughly confused here. Are visitors still the pattern to use here?
Adding directives to a federated service
buildFederatedSchema/buildSubgraphSchema
accepts typeDefs and resolvers, similar to makeExecutableSchema
, but it’s unclear if I need to do these in a particular order.
Do I need to make an executable. schema first, and then turn it into a federated schema, or do I need to build a federated schema and make it executable? How do I actually do that, when the results of buildFederatedSchema
and makeExecutableSchema
can’t cleanly pipe into each other?
I can’t simply make an executable schema and then make that schema federated, because they each accept lower-level types and output a schema, and neither of them appear to allow a schema as input, so I appear to need to make an executable schema, pull out the typedefs, and then make a federated schema from that.
This seems like a pretty simple use-case, and for the life of me I can’t figure out a way to do this that doesn’t feel like a hack.
Maybe I’m just confused, but the docs are just making me more confused right now. Can anybody give me a breakdown of the current state of schema directives?