-
Notifications
You must be signed in to change notification settings - Fork 8
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
Apollo Server #56
Comments
I did a proof of concept using the express implementation inside Apollo Server and I create apollo-server.framework.ts. If you want to give it a try, just create the import { IncomingMessage, ServerResponse } from 'http';
import { ApolloServer } from '@apollo/server';
import { ServerlessAdapter, getCurrentInvoke } from '@h4ad/serverless-adapter';
import { DefaultHandler } from '@h4ad/serverless-adapter/lib/handlers/default';
import { PromiseResolver } from '@h4ad/serverless-adapter/lib/resolvers/promise';
import {
ApiGatewayV1Adapter,
ApiGatewayV2Adapter,
} from '@h4ad/serverless-adapter/lib/adapters/aws';
import { ApolloServerFramework } from '@h4ad/serverless-adapter/lib/frameworks/apollo-server/apollo-server';
type CustomContext = {
request: IncomingMessage;
response: ServerResponse;
lambdaEvent: unknown;
lambdaContext: unknown;
};
const server = new ApolloServer<CustomContext>({
typeDefs: 'type Query { x: ID }',
resolvers: { Query: { x: () => 'hi!' } },
});
const framework = new ApolloServerFramework<CustomContext>({
context: ({ request, response }) => {
const { event, context } = getCurrentInvoke();
return Promise.resolve({
request: request,
response: response,
lambdaEvent: event,
lambdaContext: context,
});
},
});
server.startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests();
// this handler add support for API Gateway v1 and v2, to add another event source, just call addAdapter.
export const handler = ServerlessAdapter.new(server)
.setHandler(new DefaultHandler())
.setFramework(framework)
.setResolver(new PromiseResolver())
.addAdapter(new ApiGatewayV1Adapter())
.addAdapter(new ApiGatewayV2Adapter())
.build(); |
I still need to figure out how to handle In theory, if I recommend the user to configure within API Gateway is not a problem, but we also have to add support for other clouds, this is not an option. |
The problem with |
I'll wait until I have more time to work on #62, after I finish that integration I'll see how it works with Apollo. For those who want to use Apollo and don't want to wait, just copy the code from apollo-server.framework.ts, install the latest version of the library and be happy. |
Once the body parser frameworks have been completed, I will now work on completing the Apollo server integration. |
🎉 This issue has been resolved in version 2.13.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Feature request
Inspired apollo-server-integrations/apollo-server-integration-aws-lambda#38.
Is your feature request related to an issue? Please describe.
Added support for
Apollo Server
as Framework/Handler.Describe the solution you would like
In theory, we already have support for Apollo Server if we use
express
as middleware.But maybe we can do better, the solutions are:
Apollo Server
as Framework.Apollo Server
as Handler, so you don't need to create another Request/Response.In both ways, I don't exactly know how to deal with
cors
, maybe I can create a CorsFramework to wrap around any other framework to addcors
features.Are you willing to resolve this issue by submitting a pull request?
The text was updated successfully, but these errors were encountered: