# generator-cosappsync

> ## Prerequesites

Latest version **0.9.0** (published 2020-06-12) · 0 weekly downloads

## Install

```sh
npm install generator-cosappsync
pnpm add generator-cosappsync
yarn add generator-cosappsync
bun add generator-cosappsync
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2020-06-12 |
| First published | 2020-06-12 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 50.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ccludts |
| Keywords | yeoman-generator |

## Links

- npm: https://www.npmjs.com/package/generator-cosappsync
- npm.io page: https://npm.io/package/generator-cosappsync

## Dependencies (1)

- [yeoman-generator](https://npm.io/package/yeoman-generator.md) ^4.7.2

## Recent versions

- 0.9.0 (latest) — 2020-06-12

## README

# Generator: CosAppSync

## Prerequesites

It's best to familiarize yourself with these topics if you don't know where to start:

- [TypeScript](https://www.typescriptlang.org/)
- [GraphQL](https://graphql.org/)
- [CDK](https://docs.aws.amazon.com/cdk/latest/guide/home.html)
- [AppSync](https://aws.amazon.com/appsync/)
- [Velocity (VTL)](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-overview.html)

When using `dynamodb` as a backend:

- [DynamoDB](https://aws.amazon.com/dynamodb/)

When using `aurora-postgres` as a backend:

- [RDS](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html)
- [Postgres](https://www.postgresql.org/docs/10/index.html)

Also worth checking out:

- [Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)

## How to use

First make sure [Yeoman](https://yeoman.io/) is installed globally: `npm install -g yo`

Then make Yeoman aware of the generator in this repo:

```bash
npm i
npm link
```

Afterwards you can use the template by running:

`yo cosappsync`

**_NOTE_**: Run this in a different folder, where you want your project to be created in.

Also, the generator will assign a random port to your local endpoint and prints it once it's done.

## Structure

The generator supports the following database backends:

```bash
- aurora-postgres
- dynamodb
```

It also generates resolver examples for you:

```bash
- Unit Resolver + Go Lambda
- Pipeline Resolver
```

**_NOTE_**: If you choose `aurora-postgres` you need to have `NPM_TOKEN` in your env set to a token with access to the Gitlab NPM registry. If you don't know what to do, just poke someone.

Also worth mentioning: The latest supported Postgres version by Aurora is `10.7`. Just keep that in mind when developing your schema.

Depending on which you choose, it will setup all necessary files and give you a deployable AppSync project.

The layout of a project is as follows (omitted some files for clarity):

```
...
lib/ - here is where all the actual logic of the backend is placed
    graphql/ - contains the schema.graphql
    lambdas/ - all lambdas (if any) should go here
    resolvers/ - all resolvers (*.vtl) should go here
    sql/ - contains the schema.sql for providing all tables, functions, triggers, ... only exists when choosing aurora-postgres)
    <project>-stack.ts - the CDK stack containing a GraphQL API, database backend and basic resolvers)
docker/ - contains everything necessary to run the mock API
test/ - some basic boilerplate for writing tests
appsync-mock.json - configuration of the mock API, which is where - amongst others - the connection strings to the databases can be configured as well as the JWT token that is used in the GraphQL editor
...
```

## Working with GraphQL

For working with GraphQL it is a good idea to use the GraphQL editor available at `http://localhost:2XXXX` (port is randomly chosen when the project is created) which makes writing and testing queries a lot easier thanks to introspection.

### API Authentitcation

The API uses OIDC for authorization and therefore you need a valid token. The aforementioned GraphQL editor provides one automatically for you. The used JWT token is defined in the `appsync-mock.json`.

## References

To get more concrete examples, you can use these projects as a reference. Both used this template as a starting point:

### Aurora Postgres

https://gitlab.botogames.com/g4g/match3-api

### DynamoDB

https://gitlab.botogames.com/g4g/unity-jobs

---
_Source: https://npm.io/package/generator-cosappsync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
