Hey guys,
Currently building out an auth API microservice (Apollo server) behind an Apollo Gateway (Apollo-server-express), and I’m trying to implement some form validation, on a createUser
mutation.
After a quick google I came across the graphql-constraints-directive
package, and this Apollo blog: GraphQL validation using directives - Apollo GraphQL Blog
Looks like it’s going to do everything I want, so gave it a go. However, I’m struggling to implement it on my auth subgraph, as currently I’m using the buildSubgraphSchema
function from @apollo/subgraph
to build the schema and make it available to my gateway (this is being done via IntrospectAndCompose
on my local machine, but will be done via the managed federations/supergraph in production).
So currently I have this:
const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers }),
validationRules: [depthLimit(7)]
});
and the blog, says to implement it like this:
const typeDefs = `SDL HERE`
const schema = makeExecutableSchema({
typeDefs, schemaDirectives: { constraint: ConstraintDirective }
})
From what I can understand, both of these are building a final schema. However, I can’t seem to find a good way of combining the two to enable me to use constraints within my schema typeDefs
.
I was able to get one implementation where TS didn’t complain and compiled, but then my gateway complained when it tried to compose the supergraph, so obviously my buildSubgraphSchema
result was being replaced.
I’ve tried some googling, and can’t really find anything about this specific constraint directive package within a subgraph/supergraph, so wondering if anyone else has any suggestions, or even a working implementation. I’m also open to using a completely different method of form validation if you have a good suggestion - this directive just seems like it would fit perfectly.