import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { ApolloServer } from "apollo-server-azure-functions";
import { ApolloGateway } from "@apollo/gateway";
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
const startApollo = () => {
let handler: AzureFunction | undefined;
const init = async () => {
const gateway = new ApolloGateway({
serviceList: [
{ name: 'subgraph-api', url: 'https://localhost:7071/api/graphql' }
]
});
const { schema, executor } = await gateway.load();
const server = new ApolloServer({ schema, executor: executor as any, plugins: [ApolloServerPluginLandingPageGraphQLPlayground]});
handler = server.createHandler()
console.log("Apollo server started.");
};
init();
return (context: Context, req: HttpRequest) => {
if (handler) handler(context, req);
};
};
exports.graphqlHandler = startApollo();