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

@graphql-toolkit/schema-merging

Package Overview
Dependencies
Maintainers
3
Versions
704
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-toolkit/schema-merging - npm Package Compare versions

Comparing version 0.10.2 to 0.10.3-alpha-0a56f31.6

62

index.cjs.js

@@ -8,3 +8,3 @@ 'use strict';

const common = require('@graphql-toolkit/common');
const graphqlToolsFork = require('graphql-tools-fork');
const schema = require('@graphql-toolkit/schema');

@@ -50,3 +50,3 @@ const isMergeableObject = (target) => {

result = ((...args) => {
const resultsOfFactories = resolversFactories.map(factory => factory(...args));
const resultsOfFactories = resolversFactories.map((factory) => factory(...args));
return deepMerge.all([...resolvers, ...resultsOfFactories], { isMergeableObject });

@@ -73,3 +73,3 @@ });

function mergeArguments(args1, args2, config) {
const result = deduplicateArguments([].concat(args2, args1).filter(a => a));
const result = deduplicateArguments([].concat(args2, args1).filter((a) => a));
if (config && config.sort) {

@@ -82,3 +82,3 @@ result.sort(common.compareNodes);

return args.reduce((acc, current) => {
const dup = acc.find(arg => arg.name.value === current.name.value);
const dup = acc.find((arg) => arg.name.value === current.name.value);
if (!dup) {

@@ -100,3 +100,3 @@ return acc.concat([current]);

case 'EnumTypeDefinition':
node.values.forEach(value => {
node.values.forEach((value) => {
pushComment(value, entityName, value.name.value);

@@ -112,3 +112,3 @@ });

if (isFieldDefinitionNode(field) && field.arguments) {
field.arguments.forEach(arg => {
field.arguments.forEach((arg) => {
pushComment(arg, entityName, field.name.value, arg.name.value);

@@ -159,3 +159,3 @@ });

function join(maybeArray, separator) {
return maybeArray ? maybeArray.filter(x => x).join(separator || '') : '';
return maybeArray ? maybeArray.filter((x) => x).join(separator || '') : '';
}

@@ -214,10 +214,10 @@ function addDescription(cb) {

leave: {
Name: node => node.value,
Variable: node => `$${node.name}`,
Name: (node) => node.value,
Variable: (node) => `$${node.name}`,
// Document
Document: node => `${node.definitions
.map(defNode => `${defNode}\n${defNode[0] === '#' ? '' : '\n'}`)
Document: (node) => `${node.definitions
.map((defNode) => `${defNode}\n${defNode[0] === '#' ? '' : '\n'}`)
.join('')
.trim()}\n`,
OperationTypeDefinition: node => `${node.operation}: ${node.type}`,
OperationTypeDefinition: (node) => `${node.operation}: ${node.type}`,
VariableDefinition: ({ variable, type, defaultValue }) => `${variable}: ${type}${wrap(' = ', defaultValue)}`,

@@ -474,3 +474,3 @@ SelectionSet: ({ selections }) => block(selections),

function fieldAlreadyExists(fieldsArr, otherField) {
const result = fieldsArr.find(field => field.name.value === otherField.name.value);
const result = fieldsArr.find((field) => field.name.value === otherField.name.value);
if (result) {

@@ -511,3 +511,3 @@ const t1 = extractType(result.type);

if (config && config.exclusions) {
return result.filter(field => !config.exclusions.includes(`${type.name.value}.${field.name.value}`));
return result.filter((field) => !config.exclusions.includes(`${type.name.value}.${field.name.value}`));
}

@@ -604,6 +604,6 @@ return result;

function alreadyExists(arr, other) {
return !!arr.find(i => i.name.value === other.name.value);
return !!arr.find((i) => i.name.value === other.name.value);
}
function mergeNamedTypeArray(first, second, config) {
const result = [...second, ...first.filter(d => !alreadyExists(second, d))];
const result = [...second, ...first.filter((d) => !alreadyExists(second, d))];
if (config && config.sort) {

@@ -741,3 +741,3 @@ result.sort(common.compareNodes);

const allNodes = types
.map(type => {
.map((type) => {
if (graphql.isSchema(type)) {

@@ -751,3 +751,3 @@ return graphql.parse(common.printSchemaWithDirectives(type));

})
.map(ast => ast.definitions)
.map((ast) => ast.definitions)
.reduce((defs, newDef = []) => [...defs, ...newDef], []);

@@ -757,4 +757,4 @@ // XXX: right now we don't handle multiple schema definitions

node.operationTypes
.filter(op => op.type.name.value)
.forEach(op => {
.filter((op) => op.type.name.value)
.forEach((op) => {
def[op.operation] = op.type.name.value;

@@ -774,5 +774,7 @@ });

if (config && config.useSchemaDefinition) {
const queryType = schemaDef.query ? schemaDef.query : allTypes.find(t => t === 'Query');
const mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find(t => t === 'Mutation');
const subscriptionType = schemaDef.subscription ? schemaDef.subscription : allTypes.find(t => t === 'Subscription');
const queryType = schemaDef.query ? schemaDef.query : allTypes.find((t) => t === 'Query');
const mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find((t) => t === 'Mutation');
const subscriptionType = schemaDef.subscription
? schemaDef.subscription
: allTypes.find((t) => t === 'Subscription');
schemaDef = {

@@ -945,7 +947,7 @@ query: queryType,

function makeSchema({ resolvers, typeDefs, extensions, }, config) {
let schema = typeof typeDefs === 'string' ? graphql.buildSchema(typeDefs, config) : graphql.buildASTSchema(typeDefs, config);
let schema$1 = typeof typeDefs === 'string' ? graphql.buildSchema(typeDefs, config) : graphql.buildASTSchema(typeDefs, config);
// add resolvers
if (resolvers) {
graphqlToolsFork.addResolveFunctionsToSchema({
schema,
schema.addResolversToSchema({
schema: schema$1,
resolvers,

@@ -960,11 +962,11 @@ resolverValidationOptions: {

if (config.logger) {
graphqlToolsFork.addErrorLoggingToSchema(schema, config.logger);
schema.addErrorLoggingToSchema(schema$1, config.logger);
}
// use schema directives
if (config.schemaDirectives) {
graphqlToolsFork.SchemaDirectiveVisitor.visitSchemaDirectives(schema, config.schemaDirectives);
schema.SchemaDirectiveVisitor.visitSchemaDirectives(schema$1, config.schemaDirectives);
}
// extensions
applyExtensions(schema, extensions);
return schema;
applyExtensions(schema$1, extensions);
return schema$1;
}

@@ -971,0 +973,0 @@

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, extractResolversFromSchema, composeResolvers } from '@graphql-toolkit/common';
import { addResolveFunctionsToSchema, addErrorLoggingToSchema, SchemaDirectiveVisitor } from 'graphql-tools-fork';
import { addResolversToSchema, addErrorLoggingToSchema, SchemaDirectiveVisitor } from '@graphql-toolkit/schema';

@@ -45,3 +45,3 @@ const isMergeableObject = (target) => {

result = ((...args) => {
const resultsOfFactories = resolversFactories.map(factory => factory(...args));
const resultsOfFactories = resolversFactories.map((factory) => factory(...args));
return all([...resolvers, ...resultsOfFactories], { isMergeableObject });

@@ -68,3 +68,3 @@ });

function mergeArguments(args1, args2, config) {
const result = deduplicateArguments([].concat(args2, args1).filter(a => a));
const result = deduplicateArguments([].concat(args2, args1).filter((a) => a));
if (config && config.sort) {

@@ -77,3 +77,3 @@ result.sort(compareNodes);

return args.reduce((acc, current) => {
const dup = acc.find(arg => arg.name.value === current.name.value);
const dup = acc.find((arg) => arg.name.value === current.name.value);
if (!dup) {

@@ -95,3 +95,3 @@ return acc.concat([current]);

case 'EnumTypeDefinition':
node.values.forEach(value => {
node.values.forEach((value) => {
pushComment(value, entityName, value.name.value);

@@ -107,3 +107,3 @@ });

if (isFieldDefinitionNode(field) && field.arguments) {
field.arguments.forEach(arg => {
field.arguments.forEach((arg) => {
pushComment(arg, entityName, field.name.value, arg.name.value);

@@ -154,3 +154,3 @@ });

function join(maybeArray, separator) {
return maybeArray ? maybeArray.filter(x => x).join(separator || '') : '';
return maybeArray ? maybeArray.filter((x) => x).join(separator || '') : '';
}

@@ -209,10 +209,10 @@ function addDescription(cb) {

leave: {
Name: node => node.value,
Variable: node => `$${node.name}`,
Name: (node) => node.value,
Variable: (node) => `$${node.name}`,
// Document
Document: node => `${node.definitions
.map(defNode => `${defNode}\n${defNode[0] === '#' ? '' : '\n'}`)
Document: (node) => `${node.definitions
.map((defNode) => `${defNode}\n${defNode[0] === '#' ? '' : '\n'}`)
.join('')
.trim()}\n`,
OperationTypeDefinition: node => `${node.operation}: ${node.type}`,
OperationTypeDefinition: (node) => `${node.operation}: ${node.type}`,
VariableDefinition: ({ variable, type, defaultValue }) => `${variable}: ${type}${wrap(' = ', defaultValue)}`,

@@ -469,3 +469,3 @@ SelectionSet: ({ selections }) => block(selections),

function fieldAlreadyExists(fieldsArr, otherField) {
const result = fieldsArr.find(field => field.name.value === otherField.name.value);
const result = fieldsArr.find((field) => field.name.value === otherField.name.value);
if (result) {

@@ -506,3 +506,3 @@ const t1 = extractType(result.type);

if (config && config.exclusions) {
return result.filter(field => !config.exclusions.includes(`${type.name.value}.${field.name.value}`));
return result.filter((field) => !config.exclusions.includes(`${type.name.value}.${field.name.value}`));
}

@@ -599,6 +599,6 @@ return result;

function alreadyExists(arr, other) {
return !!arr.find(i => i.name.value === other.name.value);
return !!arr.find((i) => i.name.value === other.name.value);
}
function mergeNamedTypeArray(first, second, config) {
const result = [...second, ...first.filter(d => !alreadyExists(second, d))];
const result = [...second, ...first.filter((d) => !alreadyExists(second, d))];
if (config && config.sort) {

@@ -736,3 +736,3 @@ result.sort(compareNodes);

const allNodes = types
.map(type => {
.map((type) => {
if (isSchema(type)) {

@@ -746,3 +746,3 @@ return parse(printSchemaWithDirectives(type));

})
.map(ast => ast.definitions)
.map((ast) => ast.definitions)
.reduce((defs, newDef = []) => [...defs, ...newDef], []);

@@ -752,4 +752,4 @@ // XXX: right now we don't handle multiple schema definitions

node.operationTypes
.filter(op => op.type.name.value)
.forEach(op => {
.filter((op) => op.type.name.value)
.forEach((op) => {
def[op.operation] = op.type.name.value;

@@ -769,5 +769,7 @@ });

if (config && config.useSchemaDefinition) {
const queryType = schemaDef.query ? schemaDef.query : allTypes.find(t => t === 'Query');
const mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find(t => t === 'Mutation');
const subscriptionType = schemaDef.subscription ? schemaDef.subscription : allTypes.find(t => t === 'Subscription');
const queryType = schemaDef.query ? schemaDef.query : allTypes.find((t) => t === 'Query');
const mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find((t) => t === 'Mutation');
const subscriptionType = schemaDef.subscription
? schemaDef.subscription
: allTypes.find((t) => t === 'Subscription');
schemaDef = {

@@ -943,3 +945,3 @@ query: queryType,

if (resolvers) {
addResolveFunctionsToSchema({
addResolversToSchema({
schema,

@@ -946,0 +948,0 @@ resolvers,

@@ -1,2 +0,2 @@

import { IResolvers } from 'graphql-tools-fork';
import { IResolvers } from '@graphql-toolkit/types';
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-fork';
import { SchemaDirectiveVisitor, IResolverValidationOptions } from '@graphql-toolkit/schema';
import { ResolversComposerMapping } from '@graphql-toolkit/common';
import { IResolvers, ILogger } from '@graphql-toolkit/types';
import { Config } from './typedefs-mergers/merge-typedefs';
import { ResolversComposerMapping } from '@graphql-toolkit/common';
export interface MergeSchemasConfig<Resolvers extends IResolvers = IResolvers> extends Config, BuildSchemaOptions {

@@ -6,0 +7,0 @@ schemas: GraphQLSchema[];

{
"name": "@graphql-toolkit/schema-merging",
"version": "0.10.2",
"version": "0.10.3-alpha-0a56f31.6+0a56f31",
"description": "A set of utils for faster development of GraphQL tools",

@@ -18,8 +18,9 @@ "peerDependencies": {

"dependencies": {
"@graphql-toolkit/common": "0.10.2",
"@graphql-toolkit/common": "0.10.3-alpha-0a56f31.6+0a56f31",
"@graphql-toolkit/schema": "0.10.3-alpha-0a56f31.6+0a56f31",
"@graphql-toolkit/types": "0.10.3-alpha-0a56f31.6+0a56f31",
"deepmerge": "4.2.2",
"graphql-tools-fork": "9.0.1",
"tslib": "1.11.1"
"tslib": "^1.11.1"
},
"sideEffects": false
}

@@ -0,5 +1,5 @@

import { FieldDefinitionNode, InputValueDefinitionNode, NameNode } from 'graphql';
import { Config } from './merge-typedefs';
import { FieldDefinitionNode, InputValueDefinitionNode, NameNode } from 'graphql';
export declare function mergeFields<T extends FieldDefinitionNode | InputValueDefinitionNode>(type: {
name: NameNode;
}, f1: ReadonlyArray<T>, f2: ReadonlyArray<T>, config: Config): T[];

@@ -1,4 +0,4 @@

import { Config } from './merge-typedefs';
import { InputObjectTypeDefinitionNode } from 'graphql';
import { InputObjectTypeExtensionNode } from 'graphql/language/ast';
import { Config } from './merge-typedefs';
export declare function mergeInputType(node: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode, existingNode: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode, config?: Config): InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode;

@@ -0,3 +1,3 @@

import { InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs';
import { InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode } from 'graphql';
export declare function mergeInterface(node: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, existingNode: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, config: Config): InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode;

@@ -0,3 +1,3 @@

import { DefinitionNode } from 'graphql';
import { Config } from './merge-typedefs';
import { DefinitionNode } from 'graphql';
export declare type MergedResultMap = {

@@ -4,0 +4,0 @@ [name: string]: DefinitionNode;

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