Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose GraphQLModule options and gqlSchemaHost to support Serverless #3164

Closed
1 task done
amokio opened this issue Feb 27, 2024 · 0 comments
Closed
1 task done

Expose GraphQLModule options and gqlSchemaHost to support Serverless #3164

amokio opened this issue Feb 27, 2024 · 0 comments
Labels

Comments

@amokio
Copy link

amokio commented Feb 27, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

No

Describe the solution you'd like

when use createApplicationContext, GraphQLModule it will not run adapter.start() and create ApolloServer because of httpAdapter is null.

to support serverless, can we expose options and gqlSchemaHost.schema so that we can manual create ApolloServer

import { ApolloFederationDriver } from '@nestjs/apollo';
import { NestFactory } from '@nestjs/core';
import { GraphQLModule } from '@nestjs/graphql';
import { AppModule } from './app.module';
import { ApolloServer } from '@apollo/server';
import {
  LambdaHandler,
  handlers,
  startServerAndCreateLambdaHandler,
} from '@as-integrations/aws-lambda';

const requestHandler = handlers.createAPIGatewayProxyEventV2RequestHandler();

let serverless: LambdaHandler<typeof requestHandler>;

const bootstrap = async () => {
  if (!serverless) {
    const app = await NestFactory.createApplicationContext(AppModule, {
      logger: ['error'],
    });

    await app.init();

    const graphql =
      app.get<GraphQLModule<ApolloFederationDriver>>(GraphQLModule);

    const options = (graphql as any).options;

    const server = new ApolloServer({
      ...options,
      schema: (graphql as any).gqlSchemaHost.schema,
    });

    serverless = startServerAndCreateLambdaHandler(server, requestHandler, {});
  }
};

bootstrap();

export const handler = async (event, context, callback) => {
  if (!serverless) {
    await bootstrap();
  }

  return serverless(event, context, callback);
};

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

integrate with @as-integrations/aws-lambda

@amokio amokio added the feature label Feb 27, 2024
@amokio amokio changed the title Expose GraphQLModule options and gqlSchemaHost to support Apollo Integration Lambda Expose GraphQLModule options and gqlSchemaHost to support Serverless Feb 27, 2024
@amokio amokio closed this as completed Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant