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

@graphql-tools/delegate

Package Overview
Dependencies
Maintainers
3
Versions
1527
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/delegate - npm Package Compare versions

Comparing version 6.0.0-alpha-b3f9b0a.0 to 6.0.0-alpha-b40891f.0

transforms/AddFragmentsByField.d.ts

75

index.cjs.js

@@ -427,9 +427,9 @@ 'use strict';

class AddReplacementSelectionSets {
constructor(schema, mapping) {
this.schema = schema;
class AddFragmentsByField {
constructor(targetSchema, mapping) {
this.targetSchema = targetSchema;
this.mapping = mapping;
}
transformRequest(originalRequest) {
const document = replaceFieldsWithSelectionSet(this.schema, originalRequest.document, this.mapping);
const document = addFragmentsByField(this.targetSchema, originalRequest.document, this.mapping);
return {

@@ -441,4 +441,4 @@ ...originalRequest,

}
function replaceFieldsWithSelectionSet(schema, document, mapping) {
const typeInfo = new graphql.TypeInfo(schema);
function addFragmentsByField(targetSchema, document, mapping) {
const typeInfo = new graphql.TypeInfo(targetSchema);
return graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, {

@@ -454,5 +454,5 @@ [graphql.Kind.SELECTION_SET](node) {

const name = selection.name.value;
const selectionSet = mapping[parentTypeName][name];
if (selectionSet != null) {
selections = selections.concat(selectionSet.selections);
const fragment = mapping[parentTypeName][name];
if (fragment != null) {
selections = selections.concat(fragment);
}

@@ -473,9 +473,9 @@ }

class AddReplacementFragments {
constructor(targetSchema, mapping) {
this.targetSchema = targetSchema;
class AddSelectionSetsByField {
constructor(schema, mapping) {
this.schema = schema;
this.mapping = mapping;
}
transformRequest(originalRequest) {
const document = replaceFieldsWithFragments(this.targetSchema, originalRequest.document, this.mapping);
const document = addSelectionSetsByField(this.schema, originalRequest.document, this.mapping);
return {

@@ -487,4 +487,4 @@ ...originalRequest,

}
function replaceFieldsWithFragments(targetSchema, document, mapping) {
const typeInfo = new graphql.TypeInfo(targetSchema);
function addSelectionSetsByField(schema, document, mapping) {
const typeInfo = new graphql.TypeInfo(schema);
return graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, {

@@ -500,5 +500,5 @@ [graphql.Kind.SELECTION_SET](node) {

const name = selection.name.value;
const fragment = mapping[parentTypeName][name];
if (fragment != null) {
selections = selections.concat(fragment);
const selectionSet = mapping[parentTypeName][name];
if (selectionSet != null) {
selections = selections.concat(selectionSet.selections);
}

@@ -519,3 +519,3 @@ }

class AddMergedTypeFragments {
class AddSelectionSetsByType {
constructor(targetSchema, mapping) {

@@ -526,3 +526,3 @@ this.targetSchema = targetSchema;

transformRequest(originalRequest) {
const document = addMergedTypeSelectionSets(this.targetSchema, originalRequest.document, this.mapping);
const document = addSelectionSetsByType(this.targetSchema, originalRequest.document, this.mapping);
return {

@@ -534,3 +534,3 @@ ...originalRequest,

}
function addMergedTypeSelectionSets(targetSchema, document, mapping) {
function addSelectionSetsByType(targetSchema, document, mapping) {
const typeInfo = new graphql.TypeInfo(targetSchema);

@@ -544,3 +544,3 @@ return graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, {

if (parentTypeName in mapping) {
const selectionSet = mapping[parentTypeName].selectionSet;
const selectionSet = mapping[parentTypeName];
if (selectionSet != null) {

@@ -791,9 +791,11 @@ selections = selections.concat(selectionSet.selections);

function handleObject(type, object, errors, subschema, context, info, skipTypeMerging) {
var _a;
const stitchingInfo = (_a = info === null || info === void 0 ? void 0 : info.schema.extensions) === null || _a === void 0 ? void 0 : _a.stitchingInfo;
utils.setErrors(object, errors.map(error => utils.slicedError(error)));
setObjectSubschema(object, subschema);
if (skipTypeMerging || !(info === null || info === void 0 ? void 0 : info.mergeInfo)) {
if (skipTypeMerging || !stitchingInfo) {
return object;
}
const typeName = graphql.isAbstractType(type) ? info.schema.getTypeMap()[object.__typename].name : type.name;
const mergedTypeInfo = info.mergeInfo.mergedTypes[typeName];
const mergedTypeInfo = stitchingInfo.mergedTypes[typeName];
let targetSubschemas;

@@ -1124,11 +1126,12 @@ if (mergedTypeInfo != null) {

function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, transformedSchema, skipTypeMerging) {
var _a;
var _a, _b;
const stitchingInfo = (_a = info === null || info === void 0 ? void 0 : info.schema.extensions) === null || _a === void 0 ? void 0 : _a.stitchingInfo;
let delegationTransforms = [
new CheckResultAndHandleErrors(info, fieldName, subschemaOrSubschemaConfig, context, returnType, skipTypeMerging),
];
if ((info === null || info === void 0 ? void 0 : info.mergeInfo) != null) {
delegationTransforms.push(new AddReplacementSelectionSets(info.schema, info.mergeInfo.replacementSelectionSets), new AddMergedTypeFragments(info.schema, info.mergeInfo.mergedTypes));
if (stitchingInfo != null) {
delegationTransforms.push(new AddSelectionSetsByField(info.schema, stitchingInfo.selectionSetsByField), new AddSelectionSetsByType(info.schema, stitchingInfo.selectionSetsByType));
}
const transformedTargetSchema = (info === null || info === void 0 ? void 0 : info.mergeInfo) == null
? transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : targetSchema : (_a = transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : info.mergeInfo.transformedSchemas.get(subschemaOrSubschemaConfig)) !== null && _a !== void 0 ? _a : targetSchema;
const transformedTargetSchema = stitchingInfo == null
? transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : targetSchema : (_b = transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : stitchingInfo.transformedSchemas.get(subschemaOrSubschemaConfig)) !== null && _b !== void 0 ? _b : targetSchema;
delegationTransforms.push(new WrapConcreteTypes(returnType, transformedTargetSchema));

@@ -1139,4 +1142,4 @@ if (info != null) {

delegationTransforms = delegationTransforms.concat(transforms);
if ((info === null || info === void 0 ? void 0 : info.mergeInfo) != null) {
delegationTransforms.push(new AddReplacementFragments(targetSchema, info.mergeInfo.replacementFragments));
if (stitchingInfo != null) {
delegationTransforms.push(new AddFragmentsByField(targetSchema, stitchingInfo.fragmentsByField));
}

@@ -1292,3 +1295,3 @@ if (args != null) {

transformRequest(originalRequest) {
const document = replaceFieldsWithFragments$1(this.targetSchema, originalRequest.document, this.mapping);
const document = replaceFieldsWithFragments(this.targetSchema, originalRequest.document, this.mapping);
return {

@@ -1300,3 +1303,3 @@ ...originalRequest,

}
function replaceFieldsWithFragments$1(targetSchema, document, mapping) {
function replaceFieldsWithFragments(targetSchema, document, mapping) {
const typeInfo = new graphql.TypeInfo(targetSchema);

@@ -1354,5 +1357,5 @@ return graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, {

exports.AddArgumentsAsVariables = AddArgumentsAsVariables;
exports.AddMergedTypeSelectionSets = AddMergedTypeFragments;
exports.AddReplacementFragments = AddReplacementFragments;
exports.AddReplacementSelectionSets = AddReplacementSelectionSets;
exports.AddFragmentsByField = AddFragmentsByField;
exports.AddMergedTypeSelectionSets = AddSelectionSetsByType;
exports.AddSelectionSetsByField = AddSelectionSetsByField;
exports.AddTypenameToAbstract = AddTypenameToAbstract;

@@ -1359,0 +1362,0 @@ exports.CheckResultAndHandleErrors = CheckResultAndHandleErrors;

@@ -423,9 +423,9 @@ import { visit, visitWithTypeInfo, Kind, getNamedType, isAbstractType, TypeInfo, isObjectType, isInterfaceType, TypeNameMetaFieldDef, getNullableType, isLeafType, isCompositeType, isListType, typeFromAST, isSchema, getOperationAST, validate, execute, subscribe, defaultFieldResolver, parse } from 'graphql';

class AddReplacementSelectionSets {
constructor(schema, mapping) {
this.schema = schema;
class AddFragmentsByField {
constructor(targetSchema, mapping) {
this.targetSchema = targetSchema;
this.mapping = mapping;
}
transformRequest(originalRequest) {
const document = replaceFieldsWithSelectionSet(this.schema, originalRequest.document, this.mapping);
const document = addFragmentsByField(this.targetSchema, originalRequest.document, this.mapping);
return {

@@ -437,4 +437,4 @@ ...originalRequest,

}
function replaceFieldsWithSelectionSet(schema, document, mapping) {
const typeInfo = new TypeInfo(schema);
function addFragmentsByField(targetSchema, document, mapping) {
const typeInfo = new TypeInfo(targetSchema);
return visit(document, visitWithTypeInfo(typeInfo, {

@@ -450,5 +450,5 @@ [Kind.SELECTION_SET](node) {

const name = selection.name.value;
const selectionSet = mapping[parentTypeName][name];
if (selectionSet != null) {
selections = selections.concat(selectionSet.selections);
const fragment = mapping[parentTypeName][name];
if (fragment != null) {
selections = selections.concat(fragment);
}

@@ -469,9 +469,9 @@ }

class AddReplacementFragments {
constructor(targetSchema, mapping) {
this.targetSchema = targetSchema;
class AddSelectionSetsByField {
constructor(schema, mapping) {
this.schema = schema;
this.mapping = mapping;
}
transformRequest(originalRequest) {
const document = replaceFieldsWithFragments(this.targetSchema, originalRequest.document, this.mapping);
const document = addSelectionSetsByField(this.schema, originalRequest.document, this.mapping);
return {

@@ -483,4 +483,4 @@ ...originalRequest,

}
function replaceFieldsWithFragments(targetSchema, document, mapping) {
const typeInfo = new TypeInfo(targetSchema);
function addSelectionSetsByField(schema, document, mapping) {
const typeInfo = new TypeInfo(schema);
return visit(document, visitWithTypeInfo(typeInfo, {

@@ -496,5 +496,5 @@ [Kind.SELECTION_SET](node) {

const name = selection.name.value;
const fragment = mapping[parentTypeName][name];
if (fragment != null) {
selections = selections.concat(fragment);
const selectionSet = mapping[parentTypeName][name];
if (selectionSet != null) {
selections = selections.concat(selectionSet.selections);
}

@@ -515,3 +515,3 @@ }

class AddMergedTypeFragments {
class AddSelectionSetsByType {
constructor(targetSchema, mapping) {

@@ -522,3 +522,3 @@ this.targetSchema = targetSchema;

transformRequest(originalRequest) {
const document = addMergedTypeSelectionSets(this.targetSchema, originalRequest.document, this.mapping);
const document = addSelectionSetsByType(this.targetSchema, originalRequest.document, this.mapping);
return {

@@ -530,3 +530,3 @@ ...originalRequest,

}
function addMergedTypeSelectionSets(targetSchema, document, mapping) {
function addSelectionSetsByType(targetSchema, document, mapping) {
const typeInfo = new TypeInfo(targetSchema);

@@ -540,3 +540,3 @@ return visit(document, visitWithTypeInfo(typeInfo, {

if (parentTypeName in mapping) {
const selectionSet = mapping[parentTypeName].selectionSet;
const selectionSet = mapping[parentTypeName];
if (selectionSet != null) {

@@ -787,9 +787,11 @@ selections = selections.concat(selectionSet.selections);

function handleObject(type, object, errors, subschema, context, info, skipTypeMerging) {
var _a;
const stitchingInfo = (_a = info === null || info === void 0 ? void 0 : info.schema.extensions) === null || _a === void 0 ? void 0 : _a.stitchingInfo;
setErrors(object, errors.map(error => slicedError(error)));
setObjectSubschema(object, subschema);
if (skipTypeMerging || !(info === null || info === void 0 ? void 0 : info.mergeInfo)) {
if (skipTypeMerging || !stitchingInfo) {
return object;
}
const typeName = isAbstractType(type) ? info.schema.getTypeMap()[object.__typename].name : type.name;
const mergedTypeInfo = info.mergeInfo.mergedTypes[typeName];
const mergedTypeInfo = stitchingInfo.mergedTypes[typeName];
let targetSubschemas;

@@ -1120,11 +1122,12 @@ if (mergedTypeInfo != null) {

function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, transformedSchema, skipTypeMerging) {
var _a;
var _a, _b;
const stitchingInfo = (_a = info === null || info === void 0 ? void 0 : info.schema.extensions) === null || _a === void 0 ? void 0 : _a.stitchingInfo;
let delegationTransforms = [
new CheckResultAndHandleErrors(info, fieldName, subschemaOrSubschemaConfig, context, returnType, skipTypeMerging),
];
if ((info === null || info === void 0 ? void 0 : info.mergeInfo) != null) {
delegationTransforms.push(new AddReplacementSelectionSets(info.schema, info.mergeInfo.replacementSelectionSets), new AddMergedTypeFragments(info.schema, info.mergeInfo.mergedTypes));
if (stitchingInfo != null) {
delegationTransforms.push(new AddSelectionSetsByField(info.schema, stitchingInfo.selectionSetsByField), new AddSelectionSetsByType(info.schema, stitchingInfo.selectionSetsByType));
}
const transformedTargetSchema = (info === null || info === void 0 ? void 0 : info.mergeInfo) == null
? transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : targetSchema : (_a = transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : info.mergeInfo.transformedSchemas.get(subschemaOrSubschemaConfig)) !== null && _a !== void 0 ? _a : targetSchema;
const transformedTargetSchema = stitchingInfo == null
? transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : targetSchema : (_b = transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : stitchingInfo.transformedSchemas.get(subschemaOrSubschemaConfig)) !== null && _b !== void 0 ? _b : targetSchema;
delegationTransforms.push(new WrapConcreteTypes(returnType, transformedTargetSchema));

@@ -1135,4 +1138,4 @@ if (info != null) {

delegationTransforms = delegationTransforms.concat(transforms);
if ((info === null || info === void 0 ? void 0 : info.mergeInfo) != null) {
delegationTransforms.push(new AddReplacementFragments(targetSchema, info.mergeInfo.replacementFragments));
if (stitchingInfo != null) {
delegationTransforms.push(new AddFragmentsByField(targetSchema, stitchingInfo.fragmentsByField));
}

@@ -1288,3 +1291,3 @@ if (args != null) {

transformRequest(originalRequest) {
const document = replaceFieldsWithFragments$1(this.targetSchema, originalRequest.document, this.mapping);
const document = replaceFieldsWithFragments(this.targetSchema, originalRequest.document, this.mapping);
return {

@@ -1296,3 +1299,3 @@ ...originalRequest,

}
function replaceFieldsWithFragments$1(targetSchema, document, mapping) {
function replaceFieldsWithFragments(targetSchema, document, mapping) {
const typeInfo = new TypeInfo(targetSchema);

@@ -1349,3 +1352,3 @@ return visit(document, visitWithTypeInfo(typeInfo, {

export { AddArgumentsAsVariables, AddMergedTypeFragments as AddMergedTypeSelectionSets, AddReplacementFragments, AddReplacementSelectionSets, AddTypenameToAbstract, CheckResultAndHandleErrors, ExpandAbstractTypes, FilterToSchema, ReplaceFieldWithFragment, checkResultAndHandleErrors, createMergedResolver, createRequest, createRequestFromInfo, defaultMergedResolver, delegateRequest, delegateToSchema, getSubschema, handleResult, isSubschemaConfig };
export { AddArgumentsAsVariables, AddFragmentsByField, AddSelectionSetsByType as AddMergedTypeSelectionSets, AddSelectionSetsByField, AddTypenameToAbstract, CheckResultAndHandleErrors, ExpandAbstractTypes, FilterToSchema, ReplaceFieldWithFragment, checkResultAndHandleErrors, createMergedResolver, createRequest, createRequestFromInfo, defaultMergedResolver, delegateRequest, delegateToSchema, getSubschema, handleResult, isSubschemaConfig };
//# sourceMappingURL=index.esm.js.map
{
"name": "@graphql-tools/delegate",
"version": "6.0.0-alpha-b3f9b0a.0",
"version": "6.0.0-alpha-b40891f.0",
"description": "A set of utils for faster development of GraphQL tools",
"sideEffects": false,
"peerDependencies": {

@@ -9,5 +10,5 @@ "graphql": "^14.0.0 || ^15.0.0"

"dependencies": {
"@graphql-tools/schema": "6.0.0-alpha-b3f9b0a.0",
"@graphql-tools/utils": "6.0.0-alpha-b3f9b0a.0",
"tslib": "1.11.1"
"@graphql-tools/schema": "6.0.0-alpha-b40891f.0",
"@graphql-tools/utils": "6.0.0-alpha-b40891f.0",
"tslib": "~2.0.0"
},

@@ -14,0 +15,0 @@ "repository": "git@github.com:ardatan/graphql-tools.git",

export { default as CheckResultAndHandleErrors } from './CheckResultAndHandleErrors';
export { checkResultAndHandleErrors } from './CheckResultAndHandleErrors';
export { default as ExpandAbstractTypes } from './ExpandAbstractTypes';
export { default as AddReplacementSelectionSets } from './AddReplacementSelectionSets';
export { default as AddMergedTypeSelectionSets } from './AddMergedTypeSelectionSets';
export { default as AddSelectionSetsByField } from './AddSelectionSetsByField';
export { default as AddMergedTypeSelectionSets } from './AddSelectionSetsByType';
export { default as AddArgumentsAsVariables } from './AddArgumentsAsVariables';

@@ -10,2 +10,2 @@ export { default as FilterToSchema } from './FilterToSchema';

export { default as ReplaceFieldWithFragment } from './ReplaceFieldWithFragment';
export { default as AddReplacementFragments } from './AddReplacementFragments';
export { default as AddFragmentsByField } from './AddFragmentsByField';

@@ -84,13 +84,10 @@ import { GraphQLSchema, GraphQLOutputType, SelectionSetNode, FieldNode, DocumentNode, GraphQLResolveInfo, GraphQLFieldResolver, InlineFragmentNode, FragmentDefinitionNode, GraphQLObjectType, VariableDefinitionNode } from 'graphql';

}
export interface ReplacementSelectionSetMapping {
[typeName: string]: {
[fieldName: string]: SelectionSetNode;
};
}
export interface ReplacementFragmentMapping {
[typeName: string]: {
[fieldName: string]: InlineFragmentNode;
};
}
export declare type MergedTypeResolver = (originalResult: any, context: Record<string, any>, info: GraphQLResolveInfo, subschema: GraphQLSchema | SubschemaConfig, selectionSet: SelectionSetNode) => any;
export declare function isSubschemaConfig(value: any): value is SubschemaConfig;
export interface StitchingInfo {
transformedSchemas: Map<GraphQLSchema | SubschemaConfig, GraphQLSchema>;
fragmentsByField: Record<string, Record<string, InlineFragmentNode>>;
selectionSetsByField: Record<string, Record<string, SelectionSetNode>>;
selectionSetsByType: Record<string, SelectionSetNode>;
mergedTypes: Record<string, MergedTypeInfo>;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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