# appsync-schema-converter

> Converts GraphQL schemas into AppSync compatible version.

Latest version **2.1.4** (published 2023-03-27) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install appsync-schema-converter
pnpm add appsync-schema-converter
yarn add appsync-schema-converter
bun add appsync-schema-converter
```

Provides the command `appsync-schema-converter`.

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2023-03-27 |
| First published | 2019-08-18 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 85.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vicary Archangel |
| Maintainers | vicary |
| Keywords | aws, appsync, directives, graphql, schema, utilities |

## Links

- npm: https://www.npmjs.com/package/appsync-schema-converter
- Repository: https://gitlab.com/vicary/appsync-schema-converter
- Homepage: https://gitlab.com/vicary/appsync-schema-converter#readme
- Issues: https://gitlab.com/vicary/appsync-schema-converter/issues
- Funding: https://github.com/sponsors/vicary
- npm.io page: https://npm.io/package/appsync-schema-converter

## Dependencies (1)

- [commander](https://npm.io/package/commander.md) ^8.3.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.1.4 (latest) — 2023-03-27
- 2.1.3 — 2023-03-22
- 2.1.2 — 2023-03-22
- 2.1.1 — 2022-12-21
- 2.0.0 — 2021-11-19
- 1.1.6 — 2021-11-08
- 1.1.5 — 2021-11-08
- 1.1.4 — 2021-11-08
- 1.1.3 — 2021-11-08
- 1.1.2 — 2021-07-28
- 1.1.1 — 2021-07-06
- 1.1.0 — 2021-06-30
- 1.0.6 — 2021-06-28
- 1.0.5 — 2021-05-24
- 1.0.4 — 2021-05-24
- … 8 more at https://npm.io/package/appsync-schema-converter/versions

## README

# AppSync Schema Converter

The sole purpose of this package is to convert modern GraphQL schemas into AppSync compatible version.

1. `printSchema()` is a copy of `graphql@^15/utilities/printSchema.js` with AppSync specific options added.
2. `convertSchemas(schemas: [string])` takes an array of GraphQL SDL string and converts them into one single AppSync comptaible schema.

## Upgrade from 1.x

All exposed functions are now synchronize, async/await was found unnecessary.

# Usage

## CLI

This package supports direct shell invocation via npx:

```bash
npx appsync-schmea-converter **/*.graphql
```

## Serverless Framework

This package also made with [`serverless-appsync-plugin`](https://www.npmjs.com/package/serverless-appsync-plugin) in mind, especially useful when [`merge-graphql-schemas`](https://www.npmjs.com/package/merge-graphql-schemas) was in your stack.

You make use of [variables in JavaScript](https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-in-javascript-files) and write a little script to merge schemas into AppSync compatible one.

Based on your `serverless-appsync-plugin` settings, change this line in your `serverless.yml`.

```YAML
custom:
  appSync:
    schema: ${file(schema.js):compile}
```

Then read and convert your schemas in `schema.js@compile`.

```javascript
const glob = require("fast-glob");
const { promises: fs } = require("fs");
const { convertSchemas } = require("appsync-schema-converter");

const SCHEMA_PATH = "./schema.graphql";

module.exports.compile = async (_) => {
  let schemas;

  schemas = await glob(`${__dirname}/schemas/**/*.graphql`);
  schemas = await Promise.all(schemas.map((schema) => fs.readFile(schema, { encoding: "utf-8" })));
  schemas = convertSchemas(schemas, {
    commentDescriptions: true,
    includeDirectives: true,
    includeEnumDescriptions: false,
    interfaceSeparator: ", ",
  });
  // Or use the simplified version: convertAppSyncSchemas(schemas);

  await fs.writeFile(SCHEMA_PATH, schemas);

  return SCHEMA_PATH;
};
```

### Missing comments?

You may notice that after deploying to AppSync, schema comments are still
nowhere to be found.

It appears that `serverless-appsync-plugin@<=1.11.3` simply removes ALL schema
comments when building the CloudFormation stack JSON. Even if this plugin
correctly converts the schemas.

If you are feeling extra adventurous, you may skip all the above and use my fork
[serverless-appsync-plugin#modern-schema](https://github.com/vicary/serverless-appsync-plugin/tree/modern-schema)
instead. It has this package fully integrated into the plugin itself. The behavior is expected to largely stay the same, with the the comment-stripping
logic replaced with my workarounds for AppSync schema syntax.

I try to kept all the unit tests passing, and my team is already using it in production.

# Funding

If you find this project useful, please [chip in](https://github.com/sponsors/vicary) so I can keep making it even better!

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