merge-graphql-schemas
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -9,2 +9,10 @@ # Change Log | ||
## [0.0.15] - 2017-05-19 | ||
### Changed | ||
- Changed babel preset from es2015 to node6 | ||
### Fixed | ||
- Removed unused async calls | ||
- Changed mocha tests to not use arrow functions | ||
## [0.0.14] - 2017-05-04 | ||
@@ -11,0 +19,0 @@ ### Changed |
@@ -17,11 +17,11 @@ 'use strict'; | ||
var fileLoader = function fileLoader(folderPath) { | ||
var dir = folderPath; // path.join(__dirname, folderPath); | ||
var files = []; | ||
_fs2.default.readdirSync(dir).forEach(function (f) { | ||
const fileLoader = folderPath => { | ||
const dir = folderPath; // path.join(__dirname, folderPath); | ||
const files = []; | ||
_fs2.default.readdirSync(dir).forEach(f => { | ||
if (f.slice(-3) !== '.js') { | ||
return; | ||
} | ||
var filesDir = _path2.default.join(dir, f); | ||
var file = require(filesDir); // eslint-disable-line | ||
const filesDir = _path2.default.join(dir, f); | ||
const file = require(filesDir); // eslint-disable-line | ||
files.push(file.default); | ||
@@ -28,0 +28,0 @@ }); |
@@ -24,11 +24,9 @@ 'use strict'; | ||
var mergeGraphqlSchemas = function mergeGraphqlSchemas(folderPath) { | ||
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
const mergeGraphqlSchemas = (folderPath, debug = false) => { | ||
const typesArray = (0, _file_loader2.default)(`${folderPath}/types`); | ||
const resolversArray = (0, _file_loader2.default)(`${folderPath}/resolvers`); | ||
var typesArray = (0, _file_loader2.default)(folderPath + '/types'); | ||
var resolversArray = (0, _file_loader2.default)(folderPath + '/resolvers'); | ||
const typeDefs = (0, _merge_types2.default)(typesArray); | ||
const resolvers = (0, _merge_resolvers2.default)(resolversArray); | ||
var typeDefs = (0, _merge_types2.default)(typesArray); | ||
var resolvers = (0, _merge_resolvers2.default)(resolversArray); | ||
if (debug === true) { | ||
@@ -39,3 +37,3 @@ console.log('===> SCHEMA: ', typeDefs); // eslint-disable-line | ||
return (0, _graphqlTools.makeExecutableSchema)({ typeDefs: typeDefs, resolvers: resolvers }); | ||
return (0, _graphqlTools.makeExecutableSchema)({ typeDefs, resolvers }); | ||
}; | ||
@@ -42,0 +40,0 @@ |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _deepmerge = require('deepmerge'); | ||
@@ -18,6 +14,4 @@ | ||
var mergeResolvers = function mergeResolvers(resolvers) { | ||
return _deepmerge2.default.apply(undefined, (0, _toConsumableArray3.default)(resolvers)); | ||
}; | ||
const mergeResolvers = resolvers => (0, _deepmerge2.default)(...resolvers); | ||
exports.default = mergeResolvers; |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _validate_schema = require('./validate_schema'); | ||
@@ -18,24 +14,22 @@ | ||
var mergeTypes = function mergeTypes(types) { | ||
var sliceDefaultTypes = function sliceDefaultTypes(operation) { | ||
return types.map(function (type) { | ||
var regexp = new RegExp('type ' + operation + ' {(.*?)}', 'gim'); | ||
var extractedType = type.replace(/(\s)+/gim, ' ').match(regexp); | ||
if (extractedType != null && extractedType.length > 0) { | ||
var startIndex = extractedType[0].indexOf('{') + 1; | ||
var endIndex = extractedType[0].indexOf('}') - 1; | ||
return extractedType[0].slice(startIndex, endIndex); | ||
} | ||
return ''; | ||
}).join(' '); | ||
}; | ||
const mergeTypes = types => { | ||
const sliceDefaultTypes = operation => types.map(type => { | ||
const regexp = new RegExp(`type ${operation} {(.*?)}`, 'gim'); | ||
const extractedType = type.replace(/(\s)+/gim, ' ').match(regexp); | ||
if (extractedType != null && extractedType.length > 0) { | ||
const startIndex = extractedType[0].indexOf('{') + 1; | ||
const endIndex = extractedType[0].indexOf('}') - 1; | ||
return extractedType[0].slice(startIndex, endIndex); | ||
} | ||
return ''; | ||
}).join(' '); | ||
var inputTypeRegEx = /input ([\s\S]*?) {/g; | ||
var enumTypeRegEx = /enum ([\s\S]*?) {/g; | ||
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; | ||
const inputTypeRegEx = /input ([\s\S]*?) {/g; | ||
const enumTypeRegEx = /enum ([\s\S]*?) {/g; | ||
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; | ||
var defaultOptions = { | ||
const defaultOptions = { | ||
scalar: false, | ||
@@ -45,15 +39,13 @@ closingChar: '}' | ||
var sliceTypes = function sliceTypes(regexp) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions; | ||
var extractedMatches = []; | ||
types.forEach(function (type) { | ||
var matches = type.match(regexp); | ||
const sliceTypes = (regexp, options = defaultOptions) => { | ||
const extractedMatches = []; | ||
types.forEach(type => { | ||
const matches = type.match(regexp); | ||
if (matches !== null) { | ||
matches.forEach(function (match) { | ||
matches.forEach(match => { | ||
if (options.scalar) { | ||
extractedMatches.push(match); | ||
} else { | ||
var startIndex = type.indexOf(match); | ||
var endIndex = type.indexOf(options.closingChar, startIndex); | ||
const startIndex = type.indexOf(match); | ||
const endIndex = type.indexOf(options.closingChar, startIndex); | ||
extractedMatches.push(type.slice(startIndex, endIndex + 1)); | ||
@@ -67,24 +59,40 @@ } | ||
var inputTypes = sliceTypes(inputTypeRegEx).filter(Boolean); | ||
var enumTypes = sliceTypes(enumTypeRegEx).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); | ||
var queryTypes = sliceDefaultTypes('Query'); | ||
var mutationTypes = sliceDefaultTypes('Mutation'); | ||
var subscriptionTypes = sliceDefaultTypes('Subscription'); | ||
const inputTypes = sliceTypes(inputTypeRegEx).filter(Boolean); | ||
const enumTypes = sliceTypes(enumTypeRegEx).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); | ||
const queryTypes = sliceDefaultTypes('Query'); | ||
const mutationTypes = sliceDefaultTypes('Mutation'); | ||
const subscriptionTypes = sliceDefaultTypes('Subscription'); | ||
var cleanupForComparison = function cleanupForComparison(string) { | ||
return string.replace(/(\s)+/gim, ''); | ||
}; | ||
const cleanupForComparison = string => string.replace(/(\s)+/gim, ''); | ||
var queryInterpolation = 'type Query {\n ' + queryTypes + '\n }'; | ||
var mutationInterpolation = 'type Mutation {\n ' + mutationTypes + '\n }'; | ||
var subscriptionInterpolation = 'type Subscription {\n ' + subscriptionTypes + '\n }'; | ||
var schema = '\n schema {\n query: Query\n ' + (cleanupForComparison(mutationTypes) !== '' ? 'mutation: Mutation' : '') + '\n ' + (cleanupForComparison(subscriptionTypes) !== '' ? 'subscription: Subscription' : '') + '\n }\n\n ' + (cleanupForComparison(queryTypes) !== '' ? queryInterpolation : '') + '\n\n ' + (cleanupForComparison(mutationTypes) !== '' ? mutationInterpolation : '') + '\n\n ' + (cleanupForComparison(subscriptionTypes) !== '' ? subscriptionInterpolation : '') + '\n '; | ||
const queryInterpolation = `type Query { | ||
${queryTypes} | ||
}`; | ||
const mutationInterpolation = `type Mutation { | ||
${mutationTypes} | ||
}`; | ||
const subscriptionInterpolation = `type Subscription { | ||
${subscriptionTypes} | ||
}`; | ||
const schema = ` | ||
schema { | ||
query: Query | ||
${cleanupForComparison(mutationTypes) !== '' ? 'mutation: Mutation' : ''} | ||
${cleanupForComparison(subscriptionTypes) !== '' ? 'subscription: Subscription' : ''} | ||
} | ||
var mergedTypes = []; | ||
var allTypes = [inputTypes, enumTypes, scalarTypes, interfaceTypes, unionTypes, customTypes]; | ||
allTypes.forEach(function (t) { | ||
${cleanupForComparison(queryTypes) !== '' ? queryInterpolation : ''} | ||
${cleanupForComparison(mutationTypes) !== '' ? mutationInterpolation : ''} | ||
${cleanupForComparison(subscriptionTypes) !== '' ? subscriptionInterpolation : ''} | ||
`; | ||
let mergedTypes = []; | ||
const allTypes = [inputTypes, enumTypes, scalarTypes, interfaceTypes, unionTypes, customTypes]; | ||
allTypes.forEach(t => { | ||
if (t.length !== 0) { | ||
@@ -97,5 +105,5 @@ mergedTypes = mergedTypes.concat(t); | ||
return [schema].concat((0, _toConsumableArray3.default)(mergedTypes)); | ||
return [schema, ...mergedTypes]; | ||
}; | ||
exports.default = mergeTypes; |
@@ -7,8 +7,2 @@ 'use strict'; | ||
var _taggedTemplateLiteral2 = require('babel-runtime/helpers/taggedTemplateLiteral'); | ||
var _taggedTemplateLiteral3 = _interopRequireDefault(_taggedTemplateLiteral2); | ||
var _templateObject = (0, _taggedTemplateLiteral3.default)(['', ''], ['', '']); | ||
var _graphqlTag = require('graphql-tag'); | ||
@@ -20,5 +14,5 @@ | ||
var validate = function validate(type) { | ||
const validate = type => { | ||
try { | ||
(0, _graphqlTag2.default)(_templateObject, type); // eslint-disable-line | ||
_graphqlTag2.default`${type}`; // eslint-disable-line | ||
} catch (err) { | ||
@@ -32,7 +26,5 @@ if (process.env.NODE_ENV !== 'test') { | ||
exports.default = function (schema, customTypes) { | ||
customTypes.forEach(function (ct) { | ||
return validate(ct); | ||
}); | ||
exports.default = (schema, customTypes) => { | ||
customTypes.forEach(ct => validate(ct)); | ||
validate(schema); | ||
}; |
{ | ||
"name": "merge-graphql-schemas", | ||
"author": "OK GROW!", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Better organize your GraphQL server.", | ||
@@ -27,5 +27,7 @@ "repository": { | ||
"babel-eslint": "4.x.x", | ||
"babel-plugin-transform-runtime": "6.x.x", | ||
"babel-plugin-transform-regenerator": "^6.24.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-polyfill": "6.x.x", | ||
"babel-preset-es2015": "6.x.x", | ||
"babel-preset-node6": "^11.0.0", | ||
"babel-preset-stage-2": "6.x.x", | ||
@@ -32,0 +34,0 @@ "babel-runtime": "6.x.x", |
@@ -12,5 +12,5 @@ import chai from 'chai'; | ||
describe('fileLoader', () => { | ||
describe('with default options', () => { | ||
it('loads all files from specified folder', async () => { | ||
describe('fileLoader', function () { | ||
describe('with default options', function () { | ||
it('loads all files from specified folder', function () { | ||
const types = [clientType, personEntityType, personSearchType, productType, vendorType]; | ||
@@ -17,0 +17,0 @@ const loadedTypes = fileLoader(path.join(__dirname, 'graphql/types')); |
@@ -11,5 +11,5 @@ import assert from 'assert'; | ||
describe('mergeGraphqlSchemas', () => { | ||
describe('mergeGraphqlSchemas', function () { | ||
before(() => { | ||
before(function () { | ||
td.replace('graphql-tools', graphqlToolsMock); | ||
@@ -21,9 +21,9 @@ td.replace('../src/merge_types', mergeTypes); | ||
afterEach(() => { | ||
afterEach(function () { | ||
td.reset(); | ||
}); | ||
describe('passing graphql folder', () => { | ||
describe('passing graphql folder', function () { | ||
it('should pass', async () => { | ||
it('should pass', function () { | ||
mergeGraphqlSchemas(path.join(__dirname, '/graphql')); | ||
@@ -30,0 +30,0 @@ |
@@ -8,6 +8,6 @@ import chai from 'chai'; | ||
describe('mergeResolvers', () => { | ||
describe('with default options', () => { | ||
describe('mergeResolvers', function () { | ||
describe('with default options', function () { | ||
it('merges all query resolvers', async () => { | ||
it('merges all query resolvers', function () { | ||
const resolvers = [clientResolvers, productResolvers]; | ||
@@ -23,3 +23,3 @@ const mergedResolvers = mergeResolvers(resolvers); | ||
it('merges all mutation resolvers', async () => { | ||
it('merges all mutation resolvers', function () { | ||
const resolvers = [clientResolvers, productResolvers]; | ||
@@ -35,3 +35,3 @@ const mergedResolvers = mergeResolvers(resolvers); | ||
it('merges all subQuery resolvers', async () => { | ||
it('merges all subQuery resolvers', function () { | ||
const resolvers = [clientResolvers, productResolvers]; | ||
@@ -38,0 +38,0 @@ const mergedResolvers = mergeResolvers(resolvers); |
@@ -15,5 +15,5 @@ import chai from 'chai'; // eslint-disable-line | ||
describe('mergeTypes', () => { | ||
describe('when no types exist', () => { | ||
it('returns minimal schema', async () => { | ||
describe('mergeTypes', function () { | ||
describe('when no types exist', function () { | ||
it('returns minimal schema', function () { | ||
const types = []; | ||
@@ -33,3 +33,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns empty query type', async () => { | ||
it('returns empty query type', function () { | ||
const types = []; | ||
@@ -48,3 +48,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns no mutation type', async () => { | ||
it('returns no mutation type', function () { | ||
const types = []; | ||
@@ -63,3 +63,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns no subscription type', async () => { | ||
it('returns no subscription type', function () { | ||
const types = []; | ||
@@ -79,4 +79,4 @@ const mergedTypes = mergeTypes(types); | ||
describe('when only query is specified', () => { | ||
it('returns minimal schema', async () => { | ||
describe('when only query is specified', function () { | ||
it('returns minimal schema', function () { | ||
const types = [simpleQueryType]; | ||
@@ -96,3 +96,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns simple query type', async () => { | ||
it('returns simple query type', function () { | ||
const types = [simpleQueryType]; | ||
@@ -112,3 +112,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns no mutation type', async () => { | ||
it('returns no mutation type', function () { | ||
const types = [simpleQueryType]; | ||
@@ -127,3 +127,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns no subscription type', async () => { | ||
it('returns no subscription type', function () { | ||
const types = [simpleQueryType]; | ||
@@ -143,4 +143,4 @@ const mergedTypes = mergeTypes(types); | ||
describe('when only single custom type is passed', () => { | ||
it('includes customType', async () => { | ||
describe('when only single custom type is passed', function () { | ||
it('includes customType', function () { | ||
const types = [customType]; | ||
@@ -162,3 +162,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns minimal schema', async () => { | ||
it('returns minimal schema', function () { | ||
const types = [customType]; | ||
@@ -178,3 +178,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns empty query type', async () => { | ||
it('returns empty query type', function () { | ||
const types = [customType]; | ||
@@ -193,3 +193,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns no mutation type', async () => { | ||
it('returns no mutation type', function () { | ||
const types = [customType]; | ||
@@ -208,3 +208,3 @@ const mergedTypes = mergeTypes(types); | ||
it('returns no subscription type', async () => { | ||
it('returns no subscription type', function () { | ||
const types = [customType]; | ||
@@ -224,3 +224,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes schemaType', async () => { | ||
it('includes schemaType', function () { | ||
const types = [clientType, productType]; | ||
@@ -242,3 +242,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes queryType', async () => { | ||
it('includes queryType', function () { | ||
const types = [clientType, productType]; | ||
@@ -261,3 +261,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes mutationType', async () => { | ||
it('includes mutationType', function () { | ||
const types = [clientType, productType]; | ||
@@ -280,3 +280,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes subscriptionType', async () => { | ||
it('includes subscriptionType', function () { | ||
const types = [clientType, productType]; | ||
@@ -297,3 +297,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes clientType', async () => { | ||
it('includes clientType', function () { | ||
const types = [clientType, productType]; | ||
@@ -318,3 +318,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes productType', async () => { | ||
it('includes productType', function () { | ||
const types = [clientType, productType]; | ||
@@ -338,3 +338,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes first inputType', async () => { | ||
it('includes first inputType', function () { | ||
const types = [clientType, productType]; | ||
@@ -355,3 +355,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes second inputType', async () => { | ||
it('includes second inputType', function () { | ||
const types = [clientType, productType]; | ||
@@ -371,3 +371,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes first product ENUM type', async () => { | ||
it('includes first product ENUM type', function () { | ||
const types = [clientType, productType]; | ||
@@ -389,3 +389,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes second product ENUM type', async () => { | ||
it('includes second product ENUM type', function () { | ||
const types = [clientType, productType]; | ||
@@ -407,3 +407,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes first client ENUM type', async () => { | ||
it('includes first client ENUM type', function () { | ||
const types = [clientType, productType]; | ||
@@ -425,3 +425,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes first client SCALAR type', async () => { | ||
it('includes first client SCALAR type', function () { | ||
const types = [clientType, productType]; | ||
@@ -439,3 +439,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes second client SCALAR type', async () => { | ||
it('includes second client SCALAR type', function () { | ||
const types = [clientType, productType]; | ||
@@ -453,3 +453,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes first product SCALAR type', async () => { | ||
it('includes first product SCALAR type', function () { | ||
const types = [clientType, productType]; | ||
@@ -467,3 +467,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes INTERFACE type', async () => { | ||
it('includes INTERFACE type', function () { | ||
const types = [clientType, productType, vendorType, personEntityType]; | ||
@@ -485,3 +485,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes vendor custom type', async () => { | ||
it('includes vendor custom type', function () { | ||
const types = [clientType, productType, vendorType, personEntityType]; | ||
@@ -504,3 +504,3 @@ const mergedTypes = mergeTypes(types); | ||
it('includes UNION type', async () => { | ||
it('includes UNION type', function () { | ||
const types = [clientType, productType, vendorType, personEntityType, personSearchType]; | ||
@@ -507,0 +507,0 @@ const mergedTypes = mergeTypes(types); |
@@ -6,4 +6,4 @@ import chai from 'chai'; // eslint-disable-line | ||
describe('validateSchema', () => { | ||
describe('with default options', () => { | ||
describe('validateSchema', function () { | ||
describe('with default options', function () { | ||
const validSchema = `schema { | ||
@@ -26,3 +26,3 @@ query: Query, | ||
it('it throws error when schema is invalid', async () => { | ||
it('it throws error when schema is invalid', function () { | ||
const badSchema = `schema { | ||
@@ -44,3 +44,3 @@ query: Query, | ||
it('it throws error when a customType is invalid', async () => { | ||
it('it throws error when a customType is invalid', function () { | ||
const badCustomTypes = [ | ||
@@ -47,0 +47,0 @@ 'type Client {\n id: ID!\n name:\n age: Int\n products: [Product]\n }', |
Sorry, the diff of this file is not supported yet
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
43200
24
919