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 5.0.1-alpha-d95fd59.0 to 5.0.1-alpha-e22446c.0

transforms/WrapConcreteTypes.d.ts

4

createRequest.d.ts
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;

@@ -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;

@@ -956,3 +1019,6 @@ }, {});

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;
}
});

@@ -1028,3 +1094,4 @@ }

}
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, skipTypeMerging) {
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, transformedSchema, skipTypeMerging) {
var _a;
let delegationTransforms = [

@@ -1036,4 +1103,7 @@ new CheckResultAndHandleErrors(info, fieldName, subschemaOrSubschemaConfig, context, returnType, skipTypeMerging),

}
const transformedTargetSchema = 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;
delegationTransforms.push(new WrapConcreteTypes(returnType, transformedTargetSchema));
delegationTransforms.push(new ExpandAbstractTypes(info.schema, transformedTargetSchema));
delegationTransforms = delegationTransforms.concat(transforms);
delegationTransforms.push(new ExpandAbstractTypes(info.schema, targetSchema));
if (info.mergeInfo != null) {

@@ -1048,3 +1118,3 @@ delegationTransforms.push(new AddReplacementFragments(targetSchema, info.mergeInfo.replacementFragments));

}
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 = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, args, returnType = info.returnType, context, transforms = [], transformedSchema, skipValidation, skipTypeMerging, }) {
let targetSchema;

@@ -1067,3 +1137,3 @@ let targetRootValue;

}
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, requestTransforms.reverse(), skipTypeMerging);
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, requestTransforms.reverse(), transformedSchema, skipTypeMerging);
const processedRequest = utils.applyRequestTransforms(request, delegationTransforms);

@@ -1070,0 +1140,0 @@ if (!skipValidation) {

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

// 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;

@@ -952,3 +1015,6 @@ }, {});

const varType = typeFromAST(sourceSchema, def.type);
newVariables[varName] = serializeInputValue(varType, variableValues[varName]);
const serializedValue = serializeInputValue(varType, variableValues[varName]);
if (serializedValue !== undefined) {
newVariables[varName] = serializedValue;
}
});

@@ -1024,3 +1090,4 @@ }

}
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, skipTypeMerging) {
function buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, transforms, transformedSchema, skipTypeMerging) {
var _a;
let delegationTransforms = [

@@ -1032,4 +1099,7 @@ new CheckResultAndHandleErrors(info, fieldName, subschemaOrSubschemaConfig, context, returnType, skipTypeMerging),

}
const transformedTargetSchema = 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;
delegationTransforms.push(new WrapConcreteTypes(returnType, transformedTargetSchema));
delegationTransforms.push(new ExpandAbstractTypes(info.schema, transformedTargetSchema));
delegationTransforms = delegationTransforms.concat(transforms);
delegationTransforms.push(new ExpandAbstractTypes(info.schema, targetSchema));
if (info.mergeInfo != null) {

@@ -1044,3 +1114,3 @@ delegationTransforms.push(new AddReplacementFragments(targetSchema, info.mergeInfo.replacementFragments));

}
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 = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, args, returnType = info.returnType, context, transforms = [], transformedSchema, skipValidation, skipTypeMerging, }) {
let targetSchema;

@@ -1063,3 +1133,3 @@ let targetRootValue;

}
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, requestTransforms.reverse(), skipTypeMerging);
const delegationTransforms = buildDelegationTransforms(subschemaOrSubschemaConfig, info, context, targetSchema, fieldName, args, returnType, requestTransforms.reverse(), transformedSchema, skipTypeMerging);
const processedRequest = applyRequestTransforms(request, delegationTransforms);

@@ -1066,0 +1136,0 @@ if (!skipValidation) {

{
"name": "@graphql-tools/delegate",
"version": "5.0.1-alpha-d95fd59.0",
"version": "5.0.1-alpha-e22446c.0",
"description": "A set of utils for faster development of GraphQL tools",

@@ -9,4 +9,4 @@ "peerDependencies": {

"dependencies": {
"@graphql-tools/schema": "5.0.1-alpha-d95fd59.0",
"@graphql-tools/utils": "5.0.1-alpha-d95fd59.0",
"@graphql-tools/schema": "5.0.1-alpha-e22446c.0",
"@graphql-tools/utils": "5.0.1-alpha-e22446c.0",
"tslib": "1.11.1"

@@ -13,0 +13,0 @@ },

import { GraphQLSchema } from 'graphql';
import { Transform, Request, ReplacementFragmentMapping } from '@graphql-tools/utils';
import { Transform, Request } from '@graphql-tools/utils';
import { ReplacementFragmentMapping } from '../types';
export default class AddReplacementFragments implements Transform {

@@ -4,0 +5,0 @@ private readonly targetSchema;

import { GraphQLSchema } from 'graphql';
import { Transform, Request, ReplacementSelectionSetMapping } from '@graphql-tools/utils';
import { Transform, Request } from '@graphql-tools/utils';
import { ReplacementSelectionSetMapping } from '../types';
export default class AddReplacementSelectionSets implements Transform {

@@ -4,0 +5,0 @@ private readonly schema;

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

import { GraphQLSchema, GraphQLOutputType, SelectionSetNode, FieldNode, DocumentNode, GraphQLResolveInfo, GraphQLFieldResolver, GraphQLNamedType } 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,2 +15,3 @@ export interface IDelegateToSchemaOptions<TContext = Record<string, any>, TArgs = Record<string, any>> {

transforms?: Array<Transform>;
transformedSchema?: GraphQLSchema;
skipValidation?: boolean;

@@ -29,2 +30,14 @@ skipTypeMerging?: boolean;

}
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 +62,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,4 +86,13 @@ 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 type SchemaLikeObject = SubschemaConfig | GraphQLSchema | string | DocumentNode | Array<GraphQLNamedType>;
export declare function isSubschemaConfig(value: any): value is SubschemaConfig;

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