Skip to content

Commit 721de1f

Browse files
committed
ADD: graphql example
1 parent c21e1be commit 721de1f

10 files changed

+4754
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The `functionly.json` contains the default configuration of the CLI, just create
1818
## Javascript
1919
- [greeter](https://github.com/jaystack/functionly-examples/tree/master/greeter)
2020
- [todoDB](https://github.com/jaystack/functionly-examples/tree/master/todoDB-es6)
21+
- [graphql](https://github.com/jaystack/functionly-examples/tree/master/graphql)
2122

2223
## Typescript
2324
- [todoDB](https://github.com/jaystack/functionly-examples/tree/master/todoDB)

graphql/.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"functionly-aws"
4+
]
5+
}

graphql/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# GraphQL
2+
TodoDB example with GraphQL
3+
4+
## Install
5+
```sh
6+
npm install
7+
```
8+
## Run in local
9+
Run the project with functionly CLI
10+
```sh
11+
functionly deploy local
12+
functionly start
13+
```
14+
## Try it local
15+
### Create todo
16+
```sh
17+
curl -d '@content/createTodo.json' -H "Content-Type: application/json" -X POST http://localhost:3000/graphql
18+
```
19+
### Get by status
20+
```sh
21+
curl -d '@content/getByStatus.json' -H "Content-Type: application/json" -X POST http://localhost:3000/graphql
22+
```
23+
### Get
24+
Replace the `<todoid>` to an existing id value
25+
```sh
26+
curl -d '{"query": "{todo(id:\"<todoid>\"){id,name}}"}' -H "Content-Type: application/json" -X POST http://localhost:3000/graphql
27+
```
28+
29+
30+
31+
# Deploy to aws
32+
Create and setup your AWS IAM role (Lambda execution)
33+
34+
```sh
35+
functionly deploy
36+
```
37+
38+
## Try it online
39+
### Create todo
40+
Replace the `<gatewayid>` after the deployment
41+
```sh
42+
curl -d '@content/createTodo.json' -H "Content-Type: application/json" -X POST https://<gatewayid>.execute-api.us-east-1.amazonaws.com/dev/graphql
43+
```
44+
### Get by status
45+
Replace the `<gatewayid>` after the deployment
46+
```sh
47+
curl -d '@content/getByStatus.json' -H "Content-Type: application/json" -X POST https://<gatewayid>.execute-api.us-east-1.amazonaws.com/dev/graphql
48+
```
49+
### Get
50+
Replace the `<gatewayid>` after the deployment \
51+
Replace the `<todoid>` to an existing id value
52+
```sh
53+
curl -d '{"query": "{todo(id:\"<todoid>\"){id,name}}"}' -H "Content-Type: application/json" -X POST https://<gatewayid>.execute-api.us-east-1.amazonaws.com/dev/graphql
54+
```

graphql/content/createTodo.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"query": "mutation createTodo($name: String, $description: String, $status: String){createTodo(name: $name, description: $description, status: $status) {id,name}}",
3+
"variables":{
4+
"name":"functionly-graphql",
5+
"description":"desc...",
6+
"status":"graphql"
7+
}
8+
}

graphql/content/getByStatus.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"query": "{todos(status:\"graphql\"){id,name,status}}"
3+
}

graphql/functionly.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"awsRegion": "us-east-1",
3+
"main": "./src/index.js",
4+
"deployTarget": "aws",
5+
"localPort": 3000,
6+
"stage": "dev",
7+
"watch": true,
8+
"compile": "babel-loader"
9+
}

graphql/jsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true
4+
},
5+
"exclude": [
6+
"node_modules"
7+
]
8+
}

0 commit comments

Comments
 (0)