d6a3cf337f
A hello world schema is provided with local dev and deployment instructions for AWS Lambda, Google Cloud Functions and Azure Functions. Older boilerplates are cleaned up. |
||
---|---|---|
.. | ||
.gitignore | ||
index.js | ||
lambdaCtx.js | ||
localDev.js | ||
package.json | ||
README.md |
AWS Lambda + NodeJS + Apollo
This is a GraphQL backend boilerplate in nodejs that can be deployed on AWS Lambda.
Stack
node 8.10
AWS Lambda
Frameworks/Libraries
Apollo Server (GraphQL framework)
Schema
type Query {
hello: String
}
Local Development
The sample source code is present in index.js
.
$ git clone git@github.com:hasura/graphql-engine
$ cd graphql-engine/community/boilerplates/remote-schemas/aws-lambda/nodejs
Start a local development server (you may need to install dependencies from npm):
$ npm i --no-save apollo-server express
$ node localDev.js
Output:
Server ready at http://localhost:4000/
This will start a local server on localhost:4000
. You can hit the graphql service at localhost:4000
. This opens a graphql playground where you can query your schema.
Deployment
Now that you have run the graphql service locally and made any required changes, it's time to deploy your service to AWS Lambda and get an endpoint. The easiest way to do this is through the AWS console.
- Create a Lambda function by clicking on Create Function on your Lambda console. Choose the
NodeJS 8.10
runtime andlambda_basic_execution
role.
- In the next page (or Lambda instance page), select API Gateway as the trigger.
- Configure the API Gateway as you wish. The simplest configuration is shown below.
Save your changes. You will receive a HTTPS endpoint for your lambda.
If you go to the endpoint, you will receive a "Hello from Lambda!" message. This is because we haven't uploaded any code yet!
- Zip and upload code. Make sure the handler is set as
lambdaCtx.handler
:
$ zip -r graphql.zip *
And that's it. Hit save and visit the endpoint again. You will see the graphql playground again.
IMPORTANT NOTE: You may have to edit the GraphQL URL in the Playground to reflect the right endpoint ( same as the URL created by the API Gateway ).