-
Notifications
You must be signed in to change notification settings - Fork 2k
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 2.0: AWS Lambda Integration #1188
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adnsio This is so awesome! Thank you so much for adding in Lambda support. With a couple of changes, we'll be able to include it in the next release.
Can we add some documentation to the README? An example of how to use it with SAM would be great. We can definitely pull from this section in the current README. The first code snippet could be replaced by this:
// graphql.js
const { ApolloServer, gql } = require('apollo-server-lambda')
const typeDefs = gql`
type Query {
hello: String
}
`
const resolvers = {
Query: {
hello: () => 'hello world'
}
}
const server = new ApolloServer({ typeDefs, resolvers })
exports.graphqlHandler = server.createHandler();
Tests would also be incredible. For now, we can just change the current test file on master to use the new API. It will provide a minimal smoke test, so more testing would be much appreciated.
Can't wait for this to land!
return super.graphQLServerOptions({ event, context }); | ||
} | ||
|
||
public async handle({ event, context, callback, gui }: ServerRegistration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this createHandler
, since it's more in line with the SAM configuration.
We also have a great opportunity to make the functionality much more streamline. Can we add a cors option. We can set it up like this: https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-lambda#modifying-the-lambda-response-enable-cors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the function to createHandler
, now it returns a function that accepts event
, context
and callback
(the handler).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About CORS for now I copied the old readme example, but we could also add a cors
option to simplify the setup.
@evans I added the examples in the readme similar to the previous ones. |
@adnsio Thank you so much for the documentation! I think your comment is spot on. A cors option passed to the |
Super awesome work @adnsio! Thank you @bwlt and @gragio for adding code reviews. I'm going to merge this now and include it in the next rc. Adding a deployment guide on Lambda, next to the Heroku page would be incredibly helpful and definitely make the package more widespread! It could just be a symlinked copy of the README |
AWS Lambda integration for Apollo Server 2
Demo: https://4z36935dne.execute-api.eu-west-1.amazonaws.com/production