Socket
Socket
Sign inDemoInstall

merge-graphql-schemas

Package Overview
Dependencies
Maintainers
2
Versions
269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-graphql-schemas - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

test/graphql/resolvers/vendor_resolver.js

5

CHANGELOG.md

@@ -9,2 +9,7 @@ # Change Log

## [0.0.13] - 2017-05-04
### Added
- mergeTypes parses interface type
- mergeTypes parses union type
## [0.0.12] - 2017-05-04

@@ -11,0 +16,0 @@ ### Fixed

19

dist/merge_types.js

@@ -34,6 +34,13 @@ 'use strict';

var scalarTypeRegEx = /scalar ([\s\S]*?).*/gim;
var interfaceTypeRegEx = /interface ([\s\S]*?) {/g;
var unionTypeRegEx = /union ([\s\S]*?) =/g;
var customTypeRegEx = /type (?!Query)(?!Mutation)(?!Subscription)([\s\S]*?) {/g;
var defaultOptions = {
scalar: false,
closingChar: '}'
};
var sliceTypes = function sliceTypes(regexp) {
var scalar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;

@@ -45,7 +52,7 @@ var extractedMatches = [];

matches.forEach(function (match) {
if (scalar) {
if (options.scalar) {
extractedMatches.push(match);
} else {
var startIndex = type.indexOf(match);
var endIndex = type.indexOf('}', startIndex);
var endIndex = type.indexOf(options.closingChar, startIndex);
extractedMatches.push(type.slice(startIndex, endIndex + 1));

@@ -61,3 +68,5 @@ }

var enumTypes = sliceTypes(enumTypeRegEx).filter(Boolean);
var scalarTypes = sliceTypes(scalarTypeRegEx, true).filter(Boolean);
var scalarTypes = sliceTypes(scalarTypeRegEx, { scalar: true }).filter(Boolean);
var interfaceTypes = sliceTypes(interfaceTypeRegEx).filter(Boolean);
var unionTypes = sliceTypes(unionTypeRegEx, { closingChar: '\n' }).filter(Boolean);
var customTypes = sliceTypes(customTypeRegEx).filter(Boolean);

@@ -78,3 +87,3 @@ var queryTypes = sliceDefaultTypes('Query');

var mergedTypes = [];
var allTypes = [inputTypes, enumTypes, scalarTypes, customTypes];
var allTypes = [inputTypes, enumTypes, scalarTypes, interfaceTypes, unionTypes, customTypes];
allTypes.forEach(function (t) {

@@ -81,0 +90,0 @@ if (t.length !== 0) {

{
"name": "merge-graphql-schemas",
"author": "OK GROW!",
"version": "0.0.12",
"version": "0.0.13",
"description": "Better organize your GraphQL server.",

@@ -6,0 +6,0 @@ "repository": {

@@ -19,5 +19,12 @@ import validateSchema from './validate_schema';

const scalarTypeRegEx = /scalar ([\s\S]*?).*/gim;
const interfaceTypeRegEx = /interface ([\s\S]*?) {/g;
const unionTypeRegEx = /union ([\s\S]*?) =/g;
const customTypeRegEx = /type (?!Query)(?!Mutation)(?!Subscription)([\s\S]*?) {/g;
const sliceTypes = (regexp, scalar = false) => {
const defaultOptions = {
scalar: false,
closingChar: '}',
};
const sliceTypes = (regexp, options = defaultOptions) => {
const extractedMatches = [];

@@ -28,7 +35,7 @@ types.forEach((type) => {

matches.forEach((match) => {
if (scalar) {
if (options.scalar) {
extractedMatches.push(match);
} else {
const startIndex = type.indexOf(match);
const endIndex = type.indexOf('}', startIndex);
const endIndex = type.indexOf(options.closingChar, startIndex);
extractedMatches.push(type.slice(startIndex, endIndex + 1));

@@ -44,3 +51,5 @@ }

const enumTypes = sliceTypes(enumTypeRegEx).filter(Boolean);
const scalarTypes = sliceTypes(scalarTypeRegEx, true).filter(Boolean);
const scalarTypes = sliceTypes(scalarTypeRegEx, { scalar: true }).filter(Boolean);
const interfaceTypes = sliceTypes(interfaceTypeRegEx).filter(Boolean);
const unionTypes = sliceTypes(unionTypeRegEx, { closingChar: '\n' }).filter(Boolean);
const customTypes = sliceTypes(customTypeRegEx).filter(Boolean);

@@ -77,3 +86,3 @@ const queryTypes = sliceDefaultTypes('Query');

let mergedTypes = [];
const allTypes = [inputTypes, enumTypes, scalarTypes, customTypes];
const allTypes = [inputTypes, enumTypes, scalarTypes, interfaceTypes, unionTypes, customTypes];
allTypes.forEach((t) => {

@@ -80,0 +89,0 @@ if (t.length !== 0) { mergedTypes = mergedTypes.concat(t); }

@@ -6,4 +6,6 @@ import chai from 'chai';

import productType from './graphql/types/product_type';
import vendorType from './graphql/types/vendor_type';
import personEntityType from './graphql/types/person_entity_type';
import personSearchType from './graphql/types/person_search_type';
const assert = chai.assert;

@@ -13,12 +15,9 @@

describe('with default options', () => {
it('loads all files from specified folder', async () => {
const types = [clientType, productType];
const types = [clientType, personEntityType, personSearchType, productType, vendorType];
const loadedTypes = fileLoader(path.join(__dirname, 'graphql/types'));
assert.deepEqual(loadedTypes, types);
});
});
});
});

@@ -5,2 +5,5 @@ import chai from 'chai'; // eslint-disable-line

import productType from './graphql/types/product_type';
import vendorType from './graphql/types/vendor_type';
import personEntityType from './graphql/types/person_entity_type';
import personSearchType from './graphql/types/person_search_type';
import customType from './graphql/other/custom_type';

@@ -437,2 +440,50 @@ import simpleQueryType from './graphql/other/simple_query_type';

});
it('includes INTERFACE type', async () => {
const types = [clientType, productType, vendorType, personEntityType];
const mergedTypes = mergeTypes(types);
const expectedScalarType = normalizeWhitespace(`
interface PersonEntity {
name: String
age: Int
dob: Date
}
`);
const separateTypes = mergedTypes.slice(1).map(type => normalizeWhitespace(type));
assert.include(separateTypes, expectedScalarType, 'Merged Schema is missing INTERFACE type');
});
it('includes vendor custom type', async () => {
const types = [clientType, productType, vendorType, personEntityType];
const mergedTypes = mergeTypes(types);
const expectedScalarType = normalizeWhitespace(`
type Vendor implements PersonEntity {
id: ID!
name: String
age: Int
dob: Date
}
`);
const separateTypes = mergedTypes.slice(1).map(type => normalizeWhitespace(type));
assert.include(separateTypes, expectedScalarType, 'Merged Schema is missing vendor custom type');
});
it('includes UNION type', async () => {
const types = [clientType, productType, vendorType, personEntityType, personSearchType];
const mergedTypes = mergeTypes(types);
const expectedScalarType = normalizeWhitespace(`
union personSearch = Client | Vendor
`);
const separateTypes = mergedTypes.slice(1).map(type => normalizeWhitespace(type));
assert.include(separateTypes, expectedScalarType, 'Merged Schema is missing UNION type');
});
});
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