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

Apollo Server 2.0: AWS Lambda Integration #1188

Merged
merged 9 commits into from
Jun 21, 2018
Merged

Apollo Server 2.0: AWS Lambda Integration #1188

merged 9 commits into from
Jun 21, 2018

Conversation

alessiodionisi
Copy link
Contributor

@alessiodionisi alessiodionisi commented Jun 18, 2018

AWS Lambda integration for Apollo Server 2

Demo: https://4z36935dne.execute-api.eu-west-1.amazonaws.com/production

Copy link
Contributor

@evans evans left a 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) {
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor Author

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.

@alessiodionisi
Copy link
Contributor Author

@evans I added the examples in the readme similar to the previous ones.

@evans
Copy link
Contributor

evans commented Jun 20, 2018

@adnsio Thank you so much for the documentation! I think your comment is spot on. A cors option passed to the createHandler that follows the express version would be great! The origin option can probably be a simple string or boolean.

@alessiodionisi
Copy link
Contributor Author

@evans I added the CORS option (like express) and tests for lambdaApollo.ts

@evans evans merged commit bb4f1c3 into apollographql:version-2 Jun 21, 2018
@evans
Copy link
Contributor

evans commented Jun 21, 2018

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

@evans evans mentioned this pull request Jun 21, 2018
@unicodeveloper
Copy link
Contributor

@evans I'd handle that 🍾 @adnsio Super thanks for this great work!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants