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

simple-graphql-assembler

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-graphql-assembler - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

bin/index.js

80

lib/assembler/assembler.js

@@ -10,2 +10,3 @@ const path = require('path');

path.join(path.dirname(file), `${path.basename(file, '.gql')}.resolver.js`);
const readFile = file => fs.readFileSync(file, { encoding: 'utf8' });

@@ -28,38 +29,23 @@

const assemble = (root = '.') => {
const baseFiles = [];
const baseResolvers = {};
const buildBaseResolvers = (baseResolverFiles = []) => {
const errors = [];
let errorFound = false;
// eslint-disable-next-line no-restricted-syntax
for (const files of findFiles(root)) {
const [typedefs, resolvers] = files;
const baseResolvers = baseResolverFiles.reduce((acc, curr) => {
const rModule = include(curr);
if (!rModule) return acc;
baseFiles.push(...typedefs);
// eslint-disable-next-line no-restricted-syntax
for (const resolver of resolvers) {
const rModule = include(resolver);
if (rModule) {
const [isValid, error] = validate(rModule);
if (!isValid) {
errorFound = true;
errors.push({ name: resolver, error });
} else {
const { __name, ...rest } = rModule;
baseResolvers[__name] = rest;
}
}
const [isValid, error] = validate(rModule);
if (!isValid) {
errors.push({ name: curr, error });
return acc;
}
}
if (errorFound) {
return { typeDefs: null, resolvers: null, errors };
}
const { __name, ...rest } = rModule;
return { ...acc, [__name]: rest };
}, {});
const typeDefs = baseFiles
.map(readFile)
.reduce((acc, curr) => `${acc}${curr}`, '');
return { baseResolvers, errors };
};
const buildFinalResolvers = (baseResolvers = {}) => {
const resolvers = {};

@@ -89,5 +75,41 @@

return resolvers;
};
const buildTypeDefinitions = (typeDefinitionFiles = []) =>
typeDefinitionFiles.map(readFile).reduce((acc, curr) => `${acc}${curr}`, '');
const assemble = (root = '.') => {
const typeDefinitionFiles = [];
const baseResolverFiles = [];
Array.from(findFiles(root)).forEach(gql => {
const [typeDefFiles, resolverFiles] = gql;
typeDefinitionFiles.push(...typeDefFiles);
baseResolverFiles.push(...resolverFiles);
});
const { baseResolvers, errors } = buildBaseResolvers(baseResolverFiles);
if (errors.length) {
return { typeDefs: null, resolvers: null, errors };
}
const typeDefs = buildTypeDefinitions(typeDefinitionFiles);
const resolvers = buildFinalResolvers(baseResolvers);
return { typeDefs, resolvers, errors: null };
};
const onlyTypeDefs = (root = '') => {
const typeDefinitionFiles = [];
Array.from(findFiles(root)).forEach(([typeDefFiles]) => {
typeDefinitionFiles.push(...typeDefFiles);
});
return buildTypeDefinitions(typeDefinitionFiles);
};
module.exports = assemble;
module.exports.onlyTypeDefs = onlyTypeDefs;
{
"name": "simple-graphql-assembler",
"version": "0.0.2",
"version": "0.1.0",
"description": "Simple backend graphql shcema assembler for apollo projects",

@@ -17,6 +17,11 @@ "author": "Metál Ádám <devmetal91@gmail.com> (https://github.com/devmetal)",

"main": "index.js",
"bin": {
"make-typedefs": "./bin/index.js"
},
"files": [
"index.js",
"index.d.ts",
"package.lock",
"/lib",
"/bin",
"!examples/",

@@ -48,3 +53,4 @@ "!**/__fixtures__/",

"dependencies": {
"lodash": "^4.17.11"
"lodash": "^4.17.11",
"yargs": "^13.2.1"
},

@@ -51,0 +57,0 @@ "engines": {

@@ -105,1 +105,19 @@ [![Build Status](https://travis-ci.org/devmetal/simple-graphql-assembler.svg?branch=master)](https://travis-ci.org/devmetal/simple-graphql-assembler)

```
### cli usage
I added a tool for cli usage, the tool is called **make-typedefs** This tool will be traverse the current working directory for .gql files and with a very simple technique (copy) it will create one single file as a merged schema.gql.
```bash
Usage: make-typedefs [options]
Options:
--version Show version number [boolean]
--root, -r Root folder of your gql definitions and resolvers [default: "."]
--output, -o Output file for type definitions [default: "./schema.gql"]
-h, --help Show help [boolean]
Examples:
make-typedefs -r . -o ./schema.gql Create the gql type definition file for
your definitions from the current
directory
```
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