apollo-server-integrations / apollo-server-integration-azure-functions

MIT License
32 stars 13 forks source link

Unable to switch existing apollo federation gateway supporting azure function with apollo-server-integration-azure-functions #30

Open mdv27 opened 1 year ago

mdv27 commented 1 year ago

Existing function

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();

ApolloServer class in @apollo/server v4 does not support above constructor param executor. Also createHandler() not present. Please help.