@graphql-tools/schema-merging
Advanced tools
Comparing version 5.0.1-alpha-cf1d5c6.0 to 5.0.1-alpha-d5fbf81.0
@@ -5,26 +5,6 @@ 'use strict'; | ||
const deepMerge = require('deepmerge'); | ||
const utils = require('@graphql-tools/utils'); | ||
const graphql = require('graphql'); | ||
const utils = require('@graphql-tools/utils'); | ||
const schemaStitching = require('@graphql-tools/schema-stitching'); | ||
const schemaGenerator = require('@graphql-tools/schema-generator'); | ||
const isMergeableObject = (target) => { | ||
if (!target) { | ||
return false; | ||
} | ||
if (typeof target !== 'object') { | ||
return false; | ||
} | ||
const stringValue = Object.prototype.toString.call(target); | ||
if (stringValue === '[object RegExp]') { | ||
return false; | ||
} | ||
if (stringValue === '[object Date]') { | ||
return false; | ||
} | ||
if (graphql.isScalarType(target)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
function mergeResolvers(resolversDefinitions, options) { | ||
@@ -51,7 +31,7 @@ if (!resolversDefinitions || resolversDefinitions.length === 0) { | ||
const resultsOfFactories = resolversFactories.map(factory => factory(...args)); | ||
return deepMerge.all([...resolvers, ...resultsOfFactories], { isMergeableObject }); | ||
return resolvers.concat(resultsOfFactories).reduce(utils.mergeDeep, {}); | ||
}); | ||
} | ||
else { | ||
result = deepMerge.all(resolvers, { isMergeableObject }); | ||
result = resolvers.reduce(utils.mergeDeep, {}); | ||
} | ||
@@ -833,6 +813,6 @@ if (options && options.exclusions) { | ||
function mergeExtensions(extensions) { | ||
return extensions.reduce((result, extensionObj) => deepMerge.all([result, extensionObj]), {}); | ||
return extensions.reduce((result, extensionObj) => [result, extensionObj].reduce(utils.mergeDeep, {}), {}); | ||
} | ||
function applyExtensionObject(obj, extensions) { | ||
obj.extensions = deepMerge.all([obj.extensions || {}, extensions || {}]); | ||
obj.extensions = [obj.extensions || {}, extensions || {}].reduce(utils.mergeDeep, {}); | ||
} | ||
@@ -910,7 +890,7 @@ function applyExtensions(schema, extensions) { | ||
for (const schema of config.schemas) { | ||
extractedResolvers.push(schemaStitching.getResolversFromSchema(schema)); | ||
extractedResolvers.push(utils.getResolversFromSchema(schema)); | ||
extractedExtensions.push(extractExtensionsFromSchema(schema)); | ||
} | ||
extractedResolvers.push(...ensureResolvers(config)); | ||
const resolvers = utils.composeResolvers(mergeResolvers(extractedResolvers, config), config.resolversComposition || {}); | ||
const resolvers = mergeResolvers(extractedResolvers, config); | ||
const extensions = mergeExtensions(extractedExtensions); | ||
@@ -922,3 +902,3 @@ return makeSchema({ resolvers, typeDefs, extensions }, config); | ||
mergeTypes(config), | ||
Promise.all(config.schemas.map(async (schema) => schemaStitching.getResolversFromSchema(schema))).then(extractedResolvers => utils.composeResolvers(mergeResolvers([...extractedResolvers, ...ensureResolvers(config)], config), config.resolversComposition || {})), | ||
Promise.all(config.schemas.map(async (schema) => utils.getResolversFromSchema(schema))).then(extractedResolvers => mergeResolvers([...extractedResolvers, ...ensureResolvers(config)], config)), | ||
Promise.all(config.schemas.map(async (schema) => extractExtensionsFromSchema(schema))).then(extractedExtensions => mergeExtensions(extractedExtensions)), | ||
@@ -938,3 +918,3 @@ ]); | ||
if (resolvers) { | ||
schemaStitching.addResolversToSchema({ | ||
schemaGenerator.addResolversToSchema({ | ||
schema, | ||
@@ -950,7 +930,7 @@ resolvers, | ||
if (config.logger) { | ||
schemaStitching.addErrorLoggingToSchema(schema, config.logger); | ||
schemaGenerator.addErrorLoggingToSchema(schema, config.logger); | ||
} | ||
// use schema directives | ||
if (config.schemaDirectives) { | ||
schemaStitching.SchemaDirectiveVisitor.visitSchemaDirectives(schema, config.schemaDirectives); | ||
utils.SchemaDirectiveVisitor.visitSchemaDirectives(schema, config.schemaDirectives); | ||
} | ||
@@ -957,0 +937,0 @@ // extensions |
@@ -1,25 +0,5 @@ | ||
import { all } from 'deepmerge'; | ||
import { isScalarType, getDescription, visit, print, Source, Kind, isSchema, parse, isSpecifiedScalarType, isIntrospectionType, isObjectType, isInterfaceType, isInputObjectType, isUnionType, isEnumType, buildSchema, buildASTSchema } from 'graphql'; | ||
import { compareNodes, isNotEqual, printSchemaWithDirectives, createSchemaDefinition, asArray, composeResolvers } from '@graphql-tools/utils'; | ||
import { getResolversFromSchema, addResolversToSchema, addErrorLoggingToSchema, SchemaDirectiveVisitor } from '@graphql-tools/schema-stitching'; | ||
import { mergeDeep, compareNodes, isNotEqual, printSchemaWithDirectives, createSchemaDefinition, asArray, getResolversFromSchema, SchemaDirectiveVisitor } from '@graphql-tools/utils'; | ||
import { getDescription, visit, print, Source, Kind, isSchema, parse, isScalarType, isSpecifiedScalarType, isIntrospectionType, isObjectType, isInterfaceType, isInputObjectType, isUnionType, isEnumType, buildSchema, buildASTSchema } from 'graphql'; | ||
import { addResolversToSchema, addErrorLoggingToSchema } from '@graphql-tools/schema-generator'; | ||
const isMergeableObject = (target) => { | ||
if (!target) { | ||
return false; | ||
} | ||
if (typeof target !== 'object') { | ||
return false; | ||
} | ||
const stringValue = Object.prototype.toString.call(target); | ||
if (stringValue === '[object RegExp]') { | ||
return false; | ||
} | ||
if (stringValue === '[object Date]') { | ||
return false; | ||
} | ||
if (isScalarType(target)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
function mergeResolvers(resolversDefinitions, options) { | ||
@@ -46,7 +26,7 @@ if (!resolversDefinitions || resolversDefinitions.length === 0) { | ||
const resultsOfFactories = resolversFactories.map(factory => factory(...args)); | ||
return all([...resolvers, ...resultsOfFactories], { isMergeableObject }); | ||
return resolvers.concat(resultsOfFactories).reduce(mergeDeep, {}); | ||
}); | ||
} | ||
else { | ||
result = all(resolvers, { isMergeableObject }); | ||
result = resolvers.reduce(mergeDeep, {}); | ||
} | ||
@@ -828,6 +808,6 @@ if (options && options.exclusions) { | ||
function mergeExtensions(extensions) { | ||
return extensions.reduce((result, extensionObj) => all([result, extensionObj]), {}); | ||
return extensions.reduce((result, extensionObj) => [result, extensionObj].reduce(mergeDeep, {}), {}); | ||
} | ||
function applyExtensionObject(obj, extensions) { | ||
obj.extensions = all([obj.extensions || {}, extensions || {}]); | ||
obj.extensions = [obj.extensions || {}, extensions || {}].reduce(mergeDeep, {}); | ||
} | ||
@@ -909,3 +889,3 @@ function applyExtensions(schema, extensions) { | ||
extractedResolvers.push(...ensureResolvers(config)); | ||
const resolvers = composeResolvers(mergeResolvers(extractedResolvers, config), config.resolversComposition || {}); | ||
const resolvers = mergeResolvers(extractedResolvers, config); | ||
const extensions = mergeExtensions(extractedExtensions); | ||
@@ -917,3 +897,3 @@ return makeSchema({ resolvers, typeDefs, extensions }, config); | ||
mergeTypes(config), | ||
Promise.all(config.schemas.map(async (schema) => getResolversFromSchema(schema))).then(extractedResolvers => composeResolvers(mergeResolvers([...extractedResolvers, ...ensureResolvers(config)], config), config.resolversComposition || {})), | ||
Promise.all(config.schemas.map(async (schema) => getResolversFromSchema(schema))).then(extractedResolvers => mergeResolvers([...extractedResolvers, ...ensureResolvers(config)], config)), | ||
Promise.all(config.schemas.map(async (schema) => extractExtensionsFromSchema(schema))).then(extractedExtensions => mergeExtensions(extractedExtensions)), | ||
@@ -920,0 +900,0 @@ ]); |
@@ -1,2 +0,2 @@ | ||
import { IResolvers } from '@graphql-tools/schema-stitching'; | ||
import { IResolvers } from '@graphql-tools/utils'; | ||
export declare type ResolversFactory<TContext> = (...args: any[]) => IResolvers<any, TContext>; | ||
@@ -3,0 +3,0 @@ export declare type ResolversDefinition<TContext> = IResolvers<any, TContext> | ResolversFactory<TContext>; |
import { GraphQLSchema, DocumentNode, BuildSchemaOptions } from 'graphql'; | ||
import { IResolvers, SchemaDirectiveVisitor, IResolverValidationOptions, ILogger } from '@graphql-tools/schema-stitching'; | ||
import { Config } from './typedefs-mergers/merge-typedefs'; | ||
import { ResolversComposerMapping } from '@graphql-tools/utils'; | ||
import { IResolvers, SchemaDirectiveVisitor, IResolverValidationOptions, ILogger } from '@graphql-tools/utils'; | ||
export interface MergeSchemasConfig<Resolvers extends IResolvers = IResolvers> extends Config, BuildSchemaOptions { | ||
@@ -9,3 +8,2 @@ schemas: GraphQLSchema[]; | ||
resolvers?: Resolvers | Resolvers[]; | ||
resolversComposition?: ResolversComposerMapping<Resolvers>; | ||
schemaDirectives?: { | ||
@@ -12,0 +10,0 @@ [directiveName: string]: typeof SchemaDirectiveVisitor; |
{ | ||
"name": "@graphql-tools/schema-merging", | ||
"version": "5.0.1-alpha-cf1d5c6.0", | ||
"version": "5.0.1-alpha-d5fbf81.0", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -9,5 +9,4 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@graphql-tools/utils": "5.0.1-alpha-cf1d5c6.0", | ||
"deepmerge": "4.2.2", | ||
"@graphql-tools/schema-stitching": "5.0.1-alpha-cf1d5c6.0", | ||
"@graphql-tools/schema-generator": "5.0.1-alpha-d5fbf81.0", | ||
"@graphql-tools/utils": "5.0.1-alpha-d5fbf81.0", | ||
"tslib": "1.11.1" | ||
@@ -24,5 +23,2 @@ }, | ||
}, | ||
"devDependencies": { | ||
"@types/deepmerge": "2.2.0" | ||
}, | ||
"publishConfig": { | ||
@@ -29,0 +25,0 @@ "access": "public" |
Sorry, the diff of this file is not supported yet
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
4
0
263475
2115
+ Added@graphql-tools/schema-generator@5.0.1-alpha-d5fbf81.0
+ Added@graphql-tools/schema-generator@5.0.1-alpha-d5fbf81.0(transitive)
+ Added@graphql-tools/utils@5.0.1-alpha-d5fbf81.0(transitive)
- Removed@graphql-tools/schema-stitching@5.0.1-alpha-cf1d5c6.0
- Removeddeepmerge@4.2.2
- Removed@graphql-tools/schema-stitching@5.0.1-alpha-cf1d5c6.0(transitive)
- Removed@graphql-tools/utils@5.0.1-alpha-cf1d5c6.0(transitive)
- Removedaggregate-error@3.0.1(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removeddeepmerge@4.2.2(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedlodash@4.17.15(transitive)