import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import { enableIntrospection } from '../config.js';
/**
 * Creates and configures an Apollo Server instance with built-in plugins
 * for HTTP drain and WebSocket cleanup.
 *
 * @param configOverride - Apollo Server options (typically contains the schema)
 * @param servers - HTTP server and WebSocket cleanup disposable
 * @param additionalPlugins - Optional additional plugins to merge with built-in plugins
 */
const buildApolloServer = (configOverride, { httpServer, serverCleanup }, additionalPlugins) => {
    const builtInPlugins = [
        ApolloServerPluginDrainHttpServer({ httpServer }),
        {
            async serverWillStart() {
                return {
                    async drainServer() {
                        await serverCleanup.dispose();
                    },
                };
            },
        }
    ];
    const allPlugins = additionalPlugins
        ? [...builtInPlugins, ...additionalPlugins]
        : builtInPlugins;
    return new ApolloServer({
        csrfPrevention: true,
        cache: 'bounded',
        plugins: allPlugins,
        introspection: enableIntrospection,
        ...configOverride,
    });
};
export default buildApolloServer;
//# sourceMappingURL=index.js.map