appsync-schema-converter
Advanced tools
Comparing version 0.1.0 to 0.1.1
17
index.js
@@ -29,3 +29,14 @@ const { | ||
function convertSchemas(schemas) { | ||
/** | ||
* Convert Apollo GraphQL schemas into AppSync verison. | ||
* | ||
* @param {[string]} An array of GraphQL SDL string to be converted. | ||
* @param {object} options | ||
* - {boolean} options.commentDescriptions Use legacy comment as type description. | ||
* - {boolean} options.includeDirectives Include field directive declarations as output. | ||
*/ | ||
function convertSchemas(schemas, { | ||
commentDescriptions = false, | ||
includeDirectives = false, | ||
}) { | ||
const AppSyncDefs = AppSyncScalars.concat(AppSyncDirectives); | ||
@@ -37,3 +48,3 @@ let schema = Array.isArray(schemas) ? schemas : [schemas]; | ||
// note;dev; buildSchema() does not handles type extension, extendSchema() is required. | ||
// buildSchema() does not handles type extension, extendSchema() is required. | ||
schema = (schema.definitions || []).reduce((prev, astNode) => { | ||
@@ -57,3 +68,3 @@ const { defs, exts } = prev; | ||
schema = printSchema(schema, { commentDescriptions: true, includeDirectives: true }); | ||
schema = printSchema(schema, { commentDescriptions, includeDirectives }); | ||
@@ -60,0 +71,0 @@ AppSyncDefs.forEach(type => { |
{ | ||
"name": "appsync-schema-converter", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Converts modern schemas into AppSync compatible version.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,3 +11,41 @@ # AppSync Schema Converter | ||
# 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 { promisify } = require('util'); | ||
const glob = require('glob'); | ||
const { readFile, writeFile } = require('fs').promises; | ||
const { convertSchemas } = require("appsync-schema-converter"); | ||
const SCHEMA_PATH = './schema.graphql'; | ||
module.exports.compile = async _ => { | ||
let schemas; | ||
schemas = await promisify(glob)(`${__dirname}/schemas/**/*.graphql`); | ||
schemas = await Promise.all(schemas.map(async schema => (await readFile(schema)).toString('utf8'))); | ||
schemas = convertSchemas(schemas, { | ||
commentDescriptions: true, | ||
includeDirectives: true, | ||
}); | ||
await writeFile(SCHEMA_PATH, schemas); | ||
return SCHEMA_PATH; | ||
}; | ||
``` | ||
# Contributors | ||
- [Vicary Archangel](mailto:vicary.archangel@member.mensa.org) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18162
7
386
51