graphql-tools custom @directives (schema sugar for GraphQL SDL) are the way to go to augment a resolver or field. Basically run some code before or after a resolver, for example '@toUpper' could set the text of a field to upper case before returning to client, or @withLoginToThirdPartyAPI could ensure you are authed with any third party API before running the resolver that calls it. Not very well documented at this moment in time but I managed to piece together both of the above concepts into my API thats using Prisma for the data layer. A small example can be seen here:
https://github.com/apollographql/graphql-tools/issues/530
From the example there you will have an exported 'schema', just pass this in the the GraphQLServer instance along with prisma
const server = new GraphQLServer({
schema: schema,
context: req => ({
...req,
db: new Prisma({
typeDefs: 'src/generated/prisma.graphql',
endpoint: process.env.PRISMA_ENDPOINT, // the endpoint of the Prisma DB service (value is set in .env)
secret: process.env.PRISMA_SECRET, // taken from database/prisma.yml (value is set in .env)
debug: true, // log all GraphQL queries & mutations
}),
}),
})
You can swap the order of 'next()' in the directiveResolver to perform your action before or after the resovler. When doing before, like my loginToThirdPartyAPI example, I Object.Assign'ed my authed object to the context to make it available to my resolver.