@ttoss/appsync-api 0.4.3 → 0.5.0

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 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
+ ```