Skip to content

Commit d6a3cf3

Browse files
tirumaraiselvanshahidhk
authored andcommitted
add hello-world remote-schema boilerplates for major serverless providers (hasura#1694)
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.
1 parent 98405fd commit d6a3cf3

File tree

45 files changed

+506
-1970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+506
-1970
lines changed

community/boilerplates/event-triggers/zeit-serverless-docker/README.md

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# (MOVED) GraphQL server using NodeJS and Apollo
22

3-
**This folder has been moved to [remote-schemas/zeit-now/nodejs/apollo-sequelize](../../remote-schemas/zeit-now/nodejs/apollo-sequelize)**
3+
**This folder has been moved to [remote-schemas/aws-lambda/nodejs](../../remote-schemas/aws-lambda/nodejs)**
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# (MOVED) GraphQL server using NodeJS-Express
22

3-
**This folder has been moved to [remote-schemas/zeit-now/nodejs/express-graphqljs-sequelize](../../remote-schemas/zeit-now/nodejs/express-graphqljs-sequelize)**
3+
**This folder has been moved to [remote-schemas/aws-lambda/nodejs](../../remote-schemas/aws-lambda/nodejs)**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
*.zip
3+
package-lock.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# AWS Lambda + NodeJS + Apollo
2+
3+
This is a GraphQL backend boilerplate in nodejs that can be deployed on AWS Lambda.
4+
5+
## Stack
6+
7+
node 8.10
8+
9+
AWS Lambda
10+
11+
#### Frameworks/Libraries
12+
13+
Apollo Server (GraphQL framework)
14+
15+
## Schema
16+
17+
18+
```
19+
type Query {
20+
hello: String
21+
}
22+
```
23+
24+
## Local Development
25+
26+
The sample source code is present in `index.js`.
27+
28+
```bash
29+
$ git clone [email protected]:hasura/graphql-engine
30+
$ cd graphql-engine/community/boilerplates/remote-schemas/aws-lambda/nodejs
31+
```
32+
33+
Start a local development server (you may need to install dependencies from npm):
34+
35+
```bash
36+
$ npm i --no-save apollo-server express
37+
$ node localDev.js
38+
39+
Output:
40+
41+
Server ready at http://localhost:4000/
42+
```
43+
44+
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.
45+
46+
## Deployment
47+
48+
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.
49+
50+
1) Create a Lambda function by clicking on Create Function on your Lambda console. Choose the `NodeJS 8.10` runtime and `lambda_basic_execution` role.
51+
52+
![create-lambda](../../_assets/create-lambda.png)
53+
54+
2) In the next page (or Lambda instance page), select API Gateway as the trigger.
55+
56+
![create-api-gateway](../../_assets/create-api-gateway.png)
57+
58+
3) Configure the API Gateway as you wish. The simplest configuration is shown below.
59+
60+
![configure-api-gateway](../../_assets/configure-api-gateway.png)
61+
62+
Save your changes. You will receive a HTTPS endpoint for your lambda.
63+
64+
![output-api-gateway](../../_assets/output-api-gateway.png)
65+
66+
If you go to the endpoint, you will receive a "Hello from Lambda!" message. This is because we haven't uploaded any code yet!
67+
68+
4) Zip and upload code. Make sure the handler is set as `lambdaCtx.handler`:
69+
70+
```bash
71+
$ zip -r graphql.zip *
72+
```
73+
74+
And that's it. Hit save and visit the endpoint again. You will see the graphql playground again.
75+
76+
**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 ).

community/boilerplates/remote-schemas/aws-lambda/nodejs/apollo-sequelize/.gitignore

-3
This file was deleted.

community/boilerplates/remote-schemas/aws-lambda/nodejs/apollo-sequelize/README.md

-104
This file was deleted.

community/boilerplates/remote-schemas/aws-lambda/nodejs/apollo-sequelize/index.js

-85
This file was deleted.

community/boilerplates/remote-schemas/aws-lambda/nodejs/apollo-sequelize/models.js

-37
This file was deleted.

0 commit comments

Comments
 (0)