Resolve reference function not working with custom directives

I am currently using custom directives to handle authorization across mutations and queries for my subgraphs. However, I realised that when I wrap my schema in the custom directive function, the __resolveReference function for a particular entity is not being called. But when I pass the schema returned from buildSubgraphSchema function directly to the Apollo server constructor, everything works fine. Any idea what I could be doing wrong.?

Schema returned from buildSubgraph

let schema = buildSubgraphSchema({typedefs, resolvers})
const server = new ApolloServer({schema}) // works fine

Schema returned from directive

let schema = buildSubgraphSchema({typedefs, resolvers})
schema = authDirectiveTransformer(schema)
const server = new ApolloServer({schema}) // __resolveReference is not been called on entities.


I have similar issues. I believe its related to this issue in graphql-tools which the authDirectiveTransformer uses.

I was able to fix this by using addResolversToSchema() exported from apollo-graphql package and it worked. So this is the fix

import {addResolversToSchema} from 'apollo-graphql'
let schema = authDirectiveTransformer(buildSubgraphSchema({typedefs, resolvers}))
addResolversToSchema(schema, referenceResolvers)
export default schema
const server = new ApolloServer({
 schema: // pass in schema after calling the `addResolversToSchema()`

addResolversToSchema returns void by default. So doing that will fix things up!