@ttoss/appsync-api 0.4.4 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/dist/cli.js +0 -3688
- package/dist/esm/chunk-7AZ2LNJP.js +750 -0
- package/dist/esm/chunk-NQOARNEJ.js +27 -0
- package/dist/esm/cli.js +2 -2
- package/dist/esm/index.js +5 -4
- package/dist/esm/server.js +43 -0
- package/dist/index.d.ts +15 -5
- package/dist/index.js +64 -3788
- package/dist/server.d.ts +8 -0
- package/dist/server.js +66 -0
- package/package.json +41 -9
- package/src/cli.ts +0 -3
- package/src/createApiTemplate.ts +32 -92
- package/src/{appSyncResolverHandler.ts → createAppSyncResolverHandler.ts} +8 -2
- package/src/index.ts +4 -1
- package/src/server.ts +47 -0
- package/dist/esm/chunk-OVEYUNNE.js +0 -4498
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @ttoss/appsync-api
|
|
2
|
+
|
|
3
|
+
This package provides a opinionated way to create an AppSync API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @ttoss/appsync-api graphql-compose graphql
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
You can create and deploy an AppSync API in four steps:
|
|
14
|
+
|
|
15
|
+
1. Create a `schemaComposer` object using [`graphql-compose`](https://graphql-compose.github.io/docs/intro/quick-start.html), that the next steps will use to create the API.
|
|
16
|
+
|
|
17
|
+
2. Create a `cloudformation.ts` file that exports a CloudFormation template using `createApiTemplate`:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { createApiTemplate } from '@ttoss/appsync-api';
|
|
21
|
+
import { schemaComposer } from './schemaComposer';
|
|
22
|
+
|
|
23
|
+
const template = createApiTemplate({
|
|
24
|
+
schemaComposer,
|
|
25
|
+
dataSource: {
|
|
26
|
+
roleArn: {
|
|
27
|
+
'Fn::ImportValue': 'AppSyncLambdaDataSourceIAMRoleArn',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
lambdaFunction: {
|
|
31
|
+
roleArn: {
|
|
32
|
+
'Fn::ImportValue': 'AppSyncLambdaFunctionIAMRoleArn',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export default template;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Create a `lambda.ts` file that exports a Lambda handler function using `createAppSyncResolverHandler`:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { createAppSyncResolverHandler } from '@ttoss/appsync-api';
|
|
44
|
+
import { schemaComposer } from './schemaComposer';
|
|
45
|
+
|
|
46
|
+
export const handler = createAppSyncResolverHandler({ schemaComposer });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Add `graphql` and `graphql-compose` to the `lambdaExternals` array in `carlin.yml`:
|
|
50
|
+
|
|
51
|
+
```yml
|
|
52
|
+
lambdaExternals:
|
|
53
|
+
- graphql
|
|
54
|
+
- graphql-compose
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Now you can deploy your API using `carlin deploy`:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
carlin deploy
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Server
|
|
64
|
+
|
|
65
|
+
You can create a local server to test your API using `createServer`:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { createServer } from '@ttoss/appsync-api/server';
|
|
69
|
+
import { schemaComposer } from '../src/schemaComposer';
|
|
70
|
+
|
|
71
|
+
const server = createServer({ schemaComposer });
|
|
72
|
+
|
|
73
|
+
server.listen(4000, () => {
|
|
74
|
+
// eslint-disable-next-line no-console
|
|
75
|
+
console.log(
|
|
76
|
+
'Server is running, GraphQL Playground available at http://localhost:4000/graphql'
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
```
|