Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appsync-schema-converter

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appsync-schema-converter - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.gitlab-ci.yml

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 => {

2

package.json
{
"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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc