@graphql-tools/delegate
Advanced tools
Comparing version 6.0.0-alpha.1 to 6.0.0-alpha.2
import { GraphQLSchema, GraphQLObjectType, OperationTypeNode } from 'graphql'; | ||
import { Request, ICreateRequest } from '@graphql-tools/utils'; | ||
import { ICreateRequestFromInfo } from './types'; | ||
import { Request } from '@graphql-tools/utils'; | ||
import { ICreateRequestFromInfo, ICreateRequest } from './types'; | ||
export declare function getDelegatingOperation(parentType: GraphQLObjectType, schema: GraphQLSchema): OperationTypeNode; | ||
export declare function createRequestFromInfo({ info, operation, fieldName, selectionSet, fieldNodes, }: ICreateRequestFromInfo): Request; | ||
export declare function createRequest({ sourceSchema, sourceParentType, sourceFieldName, fragments, variableDefinitions, variableValues, targetOperation, targetFieldName, selectionSet, fieldNodes, }: ICreateRequest): Request; |
import { GraphQLSchema } from 'graphql'; | ||
import { IDelegateToSchemaOptions, IDelegateRequestOptions } from './types'; | ||
export declare function delegateToSchema(options: IDelegateToSchemaOptions | GraphQLSchema): any; | ||
export declare function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation, fieldName, args, returnType, context, transforms, skipValidation, skipTypeMerging, }: IDelegateRequestOptions): any; | ||
export declare function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation, fieldName, args, returnType, context, transforms, transformedSchema, skipValidation, skipTypeMerging, }: IDelegateRequestOptions): any; |
239
index.cjs.js
@@ -171,2 +171,62 @@ 'use strict'; | ||
// For motivation, see https://github.com/ardatan/graphql-tools/issues/751 | ||
class WrapConcreteTypes { | ||
constructor(returnType, targetSchema) { | ||
this.returnType = returnType; | ||
this.targetSchema = targetSchema; | ||
} | ||
transformRequest(originalRequest) { | ||
const document = wrapConcreteTypes(this.returnType, this.targetSchema, originalRequest.document); | ||
return { | ||
...originalRequest, | ||
document, | ||
}; | ||
} | ||
} | ||
function wrapConcreteTypes(returnType, targetSchema, document) { | ||
const namedType = graphql.getNamedType(returnType); | ||
if (!graphql.isObjectType(namedType)) { | ||
return document; | ||
} | ||
const queryRootType = targetSchema.getQueryType(); | ||
const mutationRootType = targetSchema.getMutationType(); | ||
const subscriptionRootType = targetSchema.getSubscriptionType(); | ||
const typeInfo = new graphql.TypeInfo(targetSchema); | ||
const newDocument = graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, { | ||
[graphql.Kind.FIELD](node) { | ||
const maybeType = typeInfo.getParentType(); | ||
if (maybeType == null) { | ||
return false; | ||
} | ||
const parentType = graphql.getNamedType(maybeType); | ||
if (parentType !== queryRootType && parentType !== mutationRootType && parentType !== subscriptionRootType) { | ||
return false; | ||
} | ||
if (!graphql.isAbstractType(graphql.getNamedType(typeInfo.getType()))) { | ||
return false; | ||
} | ||
return { | ||
...node, | ||
selectionSet: { | ||
kind: graphql.Kind.SELECTION_SET, | ||
selections: [ | ||
{ | ||
kind: graphql.Kind.INLINE_FRAGMENT, | ||
typeCondition: { | ||
kind: graphql.Kind.NAMED_TYPE, | ||
name: { | ||
kind: graphql.Kind.NAME, | ||
value: namedType.name, | ||
}, | ||
}, | ||
selectionSet: node.selectionSet, | ||
}, | ||
], | ||
}, | ||
}; | ||
}, | ||
})); | ||
return newDocument; | ||
} | ||
class FilterToSchema { | ||
@@ -228,3 +288,6 @@ constructor(targetSchema) { | ||
const newVariables = usedVariables.reduce((acc, variableName) => { | ||
acc[variableName] = variables[variableName]; | ||
const variableValue = variables[variableName]; | ||
if (variableValue !== undefined) { | ||
acc[variableName] = variableValue; | ||
} | ||
return acc; | ||
@@ -366,9 +429,9 @@ }, {}); | ||
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 { | ||
@@ -380,4 +443,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, { | ||
@@ -393,5 +456,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); | ||
} | ||
@@ -412,9 +475,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 { | ||
@@ -426,4 +489,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, { | ||
@@ -439,5 +502,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); | ||
} | ||
@@ -458,3 +521,3 @@ } | ||
class AddMergedTypeFragments { | ||
class AddSelectionSetsByType { | ||
constructor(targetSchema, mapping) { | ||
@@ -465,3 +528,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 { | ||
@@ -473,3 +536,3 @@ ...originalRequest, | ||
} | ||
function addMergedTypeSelectionSets(targetSchema, document, mapping) { | ||
function addSelectionSetsByType(targetSchema, document, mapping) { | ||
const typeInfo = new graphql.TypeInfo(targetSchema); | ||
@@ -483,3 +546,3 @@ return graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, { | ||
if (parentTypeName in mapping) { | ||
const selectionSet = mapping[parentTypeName].selectionSet; | ||
const selectionSet = mapping[parentTypeName]; | ||
if (selectionSet != null) { | ||
@@ -537,3 +600,3 @@ selections = selections.concat(selectionSet.selections); | ||
function handleNull(fieldNodes, path, errors) { | ||
function handleNull(errors) { | ||
if (errors.length) { | ||
@@ -552,3 +615,3 @@ if (errors.some(error => !error.path || error.path.length < 2)) { | ||
Object.keys(childErrors).forEach(pathSegment => { | ||
result[pathSegment] = handleNull(fieldNodes, [...path, pathSegment], childErrors[pathSegment]); | ||
result[pathSegment] = handleNull(childErrors[pathSegment]); | ||
}); | ||
@@ -560,3 +623,3 @@ return result; | ||
Object.keys(childErrors).forEach(pathSegment => { | ||
result.push(handleNull(fieldNodes, [...path, parseInt(pathSegment, 10)], childErrors[pathSegment])); | ||
result.push(handleNull(childErrors[pathSegment])); | ||
}); | ||
@@ -579,3 +642,3 @@ return result; | ||
function unwrapResult(parent, info, path) { | ||
function unwrapResult(parent, path) { | ||
let newParent = parent; | ||
@@ -589,3 +652,3 @@ const pathLength = path.length; | ||
if (object == null) { | ||
return handleNull(info.fieldNodes, graphql.responsePathAsArray(info.path), errors); | ||
return handleNull(errors); | ||
} | ||
@@ -735,9 +798,11 @@ utils.setErrors(object, errors.map(error => utils.relocatedError(error, error.path != null ? error.path.slice(1) : undefined))); | ||
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.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; | ||
@@ -786,7 +851,7 @@ if (mergedTypeInfo != null) { | ||
const childErrors = utils.getErrorsByPathSegment(errors); | ||
return list.map((listMember, index) => handleListMember(graphql.getNullableType(type.ofType), listMember, index, index in childErrors ? childErrors[index] : [], subschema, context, info, skipTypeMerging)); | ||
return list.map((listMember, index) => handleListMember(graphql.getNullableType(type.ofType), listMember, index in childErrors ? childErrors[index] : [], subschema, context, info, skipTypeMerging)); | ||
} | ||
function handleListMember(type, listMember, index, errors, subschema, context, info, skipTypeMerging) { | ||
function handleListMember(type, listMember, errors, subschema, context, info, skipTypeMerging) { | ||
if (listMember == null) { | ||
return handleNull(info.fieldNodes, [...graphql.responsePathAsArray(info.path), index], errors); | ||
return handleNull(errors); | ||
} | ||
@@ -807,3 +872,3 @@ if (graphql.isLeafType(type)) { | ||
if (result == null) { | ||
return handleNull(info.fieldNodes, graphql.responsePathAsArray(info.path), errors); | ||
return handleNull(errors); | ||
} | ||
@@ -934,3 +999,3 @@ if (graphql.isLeafType(type)) { | ||
} | ||
function createRequestFromInfo({ info, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes, }) { | ||
function createRequestFromInfo({ info, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes = info.fieldNodes, }) { | ||
return createRequest({ | ||
@@ -946,9 +1011,10 @@ sourceSchema: info.schema, | ||
selectionSet, | ||
fieldNodes: selectionSet != null ? undefined : fieldNodes != null ? fieldNodes : info.fieldNodes, | ||
fieldNodes, | ||
}); | ||
} | ||
function createRequest({ sourceSchema, sourceParentType, sourceFieldName, fragments, variableDefinitions, variableValues, targetOperation, targetFieldName, selectionSet, fieldNodes, }) { | ||
var _a; | ||
let newSelectionSet = selectionSet; | ||
let argumentNodeMap; | ||
if (selectionSet != null && fieldNodes == null) { | ||
if (fieldNodes == null) { | ||
argumentNodeMap = Object.create(null); | ||
@@ -964,6 +1030,10 @@ } | ||
: undefined; | ||
argumentNodeMap = fieldNodes[0].arguments.reduce((prev, curr) => ({ | ||
...prev, | ||
[curr.name.value]: curr, | ||
}), {}); | ||
argumentNodeMap = {}; | ||
const args = (_a = fieldNodes[0]) === null || _a === void 0 ? void 0 : _a.arguments; | ||
if (args) { | ||
argumentNodeMap = args.reduce((prev, curr) => ({ | ||
...prev, | ||
[curr.name.value]: curr, | ||
}), argumentNodeMap); | ||
} | ||
} | ||
@@ -977,3 +1047,6 @@ const newVariables = Object.create(null); | ||
const varType = graphql.typeFromAST(sourceSchema, def.type); | ||
newVariables[varName] = utils.serializeInputValue(varType, variableValues[varName]); | ||
const serializedValue = utils.serializeInputValue(varType, variableValues[varName]); | ||
if (serializedValue !== undefined) { | ||
newVariables[varName] = serializedValue; | ||
} | ||
}); | ||
@@ -1049,13 +1122,36 @@ } | ||
} | ||
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, skipTypeMerging) { | ||
function getDelegationReturnType(info, targetSchema, operation, fieldName) { | ||
if (info != null) { | ||
return info.returnType; | ||
} | ||
let rootType; | ||
if (operation === 'query') { | ||
rootType = targetSchema.getQueryType(); | ||
} | ||
else if (operation === 'mutation') { | ||
rootType = targetSchema.getMutationType(); | ||
} | ||
else { | ||
rootType = targetSchema.getSubscriptionType(); | ||
} | ||
return rootType.getFields()[fieldName].type; | ||
} | ||
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, transformedSchema, skipTypeMerging) { | ||
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.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 = 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)); | ||
if (info != null) { | ||
delegationTransforms.push(new ExpandAbstractTypes(info.schema, transformedTargetSchema)); | ||
} | ||
delegationTransforms = delegationTransforms.concat(transforms); | ||
delegationTransforms.push(new ExpandAbstractTypes(info.schema, targetSchema)); | ||
if (info.mergeInfo != null) { | ||
delegationTransforms.push(new AddReplacementFragments(targetSchema, info.mergeInfo.replacementFragments)); | ||
if (stitchingInfo != null) { | ||
delegationTransforms.push(new AddFragmentsByField(targetSchema, stitchingInfo.fragmentsByField)); | ||
} | ||
@@ -1068,3 +1164,21 @@ if (args != null) { | ||
} | ||
function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, args, returnType = info.returnType, context, transforms = [], skipValidation, skipTypeMerging, }) { | ||
function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation, fieldName, args, returnType, context, transforms = [], transformedSchema, skipValidation, skipTypeMerging, }) { | ||
var _a; | ||
let operationDefinition; | ||
let targetOperation; | ||
let targetFieldName; | ||
if (operation == null) { | ||
operationDefinition = graphql.getOperationAST(request.document, undefined); | ||
targetOperation = operationDefinition.operation; | ||
} | ||
else { | ||
targetOperation = operation; | ||
} | ||
if (fieldName == null) { | ||
operationDefinition = operationDefinition !== null && operationDefinition !== void 0 ? operationDefinition : graphql.getOperationAST(request.document, undefined); | ||
targetFieldName = operationDefinition.selectionSet.selections[0].name.value; | ||
} | ||
else { | ||
targetFieldName = fieldName; | ||
} | ||
let targetSchema; | ||
@@ -1077,4 +1191,3 @@ let targetRootValue; | ||
targetSchema = subschemaConfig.schema; | ||
targetRootValue = | ||
rootValue != null ? rootValue : subschemaConfig.rootValue != null ? subschemaConfig.rootValue : info.rootValue; | ||
targetRootValue = (_a = rootValue !== null && rootValue !== void 0 ? rootValue : subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) !== null && _a !== void 0 ? _a : info === null || info === void 0 ? void 0 : info.rootValue; | ||
if (subschemaConfig.transforms != null) { | ||
@@ -1086,5 +1199,5 @@ requestTransforms = requestTransforms.concat(subschemaConfig.transforms); | ||
targetSchema = subschemaOrSubschemaConfig; | ||
targetRootValue = rootValue != null ? rootValue : info.rootValue; | ||
targetRootValue = rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue; | ||
} | ||
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, requestTransforms.reverse(), skipTypeMerging); | ||
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, targetFieldName, args, returnType !== null && returnType !== void 0 ? returnType : getDelegationReturnType(info, targetSchema, targetOperation, targetFieldName), requestTransforms.reverse(), transformedSchema, skipTypeMerging); | ||
const processedRequest = utils.applyRequestTransforms(request, delegationTransforms); | ||
@@ -1102,3 +1215,3 @@ if (!skipValidation) { | ||
} | ||
if (operation === 'query' || operation === 'mutation') { | ||
if (targetOperation === 'query' || targetOperation === 'mutation') { | ||
const executor = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.executor) || createDefaultExecutor(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue); | ||
@@ -1130,3 +1243,3 @@ const executionResult = executor({ | ||
return { | ||
[info.fieldName]: transformedResult, | ||
[targetFieldName]: transformedResult, | ||
}; | ||
@@ -1139,6 +1252,6 @@ }); | ||
function createDefaultExecutor(schema, rootValue) { | ||
return ({ document, context, variables, info }) => graphql.execute(schema, document, rootValue || info.rootValue, context, variables); | ||
return ({ document, context, variables, info }) => graphql.execute(schema, document, rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue, context, variables); | ||
} | ||
function createDefaultSubscriber(schema, rootValue) { | ||
return ({ document, context, variables, info }) => graphql.subscribe(schema, document, rootValue || info.rootValue, context, variables); | ||
return ({ document, context, variables, info }) => graphql.subscribe(schema, document, rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue, context, variables); | ||
} | ||
@@ -1171,3 +1284,3 @@ | ||
const unwrappingResolver = fromPath != null | ||
? (parent, args, context, info) => parentErrorResolver(unwrapResult(parent, info, fromPath), args, context, info) | ||
? (parent, args, context, info) => parentErrorResolver(unwrapResult(parent, fromPath), args, context, info) | ||
: parentErrorResolver; | ||
@@ -1201,3 +1314,3 @@ const dehoistingResolver = dehoist | ||
transformRequest(originalRequest) { | ||
const document = replaceFieldsWithFragments$1(this.targetSchema, originalRequest.document, this.mapping); | ||
const document = replaceFieldsWithFragments(this.targetSchema, originalRequest.document, this.mapping); | ||
return { | ||
@@ -1209,3 +1322,3 @@ ...originalRequest, | ||
} | ||
function replaceFieldsWithFragments$1(targetSchema, document, mapping) { | ||
function replaceFieldsWithFragments(targetSchema, document, mapping) { | ||
const typeInfo = new graphql.TypeInfo(targetSchema); | ||
@@ -1263,5 +1376,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; | ||
@@ -1268,0 +1381,0 @@ exports.CheckResultAndHandleErrors = CheckResultAndHandleErrors; |
237
index.esm.js
@@ -1,2 +0,2 @@ | ||
import { visit, visitWithTypeInfo, Kind, getNamedType, isAbstractType, TypeInfo, isObjectType, isInterfaceType, TypeNameMetaFieldDef, responsePathAsArray, getNullableType, isLeafType, isCompositeType, isListType, typeFromAST, isSchema, validate, execute, subscribe, defaultFieldResolver, parse } from 'graphql'; | ||
import { visit, visitWithTypeInfo, Kind, getNamedType, isAbstractType, TypeInfo, isObjectType, isInterfaceType, TypeNameMetaFieldDef, getNullableType, isLeafType, isCompositeType, isListType, typeFromAST, isSchema, getOperationAST, validate, execute, subscribe, defaultFieldResolver, parse } from 'graphql'; | ||
import { implementsAbstractType, CombinedError, getErrorsByPathSegment, ERROR_SYMBOL, relocatedError, mergeDeep, getErrors, setErrors, slicedError, collectFields, getResponseKeyFromInfo, updateArgument, serializeInputValue, applyRequestTransforms, applyResultTransforms, mapAsyncIterator, concatInlineFragments } from '@graphql-tools/utils'; | ||
@@ -167,2 +167,62 @@ | ||
// For motivation, see https://github.com/ardatan/graphql-tools/issues/751 | ||
class WrapConcreteTypes { | ||
constructor(returnType, targetSchema) { | ||
this.returnType = returnType; | ||
this.targetSchema = targetSchema; | ||
} | ||
transformRequest(originalRequest) { | ||
const document = wrapConcreteTypes(this.returnType, this.targetSchema, originalRequest.document); | ||
return { | ||
...originalRequest, | ||
document, | ||
}; | ||
} | ||
} | ||
function wrapConcreteTypes(returnType, targetSchema, document) { | ||
const namedType = getNamedType(returnType); | ||
if (!isObjectType(namedType)) { | ||
return document; | ||
} | ||
const queryRootType = targetSchema.getQueryType(); | ||
const mutationRootType = targetSchema.getMutationType(); | ||
const subscriptionRootType = targetSchema.getSubscriptionType(); | ||
const typeInfo = new TypeInfo(targetSchema); | ||
const newDocument = visit(document, visitWithTypeInfo(typeInfo, { | ||
[Kind.FIELD](node) { | ||
const maybeType = typeInfo.getParentType(); | ||
if (maybeType == null) { | ||
return false; | ||
} | ||
const parentType = getNamedType(maybeType); | ||
if (parentType !== queryRootType && parentType !== mutationRootType && parentType !== subscriptionRootType) { | ||
return false; | ||
} | ||
if (!isAbstractType(getNamedType(typeInfo.getType()))) { | ||
return false; | ||
} | ||
return { | ||
...node, | ||
selectionSet: { | ||
kind: Kind.SELECTION_SET, | ||
selections: [ | ||
{ | ||
kind: Kind.INLINE_FRAGMENT, | ||
typeCondition: { | ||
kind: Kind.NAMED_TYPE, | ||
name: { | ||
kind: Kind.NAME, | ||
value: namedType.name, | ||
}, | ||
}, | ||
selectionSet: node.selectionSet, | ||
}, | ||
], | ||
}, | ||
}; | ||
}, | ||
})); | ||
return newDocument; | ||
} | ||
class FilterToSchema { | ||
@@ -224,3 +284,6 @@ constructor(targetSchema) { | ||
const newVariables = usedVariables.reduce((acc, variableName) => { | ||
acc[variableName] = variables[variableName]; | ||
const variableValue = variables[variableName]; | ||
if (variableValue !== undefined) { | ||
acc[variableName] = variableValue; | ||
} | ||
return acc; | ||
@@ -362,9 +425,9 @@ }, {}); | ||
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 { | ||
@@ -376,4 +439,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, { | ||
@@ -389,5 +452,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); | ||
} | ||
@@ -408,9 +471,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 { | ||
@@ -422,4 +485,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, { | ||
@@ -435,5 +498,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); | ||
} | ||
@@ -454,3 +517,3 @@ } | ||
class AddMergedTypeFragments { | ||
class AddSelectionSetsByType { | ||
constructor(targetSchema, mapping) { | ||
@@ -461,3 +524,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 { | ||
@@ -469,3 +532,3 @@ ...originalRequest, | ||
} | ||
function addMergedTypeSelectionSets(targetSchema, document, mapping) { | ||
function addSelectionSetsByType(targetSchema, document, mapping) { | ||
const typeInfo = new TypeInfo(targetSchema); | ||
@@ -479,3 +542,3 @@ return visit(document, visitWithTypeInfo(typeInfo, { | ||
if (parentTypeName in mapping) { | ||
const selectionSet = mapping[parentTypeName].selectionSet; | ||
const selectionSet = mapping[parentTypeName]; | ||
if (selectionSet != null) { | ||
@@ -533,3 +596,3 @@ selections = selections.concat(selectionSet.selections); | ||
function handleNull(fieldNodes, path, errors) { | ||
function handleNull(errors) { | ||
if (errors.length) { | ||
@@ -548,3 +611,3 @@ if (errors.some(error => !error.path || error.path.length < 2)) { | ||
Object.keys(childErrors).forEach(pathSegment => { | ||
result[pathSegment] = handleNull(fieldNodes, [...path, pathSegment], childErrors[pathSegment]); | ||
result[pathSegment] = handleNull(childErrors[pathSegment]); | ||
}); | ||
@@ -556,3 +619,3 @@ return result; | ||
Object.keys(childErrors).forEach(pathSegment => { | ||
result.push(handleNull(fieldNodes, [...path, parseInt(pathSegment, 10)], childErrors[pathSegment])); | ||
result.push(handleNull(childErrors[pathSegment])); | ||
}); | ||
@@ -575,3 +638,3 @@ return result; | ||
function unwrapResult(parent, info, path) { | ||
function unwrapResult(parent, path) { | ||
let newParent = parent; | ||
@@ -585,3 +648,3 @@ const pathLength = path.length; | ||
if (object == null) { | ||
return handleNull(info.fieldNodes, responsePathAsArray(info.path), errors); | ||
return handleNull(errors); | ||
} | ||
@@ -731,9 +794,11 @@ setErrors(object, errors.map(error => relocatedError(error, error.path != null ? error.path.slice(1) : undefined))); | ||
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.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; | ||
@@ -782,7 +847,7 @@ if (mergedTypeInfo != null) { | ||
const childErrors = getErrorsByPathSegment(errors); | ||
return list.map((listMember, index) => handleListMember(getNullableType(type.ofType), listMember, index, index in childErrors ? childErrors[index] : [], subschema, context, info, skipTypeMerging)); | ||
return list.map((listMember, index) => handleListMember(getNullableType(type.ofType), listMember, index in childErrors ? childErrors[index] : [], subschema, context, info, skipTypeMerging)); | ||
} | ||
function handleListMember(type, listMember, index, errors, subschema, context, info, skipTypeMerging) { | ||
function handleListMember(type, listMember, errors, subschema, context, info, skipTypeMerging) { | ||
if (listMember == null) { | ||
return handleNull(info.fieldNodes, [...responsePathAsArray(info.path), index], errors); | ||
return handleNull(errors); | ||
} | ||
@@ -803,3 +868,3 @@ if (isLeafType(type)) { | ||
if (result == null) { | ||
return handleNull(info.fieldNodes, responsePathAsArray(info.path), errors); | ||
return handleNull(errors); | ||
} | ||
@@ -930,3 +995,3 @@ if (isLeafType(type)) { | ||
} | ||
function createRequestFromInfo({ info, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes, }) { | ||
function createRequestFromInfo({ info, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes = info.fieldNodes, }) { | ||
return createRequest({ | ||
@@ -942,9 +1007,10 @@ sourceSchema: info.schema, | ||
selectionSet, | ||
fieldNodes: selectionSet != null ? undefined : fieldNodes != null ? fieldNodes : info.fieldNodes, | ||
fieldNodes, | ||
}); | ||
} | ||
function createRequest({ sourceSchema, sourceParentType, sourceFieldName, fragments, variableDefinitions, variableValues, targetOperation, targetFieldName, selectionSet, fieldNodes, }) { | ||
var _a; | ||
let newSelectionSet = selectionSet; | ||
let argumentNodeMap; | ||
if (selectionSet != null && fieldNodes == null) { | ||
if (fieldNodes == null) { | ||
argumentNodeMap = Object.create(null); | ||
@@ -960,6 +1026,10 @@ } | ||
: undefined; | ||
argumentNodeMap = fieldNodes[0].arguments.reduce((prev, curr) => ({ | ||
...prev, | ||
[curr.name.value]: curr, | ||
}), {}); | ||
argumentNodeMap = {}; | ||
const args = (_a = fieldNodes[0]) === null || _a === void 0 ? void 0 : _a.arguments; | ||
if (args) { | ||
argumentNodeMap = args.reduce((prev, curr) => ({ | ||
...prev, | ||
[curr.name.value]: curr, | ||
}), argumentNodeMap); | ||
} | ||
} | ||
@@ -973,3 +1043,6 @@ const newVariables = Object.create(null); | ||
const varType = typeFromAST(sourceSchema, def.type); | ||
newVariables[varName] = serializeInputValue(varType, variableValues[varName]); | ||
const serializedValue = serializeInputValue(varType, variableValues[varName]); | ||
if (serializedValue !== undefined) { | ||
newVariables[varName] = serializedValue; | ||
} | ||
}); | ||
@@ -1045,13 +1118,36 @@ } | ||
} | ||
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, skipTypeMerging) { | ||
function getDelegationReturnType(info, targetSchema, operation, fieldName) { | ||
if (info != null) { | ||
return info.returnType; | ||
} | ||
let rootType; | ||
if (operation === 'query') { | ||
rootType = targetSchema.getQueryType(); | ||
} | ||
else if (operation === 'mutation') { | ||
rootType = targetSchema.getMutationType(); | ||
} | ||
else { | ||
rootType = targetSchema.getSubscriptionType(); | ||
} | ||
return rootType.getFields()[fieldName].type; | ||
} | ||
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, transformedSchema, skipTypeMerging) { | ||
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.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 = 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)); | ||
if (info != null) { | ||
delegationTransforms.push(new ExpandAbstractTypes(info.schema, transformedTargetSchema)); | ||
} | ||
delegationTransforms = delegationTransforms.concat(transforms); | ||
delegationTransforms.push(new ExpandAbstractTypes(info.schema, targetSchema)); | ||
if (info.mergeInfo != null) { | ||
delegationTransforms.push(new AddReplacementFragments(targetSchema, info.mergeInfo.replacementFragments)); | ||
if (stitchingInfo != null) { | ||
delegationTransforms.push(new AddFragmentsByField(targetSchema, stitchingInfo.fragmentsByField)); | ||
} | ||
@@ -1064,3 +1160,21 @@ if (args != null) { | ||
} | ||
function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, args, returnType = info.returnType, context, transforms = [], skipValidation, skipTypeMerging, }) { | ||
function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation, fieldName, args, returnType, context, transforms = [], transformedSchema, skipValidation, skipTypeMerging, }) { | ||
var _a; | ||
let operationDefinition; | ||
let targetOperation; | ||
let targetFieldName; | ||
if (operation == null) { | ||
operationDefinition = getOperationAST(request.document, undefined); | ||
targetOperation = operationDefinition.operation; | ||
} | ||
else { | ||
targetOperation = operation; | ||
} | ||
if (fieldName == null) { | ||
operationDefinition = operationDefinition !== null && operationDefinition !== void 0 ? operationDefinition : getOperationAST(request.document, undefined); | ||
targetFieldName = operationDefinition.selectionSet.selections[0].name.value; | ||
} | ||
else { | ||
targetFieldName = fieldName; | ||
} | ||
let targetSchema; | ||
@@ -1073,4 +1187,3 @@ let targetRootValue; | ||
targetSchema = subschemaConfig.schema; | ||
targetRootValue = | ||
rootValue != null ? rootValue : subschemaConfig.rootValue != null ? subschemaConfig.rootValue : info.rootValue; | ||
targetRootValue = (_a = rootValue !== null && rootValue !== void 0 ? rootValue : subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) !== null && _a !== void 0 ? _a : info === null || info === void 0 ? void 0 : info.rootValue; | ||
if (subschemaConfig.transforms != null) { | ||
@@ -1082,5 +1195,5 @@ requestTransforms = requestTransforms.concat(subschemaConfig.transforms); | ||
targetSchema = subschemaOrSubschemaConfig; | ||
targetRootValue = rootValue != null ? rootValue : info.rootValue; | ||
targetRootValue = rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue; | ||
} | ||
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, requestTransforms.reverse(), skipTypeMerging); | ||
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, targetFieldName, args, returnType !== null && returnType !== void 0 ? returnType : getDelegationReturnType(info, targetSchema, targetOperation, targetFieldName), requestTransforms.reverse(), transformedSchema, skipTypeMerging); | ||
const processedRequest = applyRequestTransforms(request, delegationTransforms); | ||
@@ -1098,3 +1211,3 @@ if (!skipValidation) { | ||
} | ||
if (operation === 'query' || operation === 'mutation') { | ||
if (targetOperation === 'query' || targetOperation === 'mutation') { | ||
const executor = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.executor) || createDefaultExecutor(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue); | ||
@@ -1126,3 +1239,3 @@ const executionResult = executor({ | ||
return { | ||
[info.fieldName]: transformedResult, | ||
[targetFieldName]: transformedResult, | ||
}; | ||
@@ -1135,6 +1248,6 @@ }); | ||
function createDefaultExecutor(schema, rootValue) { | ||
return ({ document, context, variables, info }) => execute(schema, document, rootValue || info.rootValue, context, variables); | ||
return ({ document, context, variables, info }) => execute(schema, document, rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue, context, variables); | ||
} | ||
function createDefaultSubscriber(schema, rootValue) { | ||
return ({ document, context, variables, info }) => subscribe(schema, document, rootValue || info.rootValue, context, variables); | ||
return ({ document, context, variables, info }) => subscribe(schema, document, rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue, context, variables); | ||
} | ||
@@ -1167,3 +1280,3 @@ | ||
const unwrappingResolver = fromPath != null | ||
? (parent, args, context, info) => parentErrorResolver(unwrapResult(parent, info, fromPath), args, context, info) | ||
? (parent, args, context, info) => parentErrorResolver(unwrapResult(parent, fromPath), args, context, info) | ||
: parentErrorResolver; | ||
@@ -1197,3 +1310,3 @@ const dehoistingResolver = dehoist | ||
transformRequest(originalRequest) { | ||
const document = replaceFieldsWithFragments$1(this.targetSchema, originalRequest.document, this.mapping); | ||
const document = replaceFieldsWithFragments(this.targetSchema, originalRequest.document, this.mapping); | ||
return { | ||
@@ -1205,3 +1318,3 @@ ...originalRequest, | ||
} | ||
function replaceFieldsWithFragments$1(targetSchema, document, mapping) { | ||
function replaceFieldsWithFragments(targetSchema, document, mapping) { | ||
const typeInfo = new TypeInfo(targetSchema); | ||
@@ -1258,3 +1371,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.1", | ||
"version": "6.0.0-alpha.2", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -9,5 +9,5 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@graphql-tools/schema": "6.0.0-alpha.1", | ||
"@graphql-tools/utils": "6.0.0-alpha.1", | ||
"tslib": "1.11.1" | ||
"@graphql-tools/schema": "6.0.0-alpha.2", | ||
"@graphql-tools/utils": "6.0.0-alpha.2", | ||
"tslib": "~2.0.0" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": "git@github.com:ardatan/graphql-tools.git", |
@@ -1,5 +0,4 @@ | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
export declare function isProxiedResult(result: any): any; | ||
export declare function unwrapResult(parent: any, info: GraphQLResolveInfo, path: Array<string>): any; | ||
export declare function unwrapResult(parent: any, path: Array<string>): any; | ||
export declare function dehoistResult(parent: any, delimeter?: string): any; | ||
export declare function mergeProxiedResults(target: any, ...sources: any): any; |
@@ -1,2 +0,2 @@ | ||
import { FieldNode, GraphQLError } from 'graphql'; | ||
export declare function handleNull(fieldNodes: ReadonlyArray<FieldNode>, path: Array<string | number>, errors: ReadonlyArray<GraphQLError>): {}; | ||
import { GraphQLError } from 'graphql'; | ||
export declare function handleNull(errors: ReadonlyArray<GraphQLError>): {}; |
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'; |
@@ -1,2 +0,2 @@ | ||
import { GraphQLSchema, GraphQLOutputType, SelectionSetNode, FieldNode, DocumentNode, GraphQLResolveInfo, GraphQLFieldResolver, InlineFragmentNode } from 'graphql'; | ||
import { GraphQLSchema, GraphQLOutputType, SelectionSetNode, FieldNode, DocumentNode, GraphQLResolveInfo, GraphQLFieldResolver, InlineFragmentNode, FragmentDefinitionNode, GraphQLObjectType, VariableDefinitionNode } from 'graphql'; | ||
import { Operation, Transform, Request, TypeMap, ExecutionResult } from '@graphql-tools/utils'; | ||
@@ -15,7 +15,9 @@ export interface IDelegateToSchemaOptions<TContext = Record<string, any>, TArgs = Record<string, any>> { | ||
transforms?: Array<Transform>; | ||
transformedSchema?: GraphQLSchema; | ||
skipValidation?: boolean; | ||
skipTypeMerging?: boolean; | ||
} | ||
export interface IDelegateRequestOptions extends IDelegateToSchemaOptions { | ||
export interface IDelegateRequestOptions extends Omit<IDelegateToSchemaOptions, 'info'> { | ||
request: Request; | ||
info?: GraphQLResolveInfo; | ||
} | ||
@@ -29,2 +31,14 @@ export interface ICreateRequestFromInfo { | ||
} | ||
export interface ICreateRequest { | ||
sourceSchema?: GraphQLSchema; | ||
sourceParentType?: GraphQLObjectType; | ||
sourceFieldName?: string; | ||
fragments?: Record<string, FragmentDefinitionNode>; | ||
variableDefinitions?: ReadonlyArray<VariableDefinitionNode>; | ||
variableValues?: Record<string, any>; | ||
targetOperation: Operation; | ||
targetFieldName: string; | ||
selectionSet?: SelectionSetNode; | ||
fieldNodes?: ReadonlyArray<FieldNode>; | ||
} | ||
export interface MergedTypeInfo { | ||
@@ -49,3 +63,10 @@ subschemas: Array<SubschemaConfig>; | ||
export declare type Subscriber = <TReturn = Record<string, any>, TArgs = Record<string, any>, TContext = Record<string, any>>(params: ExecutionParams<TArgs, TContext>) => Promise<AsyncIterator<ExecutionResult<TReturn>> | ExecutionResult<TReturn>>; | ||
export declare type CreateProxyingResolverFn = (schema: GraphQLSchema | SubschemaConfig, transforms: Array<Transform>, operation: Operation, fieldName: string) => GraphQLFieldResolver<any, any>; | ||
export interface ICreateProxyingResolverOptions { | ||
schema: GraphQLSchema | SubschemaConfig; | ||
transforms?: Array<Transform>; | ||
transformedSchema?: GraphQLSchema; | ||
operation?: Operation; | ||
fieldName?: string; | ||
} | ||
export declare type CreateProxyingResolverFn = (options: ICreateProxyingResolverOptions) => GraphQLFieldResolver<any, any>; | ||
export interface SubschemaConfig { | ||
@@ -66,13 +87,10 @@ schema: GraphQLSchema; | ||
} | ||
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
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
367454
33
2929
+ Added@graphql-tools/schema@6.0.0-alpha.2(transitive)
+ Added@graphql-tools/utils@6.0.0-alpha.2(transitive)
+ Addedtslib@1.14.12.0.3(transitive)
- Removed@graphql-tools/schema@6.0.0-alpha.1(transitive)
- Removed@graphql-tools/utils@6.0.0-alpha.1(transitive)
- Removedtslib@1.11.12.8.0(transitive)
Updatedtslib@~2.0.0