I’m using Apollo Server in Next.js. I’ve included graphql-tools and mergeResolvers to merge my resolver files. I’ve got things working with manual imports and declarations like this:
// Manual import of resolvers
import { resolvers as PropertiesResolver } from '@/graphql/resolvers/properties.resolver';
import { resolvers as TestResolver } from '@/graphql/resolvers/test.resolver';
const ScalarResolvers = {
DateTime: DateTimeResolver,
ObjectID: ObjectIDResolver,
};
// Manual resolver declaration
const resolvers = mergeResolvers([ScalarResolvers, PropertiesResolver, TestResolver]);
const server = new ApolloServer({
typeDefs: [DateTimeTypeDefinition, ObjectIDTypeDefinition, typeDefs],
resolvers: resolvers,
});
export default startServerAndCreateNextHandler(server);
However, I’m looking to automate the import of all resolvers in the resolvers/
directory using LoadFilesSync
. I can get this working with just my resolvers but how can I get it to work with custom scalar resolvers (also from graphql-tools):
// Automated import of all resolvers in the resolvers/ directory
const resolversArray = loadFilesSync(path.join(process.cwd(), 'src', 'graphql', 'resolvers'));
const ScalarResolvers = {
DateTime: DateTimeResolver,
ObjectID: ObjectIDResolver,
};
// Auto declaration (Not working)
const resolvers = mergeResolvers(ScalarResolvers, resolversArray);
const server = new ApolloServer({
typeDefs: [DateTimeTypeDefinition, ObjectIDTypeDefinition, typeDefs],
resolvers: resolvers,
});
export default startServerAndCreateNextHandler(server);
How can I get my custom scalars merged with my other resolvers