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

@apollo/federation-internals

Package Overview
Dependencies
Maintainers
1
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/federation-internals - npm Package Compare versions

Comparing version 2.8.0-connectors.5 to 2.8.0

dist/specs/contextSpec.d.ts

14

dist/directiveAndTypeSpecification.d.ts

@@ -5,2 +5,3 @@ import { DirectiveLocation, GraphQLError } from "graphql";

import { FeatureDefinition, FeatureVersion } from "./specs/coreSpec";
import { Subgraph } from '.';
export type DirectiveSpecification = {

@@ -14,3 +15,9 @@ name: string;

argumentsMerger?: (schema: Schema, feature: CoreFeature) => ArgumentMerger | GraphQLError;
staticArgumentTransform?: StaticArgumentsTransform;
};
export type StaticArgumentsTransform = (subgraph: Subgraph, args: Readonly<{
[key: string]: any;
}>) => Readonly<{
[key: string]: any;
}>;
export type ArgumentMerger = {

@@ -42,3 +49,3 @@ merge: (argName: string, values: any[]) => any;

};
export declare function createDirectiveSpecification({ name, locations, repeatable, args, composes, supergraphSpecification, }: {
export declare function createDirectiveSpecification({ name, locations, repeatable, args, composes, supergraphSpecification, staticArgumentTransform, }: {
name: string;

@@ -50,2 +57,7 @@ locations: DirectiveLocation[];

supergraphSpecification?: (fedVersion: FeatureVersion) => FeatureDefinition;
staticArgumentTransform?: (subgraph: Subgraph, args: {
[key: string]: any;
}) => {
[key: string]: any;
};
}): DirectiveSpecification;

@@ -52,0 +64,0 @@ export declare function createScalarTypeSpecification({ name }: {

4

dist/directiveAndTypeSpecification.js

@@ -10,3 +10,3 @@ "use strict";

const utils_1 = require("./utils");
function createDirectiveSpecification({ name, locations, repeatable = false, args = [], composes = false, supergraphSpecification = undefined, }) {
function createDirectiveSpecification({ name, locations, repeatable = false, args = [], composes = false, supergraphSpecification = undefined, staticArgumentTransform = undefined, }) {
let composition = undefined;

@@ -32,3 +32,2 @@ if (composes) {

}
;
return {

@@ -52,2 +51,3 @@ merge: (argName, values) => {

argumentsMerger,
staticArgumentTransform,
};

@@ -54,0 +54,0 @@ }

@@ -80,2 +80,7 @@ import { ASTNode, GraphQLError, GraphQLErrorOptions, GraphQLFormattedError } from "graphql";

TYPE_KIND_MISMATCH: ErrorCodeDefinition;
CONTEXT_NOT_SET: ErrorCodeDefinition;
CONTEXT_INVALID_SELECTION: ErrorCodeDefinition;
NO_CONTEXT_IN_SELECTION: ErrorCodeDefinition;
CONTEXT_NO_RESOLVABLE_KEY: ErrorCodeDefinition;
CONTEXT_NAME_INVALID: ErrorCodeDefinition;
EXTERNAL_TYPE_MISMATCH: ErrorCodeDefinition;

@@ -127,2 +132,22 @@ EXTERNAL_ARGUMENT_MISSING: ErrorCodeDefinition;

INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE: ErrorCodeDefinition;
SOURCE_FEDERATION_VERSION_REQUIRED: ErrorCodeDefinition;
SOURCE_API_NAME_INVALID: ErrorCodeDefinition;
SOURCE_API_PROTOCOL_INVALID: ErrorCodeDefinition;
SOURCE_API_HTTP_BASE_URL_INVALID: ErrorCodeDefinition;
SOURCE_HTTP_HEADERS_INVALID: ErrorCodeDefinition;
SOURCE_TYPE_API_ERROR: ErrorCodeDefinition;
SOURCE_TYPE_PROTOCOL_INVALID: ErrorCodeDefinition;
SOURCE_TYPE_HTTP_METHOD_INVALID: ErrorCodeDefinition;
SOURCE_TYPE_HTTP_PATH_INVALID: ErrorCodeDefinition;
SOURCE_TYPE_HTTP_BODY_INVALID: ErrorCodeDefinition;
SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY: ErrorCodeDefinition;
SOURCE_TYPE_SELECTION_INVALID: ErrorCodeDefinition;
SOURCE_FIELD_API_ERROR: ErrorCodeDefinition;
SOURCE_FIELD_PROTOCOL_INVALID: ErrorCodeDefinition;
SOURCE_FIELD_HTTP_METHOD_INVALID: ErrorCodeDefinition;
SOURCE_FIELD_HTTP_PATH_INVALID: ErrorCodeDefinition;
SOURCE_FIELD_HTTP_BODY_INVALID: ErrorCodeDefinition;
SOURCE_FIELD_SELECTION_INVALID: ErrorCodeDefinition;
SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD: ErrorCodeDefinition;
CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS: ErrorCodeDefinition;
};

@@ -129,0 +154,0 @@ export declare const REMOVED_ERRORS: string[][];

@@ -162,2 +162,7 @@ "use strict";

const TYPE_KIND_MISMATCH = makeCodeDefinition('TYPE_KIND_MISMATCH', 'A type has the same name in different subgraphs, but a different kind. For instance, one definition is an object type but another is an interface.', { ...DEFAULT_METADATA, replaces: ['VALUE_TYPE_KIND_MISMATCH', 'EXTENSION_OF_WRONG_KIND', 'ENUM_MISMATCH_TYPE'] });
const CONTEXT_NOT_SET = makeCodeDefinition('CONTEXT_NOT_SET', 'Context is never set for context trying to be used.', { addedIn: '2.8.0' });
const CONTEXT_INVALID_SELECTION = makeCodeDefinition('CONTEXT_INVALID_SELECTION', 'Selection within @fromContext must resolve to a single field.', { addedIn: '2.8.0' });
const NO_CONTEXT_IN_SELECTION = makeCodeDefinition('NO_CONTEXT_IN_SELECTION', 'Selection in @fromContext field argument does not reference a context.', { addedIn: '2.8.0' });
const CONTEXT_NO_RESOLVABLE_KEY = makeCodeDefinition('CONTEXT_NO_RESOLVABLE_KEY', 'If an ObjectType uses a @fromContext, at least one of its keys must be resolvable.', { addedIn: '2.8.0' });
const CONTEXT_NAME_INVALID = makeCodeDefinition('CONTEXT_NAME_INVALID', 'Context name is invalid.', { addedIn: '2.8.0' });
const EXTERNAL_TYPE_MISMATCH = makeCodeDefinition('EXTERNAL_TYPE_MISMATCH', 'An `@external` field has a type that is incompatible with the declaration(s) of that field in other subgraphs.', { addedIn: FED1_CODE });

@@ -207,2 +212,22 @@ const EXTERNAL_COLLISION_WITH_ANOTHER_DIRECTIVE = makeCodeDefinition('EXTERNAL_COLLISION_WITH_ANOTHER_DIRECTIVE', 'The @external directive collides with other directives in some situations.', { addedIn: '2.1.0' });

const INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE = makeCodeDefinition('INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE', 'A subgraph has a `@key` on an interface type, but that subgraph does not define an implementation (in the supergraph) of that interface', { addedIn: '2.3.0' });
const SOURCE_FEDERATION_VERSION_REQUIRED = makeCodeDefinition('SOURCE_FEDERATION_VERSION_REQUIRED', 'Schemas using `@source{API,Type,Field}` directives must @link-import v2.7 or later of federation', { addedIn: '2.7.1' });
const SOURCE_API_NAME_INVALID = makeCodeDefinition('SOURCE_API_NAME_INVALID', 'Each `@sourceAPI` directive must take a unique and valid name as an argument', { addedIn: '2.7.0' });
const SOURCE_API_PROTOCOL_INVALID = makeCodeDefinition('SOURCE_API_PROTOCOL_INVALID', 'Each `@sourceAPI` directive must specify exactly one of the known protocols', { addedIn: '2.7.0' });
const SOURCE_API_HTTP_BASE_URL_INVALID = makeCodeDefinition('SOURCE_API_HTTP_BASE_URL_INVALID', 'The `@sourceAPI` directive must specify a valid http.baseURL', { addedIn: '2.7.0' });
const SOURCE_HTTP_HEADERS_INVALID = makeCodeDefinition('SOURCE_HTTP_HEADERS_INVALID', 'The `http.headers` argument of `@source*` directives must specify valid HTTP headers', { addedIn: '2.7.0' });
const SOURCE_TYPE_API_ERROR = makeCodeDefinition('SOURCE_TYPE_API_ERROR', 'The `api` argument of the `@sourceType` directive must match a valid `@sourceAPI` name', { addedIn: '2.7.0' });
const SOURCE_TYPE_PROTOCOL_INVALID = makeCodeDefinition('SOURCE_TYPE_PROTOCOL_INVALID', 'The `@sourceType` directive must specify the same protocol as its corresponding `@sourceAPI`', { addedIn: '2.7.0' });
const SOURCE_TYPE_HTTP_METHOD_INVALID = makeCodeDefinition('SOURCE_TYPE_HTTP_METHOD_INVALID', 'The `@sourceType` directive must specify exactly one of `http.GET` or `http.POST`', { addedIn: '2.7.0' });
const SOURCE_TYPE_HTTP_PATH_INVALID = makeCodeDefinition('SOURCE_TYPE_HTTP_PATH_INVALID', 'The `@sourceType` directive must specify a valid URL template for `http.GET` or `http.POST`', { addedIn: '2.7.0' });
const SOURCE_TYPE_HTTP_BODY_INVALID = makeCodeDefinition('SOURCE_TYPE_HTTP_BODY_INVALID', 'If the `@sourceType` specifies `http.body`, it must be a valid `JSONSelection`', { addedIn: '2.7.0' });
const SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY = makeCodeDefinition('SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY', 'The `@sourceType` directive must be applied to an object or interface type that also has `@key`', { addedIn: '2.7.0' });
const SOURCE_TYPE_SELECTION_INVALID = makeCodeDefinition('SOURCE_TYPE_SELECTION_INVALID', 'The `selection` argument of the `@sourceType` directive must be a valid `JSONSelection` that outputs fields of the GraphQL type');
const SOURCE_FIELD_API_ERROR = makeCodeDefinition('SOURCE_FIELD_API_ERROR', 'The `api` argument of the `@sourceField` directive must match a valid `@sourceAPI` name', { addedIn: '2.7.0' });
const SOURCE_FIELD_PROTOCOL_INVALID = makeCodeDefinition('SOURCE_FIELD_PROTOCOL_INVALID', 'If `@sourceField` specifies a protocol, it must match the corresponding `@sourceAPI` protocol', { addedIn: '2.7.0' });
const SOURCE_FIELD_HTTP_METHOD_INVALID = makeCodeDefinition('SOURCE_FIELD_HTTP_METHOD_INVALID', 'The `@sourceField` directive must specify at most one of `http.{GET,POST,PUT,PATCH,DELETE}`', { addedIn: '2.7.0' });
const SOURCE_FIELD_HTTP_PATH_INVALID = makeCodeDefinition('SOURCE_FIELD_HTTP_PATH_INVALID', 'The `@sourceField` directive must specify a valid URL template for `http.{GET,POST,PUT,PATCH,DELETE}`', { addedIn: '2.7.0' });
const SOURCE_FIELD_HTTP_BODY_INVALID = makeCodeDefinition('SOURCE_FIELD_HTTP_BODY_INVALID', 'If `@sourceField` specifies http.body, it must be a valid `JSONSelection` matching available arguments and fields', { addedIn: '2.7.0' });
const SOURCE_FIELD_SELECTION_INVALID = makeCodeDefinition('SOURCE_FIELD_SELECTION_INVALID', 'The `selection` argument of the `@sourceField` directive must be a valid `JSONSelection` that outputs fields of the GraphQL type', { addedIn: '2.7.0' });
const SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD = makeCodeDefinition('SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD', 'The `@sourceField` directive must be applied to a field of the `Query` or `Mutation` types, or of an entity type', { addedIn: '2.7.0' });
const CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS = makeCodeDefinition('CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS', 'Argument on field is marked contextual in only some subgraphs', { addedIn: '2.7.0' });
exports.ERROR_CATEGORIES = {

@@ -249,2 +274,7 @@ DIRECTIVE_FIELDS_MISSING_EXTERNAL,

TYPE_KIND_MISMATCH,
CONTEXT_NOT_SET,
CONTEXT_INVALID_SELECTION,
NO_CONTEXT_IN_SELECTION,
CONTEXT_NO_RESOLVABLE_KEY,
CONTEXT_NAME_INVALID,
EXTERNAL_TYPE_MISMATCH,

@@ -296,2 +326,22 @@ EXTERNAL_ARGUMENT_MISSING,

INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE,
SOURCE_FEDERATION_VERSION_REQUIRED,
SOURCE_API_NAME_INVALID,
SOURCE_API_PROTOCOL_INVALID,
SOURCE_API_HTTP_BASE_URL_INVALID,
SOURCE_HTTP_HEADERS_INVALID,
SOURCE_TYPE_API_ERROR,
SOURCE_TYPE_PROTOCOL_INVALID,
SOURCE_TYPE_HTTP_METHOD_INVALID,
SOURCE_TYPE_HTTP_PATH_INVALID,
SOURCE_TYPE_HTTP_BODY_INVALID,
SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY,
SOURCE_TYPE_SELECTION_INVALID,
SOURCE_FIELD_API_ERROR,
SOURCE_FIELD_PROTOCOL_INVALID,
SOURCE_FIELD_HTTP_METHOD_INVALID,
SOURCE_FIELD_HTTP_PATH_INVALID,
SOURCE_FIELD_HTTP_BODY_INVALID,
SOURCE_FIELD_SELECTION_INVALID,
SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD,
CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS,
};

@@ -298,0 +348,0 @@ const codeDefByCode = Object.values(exports.ERRORS).reduce((obj, codeDef) => { obj[codeDef.code] = codeDef; return obj; }, {});

@@ -7,3 +7,3 @@ import { Schema } from "./definitions";

}[];
export declare function extractSubgraphsFromSupergraph(supergraph: Schema, validateExtractedSubgraphs?: boolean): Subgraphs;
export declare function extractSubgraphsFromSupergraph(supergraph: Schema, validateExtractedSubgraphs?: boolean): [Subgraphs, Map<string, string>];
//# sourceMappingURL=extractSubgraphsFromSupergraph.d.ts.map

@@ -149,2 +149,11 @@ "use strict";

};
const subgraphNameToGraphEnumValue = new Map();
for (const [k, v] of graphEnumNameToSubgraphName.entries()) {
subgraphNameToGraphEnumValue.set(v, k);
}
const getSubgraphEnumValue = (subgraphName) => {
const enumValue = subgraphNameToGraphEnumValue.get(subgraphName);
(0, utils_1.assert)(enumValue, () => `Invalid subgraph name ${subgraphName} found: does not match a subgraph defined in the @join__Graph enum`);
return enumValue;
};
const types = filteredTypes(supergraph, joinSpec, coreFeatures.coreDefinition);

@@ -157,2 +166,3 @@ const args = {

getSubgraph,
getSubgraphEnumValue,
};

@@ -178,3 +188,3 @@ if (isFed1) {

}
return subgraphs;
return [subgraphs, subgraphNameToGraphEnumValue];
}

@@ -202,3 +212,4 @@ catch (e) {

exports.extractSubgraphsFromSupergraph = extractSubgraphsFromSupergraph;
function addAllEmptySubgraphTypes({ supergraph, joinSpec, filteredTypes, getSubgraph, }) {
function addAllEmptySubgraphTypes(args) {
const { supergraph, joinSpec, filteredTypes, getSubgraph, } = args;
const typeDirective = joinSpec.typeDirective(supergraph);

@@ -214,12 +225,12 @@ const objOrItfTypes = [];

case 'ObjectType':
objOrItfTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
objOrItfTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;
case 'InputObjectType':
inputObjTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
inputObjTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;
case 'EnumType':
enumTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
enumTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;
case 'UnionType':
unionTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
unionTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;

@@ -242,3 +253,4 @@ case 'ScalarType':

}
function addEmptyType(type, typeApplications, getSubgraph) {
function addEmptyType(type, typeApplications, args) {
const { supergraph, getSubgraph, getSubgraphEnumValue } = args;
(0, utils_1.assert)(typeApplications.length > 0, `Missing @join__type on ${type}`);

@@ -267,2 +279,26 @@ const subgraphsInfo = new Map();

}
const coreFeatures = supergraph.coreFeatures;
(0, utils_1.assert)(coreFeatures, 'Should have core features');
const contextFeature = coreFeatures.getByIdentity(_1.ContextSpecDefinition.identity);
let supergraphContextDirective;
if (contextFeature) {
const contextSpec = _1.CONTEXT_VERSIONS.find(contextFeature.url.version);
(0, utils_1.assert)(contextSpec, 'Should have context spec');
supergraphContextDirective = contextSpec.contextDirective(supergraph);
}
if (supergraphContextDirective) {
const contextApplications = type.appliedDirectivesOf(supergraphContextDirective);
for (const application of contextApplications) {
const { name } = application.arguments();
const match = name.match(/^(.*)__([A-Za-z]\w*)$/);
const graph = match ? match[1] : undefined;
const context = match ? match[2] : undefined;
(0, utils_1.assert)(graph, `Invalid context name ${name} found in ${application} on ${application.parent}: does not match the expected pattern`);
const subgraphInfo = subgraphsInfo.get(getSubgraphEnumValue(graph));
const contextDirective = subgraphInfo === null || subgraphInfo === void 0 ? void 0 : subgraphInfo.subgraph.metadata().contextDirective();
if (subgraphInfo && contextDirective && (0, _1.isFederationDirectiveDefinedInSchema)(contextDirective)) {
subgraphInfo.type.applyDirective(contextDirective, { name: context });
}
}
}
return subgraphsInfo;

@@ -430,2 +466,21 @@ }

}
if (joinFieldArgs === null || joinFieldArgs === void 0 ? void 0 : joinFieldArgs.contextArguments) {
const fromContextDirective = subgraph.metadata().fromContextDirective();
if (!(0, _1.isFederationDirectiveDefinedInSchema)(fromContextDirective)) {
throw new Error(`@fromContext directive is not defined in the subgraph schema: ${subgraph.name}`);
}
else {
for (const arg of joinFieldArgs.contextArguments) {
const match = arg.context.match(/^.*__([A-Za-z]\w*)$/);
if (!match) {
throw new Error(`Invalid context argument: ${arg.context}`);
}
subgraphField.addArgument(arg.name, decodeType(arg.type, subgraph.schema, subgraph.name));
const argOnField = subgraphField.argument(arg.name);
argOnField === null || argOnField === void 0 ? void 0 : argOnField.applyDirective(fromContextDirective, {
field: `\$${match[1]} ${arg.selection}`,
});
}
}
}
const external = !!(joinFieldArgs === null || joinFieldArgs === void 0 ? void 0 : joinFieldArgs.external);

@@ -432,0 +487,0 @@ if (external) {

@@ -7,4 +7,12 @@ import { CompositeType, CoreFeature, Directive, DirectiveDefinition, FieldDefinition, InputFieldDefinition, InterfaceType, NamedType, ObjectType, ScalarType, Schema, SchemaBlueprint, SchemaConfig, SchemaElement, UnionType } from "./definitions";

import { PrintOptions as PrintOptions } from "./print";
import { SourceAPIDirectiveArgs, SourceFieldDirectiveArgs, SourceTypeDirectiveArgs } from "./specs/sourceSpec";
export declare const FEDERATION_RESERVED_SUBGRAPH_NAME = "_";
export declare const FEDERATION_UNNAMED_SUBGRAPH_NAME = "<unnamed>";
export declare function parseContext(input: string): {
context: undefined;
selection: undefined;
} | {
context: string;
selection: string;
};
export declare function collectUsedFields(metadata: FederationMetadata): Set<FieldDefinition<CompositeType>>;

@@ -71,2 +79,11 @@ export declare class FederationMetadata {

}>;
sourceAPIDirective(): Post20FederationDirectiveDefinition<SourceAPIDirectiveArgs>;
sourceTypeDirective(): Post20FederationDirectiveDefinition<SourceTypeDirectiveArgs>;
sourceFieldDirective(): Post20FederationDirectiveDefinition<SourceFieldDirectiveArgs>;
fromContextDirective(): Post20FederationDirectiveDefinition<{
field: string;
}>;
contextDirective(): Post20FederationDirectiveDefinition<{
name: string;
}>;
allFederationDirectives(): DirectiveDefinition[];

@@ -107,4 +124,4 @@ entityType(): UnionType | undefined;

export declare function setSchemaAsFed2Subgraph(schema: Schema, useLatest?: boolean): void;
export declare const FEDERATION2_LINK_WITH_FULL_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.7\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\", \"@authenticated\", \"@requiresScopes\", \"@policy\"])";
export declare const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.7\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\"])";
export declare const FEDERATION2_LINK_WITH_FULL_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.8\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\", \"@authenticated\", \"@requiresScopes\", \"@policy\", \"@sourceAPI\", \"@sourceType\", \"@sourceField\", \"@context\", \"@fromContext\"])";
export declare const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.8\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\"])";
export declare const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS_UPGRADED = "@link(url: \"https://specs.apollo.dev/federation/v2.4\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\"])";

@@ -111,0 +128,0 @@ export declare function asFed2SubgraphDocument(document: DocumentNode, options?: {

@@ -15,2 +15,3 @@ export * from './definitions';

export * from './specs/federationSpec';
export * from './specs/contextSpec';
export * from './supergraphs';

@@ -27,3 +28,3 @@ export * from './error';

export * from './specs/policySpec';
export * from './specs/connectSpec';
export * from './specs/sourceSpec';
//# sourceMappingURL=index.d.ts.map

@@ -32,2 +32,3 @@ "use strict";

__exportStar(require("./specs/federationSpec"), exports);
__exportStar(require("./specs/contextSpec"), exports);
__exportStar(require("./supergraphs"), exports);

@@ -45,3 +46,3 @@ __exportStar(require("./error"), exports);

__exportStar(require("./specs/policySpec"), exports);
__exportStar(require("./specs/connectSpec"), exports);
__exportStar(require("./specs/sourceSpec"), exports);
//# sourceMappingURL=index.js.map

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

import { GraphQLError } from "graphql";
import { Schema } from "./definitions";
import { FeatureDefinition, FeatureDefinitions, FeatureUrl } from "./specs/coreSpec";
export declare function registerKnownFeature(definitions: FeatureDefinitions): void;
export declare function coreFeatureDefinitionIfKnown(url: FeatureUrl): FeatureDefinition | undefined;
export declare function validateKnownFeatures(schema: Schema, errorCollector?: GraphQLError[]): GraphQLError[];
export declare function unregisterKnownFeatures(definitions: FeatureDefinitions): void;
//# sourceMappingURL=knownCoreFeatures.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unregisterKnownFeatures = exports.coreFeatureDefinitionIfKnown = exports.registerKnownFeature = void 0;
exports.unregisterKnownFeatures = exports.validateKnownFeatures = exports.coreFeatureDefinitionIfKnown = exports.registerKnownFeature = void 0;
const coreSpec_1 = require("./specs/coreSpec");
const registeredFeatures = new Map();

@@ -16,2 +17,12 @@ function registerKnownFeature(definitions) {

exports.coreFeatureDefinitionIfKnown = coreFeatureDefinitionIfKnown;
function validateKnownFeatures(schema, errorCollector = []) {
registeredFeatures.forEach(definitions => {
const feature = definitions.latest();
if (feature.validateSubgraphSchema !== coreSpec_1.FeatureDefinition.prototype.validateSubgraphSchema) {
errorCollector.push(...feature.validateSubgraphSchema(schema));
}
});
return errorCollector;
}
exports.validateKnownFeatures = validateKnownFeatures;
function unregisterKnownFeatures(definitions) {

@@ -18,0 +29,0 @@ registeredFeatures.delete(definitions.identity);

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

import { ArgumentNode, DocumentNode, FieldNode, FragmentDefinitionNode, SelectionNode, SelectionSetNode } from "graphql";
import { Directive, DirectiveTargetElement, FieldDefinition, InterfaceType, ObjectType, Schema, SchemaRootKind, VariableCollector, VariableDefinitions, CompositeType, DeferDirectiveArgs, Variable, Type, Variables, NamedType } from "./definitions";
import { ArgumentNode, DocumentNode, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, SelectionNode, SelectionSetNode } from "graphql";
import { Directive, DirectiveTargetElement, FieldDefinition, Schema, SchemaRootKind, VariableCollector, VariableDefinitions, CompositeType, DeferDirectiveArgs, Variable, Type, Variables, NamedType } from "./definitions";
import { MultiMap, SetMultiMap } from "./utils";

@@ -41,2 +41,3 @@ declare abstract class AbstractOperationElement<T extends AbstractOperationElement<T>> extends DirectiveTargetElement<T> {

baseType(): NamedType;
withUpdatedArguments(newArgs: TArgs): Field<TArgs>;
withUpdatedDefinition(newDefinition: FieldDefinition<any>): Field<TArgs>;

@@ -46,5 +47,4 @@ withUpdatedAlias(newAlias: string | undefined): Field<TArgs>;

argumentsToNodes(): ArgumentNode[] | undefined;
appliesTo(type: ObjectType | InterfaceType): boolean;
selects(definition: FieldDefinition<any>, assumeValid?: boolean, variableDefinitions?: VariableDefinitions): boolean;
validate(variableDefinitions: VariableDefinitions): void;
selects(definition: FieldDefinition<any>, assumeValid?: boolean, variableDefinitions?: VariableDefinitions, contextualArguments?: string[]): boolean;
validate(variableDefinitions: VariableDefinitions, validateContextualArgs: boolean): void;
rebaseOn({ parentType, errorIfCannotRebase }: {

@@ -239,3 +239,3 @@ parentType: CompositeType;

canRebaseOn(parentTypeToTest: CompositeType): boolean;
validate(variableDefinitions: VariableDefinitions): void;
validate(variableDefinitions: VariableDefinitions, validateContextualArgs?: boolean): void;
isEmpty(): boolean;

@@ -300,3 +300,3 @@ toSelectionSetNode(): SelectionSetNode;

abstract toSelectionNode(): SelectionNode;
abstract validate(variableDefinitions: VariableDefinitions): void;
abstract validate(variableDefinitions: VariableDefinitions, validateContextualArgs: boolean): void;
abstract rebaseOn(args: {

@@ -367,3 +367,3 @@ parentType: CompositeType;

filterRecursiveDepthFirst(predicate: (selection: Selection) => boolean): FieldSelection | undefined;
validate(variableDefinitions: VariableDefinitions): void;
validate(variableDefinitions: VariableDefinitions, validateContextualArgs: boolean): void;
rebaseOn({ parentType, fragments, errorIfCannotRebase, }: {

@@ -426,4 +426,6 @@ parentType: CompositeType;

}): SelectionSet;
export declare function parseOperationAST(source: string): OperationDefinitionNode;
export declare function operationToDocument(operation: Operation): DocumentNode;
export declare function hasSelectionWithPredicate(selectionSet: SelectionSet, predicate: (s: Selection) => boolean): boolean;
export {};
//# sourceMappingURL=operations.d.ts.map

@@ -29,2 +29,3 @@ import { ASTNode, GraphQLError, StringValueNode } from "graphql";

allElementNames(): string[];
validateSubgraphSchema(_schema: Schema): GraphQLError[];
protected nameInSchema(schema: Schema): string | undefined;

@@ -31,0 +32,0 @@ protected directiveNameInSchema(schema: Schema, directiveName: string): string | undefined;

@@ -95,2 +95,5 @@ "use strict";

}
validateSubgraphSchema(_schema) {
return [];
}
nameInSchema(schema) {

@@ -97,0 +100,0 @@ const feature = this.featureInSchema(schema);

import { FeatureDefinition, FeatureDefinitions, FeatureVersion } from "./coreSpec";
export declare const federationIdentity = "https://specs.apollo.dev/federation";
export declare enum FederationTypeName {
FIELD_SET = "FieldSet"
FIELD_SET = "FieldSet",
CONTEXT_FIELD_VALUE = "ContextFieldValue"
}

@@ -20,3 +21,8 @@ export declare enum FederationDirectiveName {

REQUIRES_SCOPES = "requiresScopes",
POLICY = "policy"
POLICY = "policy",
SOURCE_API = "sourceAPI",
SOURCE_TYPE = "sourceType",
SOURCE_FIELD = "sourceField",
CONTEXT = "context",
FROM_CONTEXT = "fromContext"
}

@@ -23,0 +29,0 @@ export declare const FEDERATION1_TYPES: import("../directiveAndTypeSpecification").TypeSpecification[];

@@ -16,2 +16,4 @@ "use strict";

const policySpec_1 = require("./policySpec");
const sourceSpec_1 = require("./sourceSpec");
const contextSpec_1 = require("./contextSpec");
exports.federationIdentity = 'https://specs.apollo.dev/federation';

@@ -21,2 +23,3 @@ var FederationTypeName;

FederationTypeName["FIELD_SET"] = "FieldSet";
FederationTypeName["CONTEXT_FIELD_VALUE"] = "ContextFieldValue";
})(FederationTypeName || (exports.FederationTypeName = FederationTypeName = {}));

@@ -39,2 +42,7 @@ var FederationDirectiveName;

FederationDirectiveName["POLICY"] = "policy";
FederationDirectiveName["SOURCE_API"] = "sourceAPI";
FederationDirectiveName["SOURCE_TYPE"] = "sourceType";
FederationDirectiveName["SOURCE_FIELD"] = "sourceField";
FederationDirectiveName["CONTEXT"] = "context";
FederationDirectiveName["FROM_CONTEXT"] = "fromContext";
})(FederationDirectiveName || (exports.FederationDirectiveName = FederationDirectiveName = {}));

@@ -143,2 +151,8 @@ const fieldSetTypeSpec = (0, directiveAndTypeSpecification_1.createScalarTypeSpecification)({ name: FederationTypeName.FIELD_SET });

}
if (version.gte(new coreSpec_1.FeatureVersion(2, 7))) {
this.registerSubFeature(sourceSpec_1.SOURCE_VERSIONS.find(new coreSpec_1.FeatureVersion(0, 1)));
}
if (version.gte(new coreSpec_1.FeatureVersion(2, 8))) {
this.registerSubFeature(contextSpec_1.CONTEXT_VERSIONS.find(new coreSpec_1.FeatureVersion(0, 1)));
}
}

@@ -155,4 +169,5 @@ }

.add(new FederationSpecDefinition(new coreSpec_1.FeatureVersion(2, 6)))
.add(new FederationSpecDefinition(new coreSpec_1.FeatureVersion(2, 7)));
.add(new FederationSpecDefinition(new coreSpec_1.FeatureVersion(2, 7)))
.add(new FederationSpecDefinition(new coreSpec_1.FeatureVersion(2, 8)));
(0, knownCoreFeatures_1.registerKnownFeature)(exports.FEDERATION_VERSIONS);
//# sourceMappingURL=federationSpec.js.map

@@ -22,2 +22,8 @@ import { GraphQLError } from 'graphql';

overrideLabel?: string;
contextArguments?: {
name: string;
type: string;
context: string;
selection: string;
}[];
};

@@ -24,0 +30,0 @@ export type JoinDirectiveArguments = {

@@ -84,2 +84,11 @@ "use strict";

}
if (this.version.gte(new coreSpec_1.FeatureVersion(0, 5))) {
const fieldValue = this.addScalarType(schema, 'FieldValue');
const contextArgumentsType = schema.addType(new definitions_1.InputObjectType('join__ContextArgument'));
contextArgumentsType.addField('name', new definitions_1.NonNullType(schema.stringType()));
contextArgumentsType.addField('type', new definitions_1.NonNullType(schema.stringType()));
contextArgumentsType.addField('context', new definitions_1.NonNullType(schema.stringType()));
contextArgumentsType.addField('selection', new definitions_1.NonNullType(fieldValue));
joinField.addArgument('contextArguments', new definitions_1.ListType(new definitions_1.NonNullType(contextArgumentsType)));
}
if (this.isV01()) {

@@ -171,4 +180,5 @@ const joinOwner = this.addDirective(schema, 'owner').addLocations(graphql_1.DirectiveLocation.OBJECT);

.add(new JoinSpecDefinition(new coreSpec_1.FeatureVersion(0, 3), new coreSpec_1.FeatureVersion(2, 0)))
.add(new JoinSpecDefinition(new coreSpec_1.FeatureVersion(0, 4), new coreSpec_1.FeatureVersion(2, 7)));
.add(new JoinSpecDefinition(new coreSpec_1.FeatureVersion(0, 4), new coreSpec_1.FeatureVersion(2, 7)))
.add(new JoinSpecDefinition(new coreSpec_1.FeatureVersion(0, 5), new coreSpec_1.FeatureVersion(2, 8)));
(0, knownCoreFeatures_1.registerKnownFeature)(exports.JOIN_VERSIONS);
//# sourceMappingURL=joinSpec.js.map

@@ -6,2 +6,3 @@ import { DocumentNode } from "graphql";

export declare const DEFAULT_SUPPORTED_SUPERGRAPH_FEATURES: Set<string>;
export declare const ROUTER_SUPPORTED_SUPERGRAPH_FEATURES: Set<string>;
export declare function validateSupergraph(supergraph: Schema): [CoreFeatures, JoinSpecDefinition];

@@ -14,2 +15,3 @@ export declare function isFed1Supergraph(supergraph: Schema): boolean;

private _subgraphs?;
private _subgraphNameToGraphEnumValue?;
constructor(schema: Schema, supportedFeatures?: Set<string> | null, shouldValidate?: boolean);

@@ -20,2 +22,3 @@ static build(supergraphSdl: string | DocumentNode, options?: {

}): Supergraph;
static buildForTests(supergraphSdl: string | DocumentNode, validateSupergraph?: boolean): Supergraph;
subgraphsMetadata(): readonly {

@@ -26,4 +29,5 @@ name: string;

subgraphs(): Subgraphs;
subgraphNameToGraphEnumValue(): Map<string, string>;
apiSchema(): Schema;
}
//# sourceMappingURL=supergraphs.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Supergraph = exports.isFed1Supergraph = exports.validateSupergraph = exports.DEFAULT_SUPPORTED_SUPERGRAPH_FEATURES = void 0;
exports.Supergraph = exports.isFed1Supergraph = exports.validateSupergraph = exports.ROUTER_SUPPORTED_SUPERGRAPH_FEATURES = exports.DEFAULT_SUPPORTED_SUPERGRAPH_FEATURES = void 0;
const coreSpec_1 = require("./specs/coreSpec");

@@ -17,2 +17,3 @@ const definitions_1 = require("./definitions");

'https://specs.apollo.dev/join/v0.4',
'https://specs.apollo.dev/join/v0.5',
'https://specs.apollo.dev/tag/v0.1',

@@ -24,2 +25,21 @@ 'https://specs.apollo.dev/tag/v0.2',

]);
exports.ROUTER_SUPPORTED_SUPERGRAPH_FEATURES = new Set([
'https://specs.apollo.dev/core/v0.1',
'https://specs.apollo.dev/core/v0.2',
'https://specs.apollo.dev/join/v0.1',
'https://specs.apollo.dev/join/v0.2',
'https://specs.apollo.dev/join/v0.3',
'https://specs.apollo.dev/join/v0.4',
'https://specs.apollo.dev/join/v0.5',
'https://specs.apollo.dev/tag/v0.1',
'https://specs.apollo.dev/tag/v0.2',
'https://specs.apollo.dev/tag/v0.3',
'https://specs.apollo.dev/inaccessible/v0.1',
'https://specs.apollo.dev/inaccessible/v0.2',
'https://specs.apollo.dev/authenticated/v0.1',
'https://specs.apollo.dev/requiresScopes/v0.1',
'https://specs.apollo.dev/policy/v0.1',
'https://specs.apollo.dev/source/v0.1',
'https://specs.apollo.dev/context/v0.1',
]);
const coreVersionZeroDotOneUrl = coreSpec_1.FeatureUrl.parse('https://specs.apollo.dev/core/v0.1');

@@ -91,2 +111,5 @@ function checkFeatureSupport(coreFeatures, supportedFeatures) {

}
static buildForTests(supergraphSdl, validateSupergraph) {
return Supergraph.build(supergraphSdl, { supportedFeatures: exports.ROUTER_SUPPORTED_SUPERGRAPH_FEATURES, validateSupergraph });
}
subgraphsMetadata() {

@@ -97,6 +120,16 @@ return this.containedSubgraphs;

if (!this._subgraphs) {
this._subgraphs = (0, extractSubgraphsFromSupergraph_1.extractSubgraphsFromSupergraph)(this.schema, this.shouldValidate);
const extractionResults = (0, extractSubgraphsFromSupergraph_1.extractSubgraphsFromSupergraph)(this.schema, this.shouldValidate);
this._subgraphs = extractionResults[0];
this._subgraphNameToGraphEnumValue = extractionResults[1];
}
return this._subgraphs;
}
subgraphNameToGraphEnumValue() {
if (!this._subgraphNameToGraphEnumValue) {
const extractionResults = (0, extractSubgraphsFromSupergraph_1.extractSubgraphsFromSupergraph)(this.schema, this.shouldValidate);
this._subgraphs = extractionResults[0];
this._subgraphNameToGraphEnumValue = extractionResults[1];
}
return new Map([...this._subgraphNameToGraphEnumValue]);
}
apiSchema() {

@@ -103,0 +136,0 @@ return this.schema.toAPISchema();

@@ -65,2 +65,5 @@ export declare function assert(condition: any, message: string | (() => string)): asserts condition;

export declare function findLast<T>(array: T[], predicate: (t: T) => boolean): T | undefined;
export declare function mergeMapOrNull<K, V>(m1: Map<K, V> | null, m2: Map<K, V> | null): Map<K, V> | null;
export declare function composeSets<T>(s1: Set<T> | null, s2: Set<T> | null): Set<T> | null;
export declare function setsEqual<T>(s1: Set<T> | null, s2: Set<T> | null): boolean;
//# sourceMappingURL=utils.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLast = exports.isNonEmptyArray = exports.removeArrayElement = exports.isDefined = exports.printHumanReadableList = exports.joinStrings = exports.validateStringContainsBoolean = exports.copyWitNewLength = exports.MapWithCachedArrays = exports.setValues = exports.mapEntries = exports.mapKeys = exports.mapValues = exports.firstOf = exports.isSubset = exports.arrayEquals = exports.OrderedMap = exports.SetMultiMap = exports.MultiMap = exports.assertUnreachable = exports.assert = void 0;
exports.setsEqual = exports.composeSets = exports.mergeMapOrNull = exports.findLast = exports.isNonEmptyArray = exports.removeArrayElement = exports.isDefined = exports.printHumanReadableList = exports.joinStrings = exports.validateStringContainsBoolean = exports.copyWitNewLength = exports.MapWithCachedArrays = exports.setValues = exports.mapEntries = exports.mapKeys = exports.mapValues = exports.firstOf = exports.isSubset = exports.arrayEquals = exports.OrderedMap = exports.SetMultiMap = exports.MultiMap = exports.assertUnreachable = exports.assert = void 0;
function assert(condition, message) {

@@ -336,2 +336,40 @@ if (!condition) {

exports.findLast = findLast;
function mergeMapOrNull(m1, m2) {
if (!m1) {
return m2;
}
if (!m2) {
return m1;
}
return new Map([...m1, ...m2]);
}
exports.mergeMapOrNull = mergeMapOrNull;
function composeSets(s1, s2) {
if (!s1 && !s2) {
return null;
}
const result = new Set();
s1 === null || s1 === void 0 ? void 0 : s1.forEach(v => result.add(v));
s2 === null || s2 === void 0 ? void 0 : s2.forEach(v => result.add(v));
return result;
}
exports.composeSets = composeSets;
function setsEqual(s1, s2) {
if (s1 === s2) {
return true;
}
if (!s1 && !s2) {
return true;
}
if (!s1 || !s2 || s1.size !== s2.size) {
return false;
}
for (const key of s1) {
if (!s2.has(key)) {
return false;
}
}
return true;
}
exports.setsEqual = setsEqual;
//# sourceMappingURL=utils.js.map
{
"name": "@apollo/federation-internals",
"version": "2.8.0-connectors.5",
"version": "2.8.0",
"description": "Apollo Federation internal utilities",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -27,2 +27,3 @@ import { ASTNode, DirectiveLocation, GraphQLError } from "graphql";

import { FeatureDefinition, FeatureVersion } from "./specs/coreSpec";
import { Subgraph } from '.';

@@ -38,4 +39,7 @@ export type DirectiveSpecification = {

argumentsMerger?: (schema: Schema, feature: CoreFeature) => ArgumentMerger | GraphQLError,
staticArgumentTransform?: StaticArgumentsTransform,
}
export type StaticArgumentsTransform = (subgraph: Subgraph, args: Readonly<{[key: string]: any}>) => Readonly<{[key: string]: any}>;
export type ArgumentMerger = {

@@ -80,2 +84,3 @@ merge: (argName: string, values: any[]) => any,

supergraphSpecification = undefined,
staticArgumentTransform = undefined,
}: {

@@ -88,2 +93,3 @@ name: string,

supergraphSpecification?: (fedVersion: FeatureVersion) => FeatureDefinition,
staticArgumentTransform?: (subgraph: Subgraph, args: {[key: string]: any}) => {[key: string]: any},
}): DirectiveSpecification {

@@ -116,3 +122,3 @@ let composition: DirectiveCompositionSpecification | undefined = undefined;

}
};
}
return {

@@ -136,2 +142,3 @@ merge: (argName, values) => {

argumentsMerger,
staticArgumentTransform,
};

@@ -138,0 +145,0 @@ }

@@ -328,2 +328,32 @@ import { ASTNode, GraphQLError, GraphQLErrorOptions, GraphQLFormattedError } from "graphql";

const CONTEXT_NOT_SET = makeCodeDefinition(
'CONTEXT_NOT_SET',
'Context is never set for context trying to be used.',
{ addedIn: '2.8.0' },
);
const CONTEXT_INVALID_SELECTION= makeCodeDefinition(
'CONTEXT_INVALID_SELECTION',
'Selection within @fromContext must resolve to a single field.',
{ addedIn: '2.8.0' },
);
const NO_CONTEXT_IN_SELECTION = makeCodeDefinition(
'NO_CONTEXT_IN_SELECTION',
'Selection in @fromContext field argument does not reference a context.',
{ addedIn: '2.8.0' },
);
const CONTEXT_NO_RESOLVABLE_KEY = makeCodeDefinition(
'CONTEXT_NO_RESOLVABLE_KEY',
'If an ObjectType uses a @fromContext, at least one of its keys must be resolvable.',
{ addedIn: '2.8.0' },
);
const CONTEXT_NAME_INVALID = makeCodeDefinition(
'CONTEXT_NAME_INVALID',
'Context name is invalid.',
{ addedIn: '2.8.0' },
);
const EXTERNAL_TYPE_MISMATCH = makeCodeDefinition(

@@ -565,2 +595,121 @@ 'EXTERNAL_TYPE_MISMATCH',

const SOURCE_FEDERATION_VERSION_REQUIRED = makeCodeDefinition(
'SOURCE_FEDERATION_VERSION_REQUIRED',
'Schemas using `@source{API,Type,Field}` directives must @link-import v2.7 or later of federation',
{ addedIn: '2.7.1' },
);
const SOURCE_API_NAME_INVALID = makeCodeDefinition(
'SOURCE_API_NAME_INVALID',
'Each `@sourceAPI` directive must take a unique and valid name as an argument',
{ addedIn: '2.7.0' },
);
const SOURCE_API_PROTOCOL_INVALID = makeCodeDefinition(
'SOURCE_API_PROTOCOL_INVALID',
'Each `@sourceAPI` directive must specify exactly one of the known protocols',
{ addedIn: '2.7.0' },
);
const SOURCE_API_HTTP_BASE_URL_INVALID = makeCodeDefinition(
'SOURCE_API_HTTP_BASE_URL_INVALID',
'The `@sourceAPI` directive must specify a valid http.baseURL',
{ addedIn: '2.7.0' },
);
const SOURCE_HTTP_HEADERS_INVALID = makeCodeDefinition(
'SOURCE_HTTP_HEADERS_INVALID',
'The `http.headers` argument of `@source*` directives must specify valid HTTP headers',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_API_ERROR = makeCodeDefinition(
'SOURCE_TYPE_API_ERROR',
'The `api` argument of the `@sourceType` directive must match a valid `@sourceAPI` name',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_PROTOCOL_INVALID = makeCodeDefinition(
'SOURCE_TYPE_PROTOCOL_INVALID',
'The `@sourceType` directive must specify the same protocol as its corresponding `@sourceAPI`',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_HTTP_METHOD_INVALID = makeCodeDefinition(
'SOURCE_TYPE_HTTP_METHOD_INVALID',
'The `@sourceType` directive must specify exactly one of `http.GET` or `http.POST`',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_HTTP_PATH_INVALID = makeCodeDefinition(
'SOURCE_TYPE_HTTP_PATH_INVALID',
'The `@sourceType` directive must specify a valid URL template for `http.GET` or `http.POST`',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_HTTP_BODY_INVALID = makeCodeDefinition(
'SOURCE_TYPE_HTTP_BODY_INVALID',
'If the `@sourceType` specifies `http.body`, it must be a valid `JSONSelection`',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY = makeCodeDefinition(
'SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY',
'The `@sourceType` directive must be applied to an object or interface type that also has `@key`',
{ addedIn: '2.7.0' },
);
const SOURCE_TYPE_SELECTION_INVALID = makeCodeDefinition(
'SOURCE_TYPE_SELECTION_INVALID',
'The `selection` argument of the `@sourceType` directive must be a valid `JSONSelection` that outputs fields of the GraphQL type',
);
const SOURCE_FIELD_API_ERROR = makeCodeDefinition(
'SOURCE_FIELD_API_ERROR',
'The `api` argument of the `@sourceField` directive must match a valid `@sourceAPI` name',
{ addedIn: '2.7.0' },
);
const SOURCE_FIELD_PROTOCOL_INVALID = makeCodeDefinition(
'SOURCE_FIELD_PROTOCOL_INVALID',
'If `@sourceField` specifies a protocol, it must match the corresponding `@sourceAPI` protocol',
{ addedIn: '2.7.0' },
);
const SOURCE_FIELD_HTTP_METHOD_INVALID = makeCodeDefinition(
'SOURCE_FIELD_HTTP_METHOD_INVALID',
'The `@sourceField` directive must specify at most one of `http.{GET,POST,PUT,PATCH,DELETE}`',
{ addedIn: '2.7.0' },
);
const SOURCE_FIELD_HTTP_PATH_INVALID = makeCodeDefinition(
'SOURCE_FIELD_HTTP_PATH_INVALID',
'The `@sourceField` directive must specify a valid URL template for `http.{GET,POST,PUT,PATCH,DELETE}`',
{ addedIn: '2.7.0' },
);
const SOURCE_FIELD_HTTP_BODY_INVALID = makeCodeDefinition(
'SOURCE_FIELD_HTTP_BODY_INVALID',
'If `@sourceField` specifies http.body, it must be a valid `JSONSelection` matching available arguments and fields',
{ addedIn: '2.7.0' },
);
const SOURCE_FIELD_SELECTION_INVALID = makeCodeDefinition(
'SOURCE_FIELD_SELECTION_INVALID',
'The `selection` argument of the `@sourceField` directive must be a valid `JSONSelection` that outputs fields of the GraphQL type',
{ addedIn: '2.7.0' },
);
const SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD = makeCodeDefinition(
'SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD',
'The `@sourceField` directive must be applied to a field of the `Query` or `Mutation` types, or of an entity type',
{ addedIn: '2.7.0' },
);
const CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS = makeCodeDefinition(
'CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS',
'Argument on field is marked contextual in only some subgraphs',
{ addedIn: '2.7.0' },
);
export const ERROR_CATEGORIES = {

@@ -608,2 +757,7 @@ DIRECTIVE_FIELDS_MISSING_EXTERNAL,

TYPE_KIND_MISMATCH,
CONTEXT_NOT_SET,
CONTEXT_INVALID_SELECTION,
NO_CONTEXT_IN_SELECTION,
CONTEXT_NO_RESOLVABLE_KEY,
CONTEXT_NAME_INVALID,
EXTERNAL_TYPE_MISMATCH,

@@ -655,2 +809,23 @@ EXTERNAL_ARGUMENT_MISSING,

INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE,
// Errors related to @sourceAPI, @sourceType, and/or @sourceField
SOURCE_FEDERATION_VERSION_REQUIRED,
SOURCE_API_NAME_INVALID,
SOURCE_API_PROTOCOL_INVALID,
SOURCE_API_HTTP_BASE_URL_INVALID,
SOURCE_HTTP_HEADERS_INVALID,
SOURCE_TYPE_API_ERROR,
SOURCE_TYPE_PROTOCOL_INVALID,
SOURCE_TYPE_HTTP_METHOD_INVALID,
SOURCE_TYPE_HTTP_PATH_INVALID,
SOURCE_TYPE_HTTP_BODY_INVALID,
SOURCE_TYPE_ON_NON_OBJECT_OR_NON_ENTITY,
SOURCE_TYPE_SELECTION_INVALID,
SOURCE_FIELD_API_ERROR,
SOURCE_FIELD_PROTOCOL_INVALID,
SOURCE_FIELD_HTTP_METHOD_INVALID,
SOURCE_FIELD_HTTP_PATH_INVALID,
SOURCE_FIELD_HTTP_BODY_INVALID,
SOURCE_FIELD_SELECTION_INVALID,
SOURCE_FIELD_NOT_ON_ROOT_OR_ENTITY_FIELD,
CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS,
};

@@ -657,0 +832,0 @@

@@ -43,3 +43,3 @@ import {

import { validateStringContainsBoolean } from "./utils";
import { errorCauses, printErrors } from ".";
import { CONTEXT_VERSIONS, ContextSpecDefinition, DirectiveDefinition, errorCauses, isFederationDirectiveDefinedInSchema, printErrors } from ".";

@@ -197,3 +197,3 @@ function filteredTypes(

export function extractSubgraphsFromSupergraph(supergraph: Schema, validateExtractedSubgraphs: boolean = true): Subgraphs {
export function extractSubgraphsFromSupergraph(supergraph: Schema, validateExtractedSubgraphs: boolean = true): [Subgraphs, Map<string, string>] {
const [coreFeatures, joinSpec] = validateSupergraph(supergraph);

@@ -217,2 +217,13 @@ const isFed1 = joinSpec.version.equals(new FeatureVersion(0, 1));

const subgraphNameToGraphEnumValue = new Map<string, string>();
for (const [k, v] of graphEnumNameToSubgraphName.entries()) {
subgraphNameToGraphEnumValue.set(v, k);
}
const getSubgraphEnumValue = (subgraphName: string): string => {
const enumValue = subgraphNameToGraphEnumValue.get(subgraphName);
assert(enumValue, () => `Invalid subgraph name ${subgraphName} found: does not match a subgraph defined in the @join__Graph enum`);
return enumValue;
}
const types = filteredTypes(supergraph, joinSpec, coreFeatures.coreDefinition);

@@ -225,2 +236,3 @@ const args: ExtractArguments = {

getSubgraph,
getSubgraphEnumValue,
};

@@ -248,3 +260,3 @@ if (isFed1) {

return subgraphs;
return [subgraphs, subgraphNameToGraphEnumValue];
} catch (e) {

@@ -289,2 +301,3 @@ let error = e;

getSubgraph: (application: Directive<any, { graph?: string }>) => Subgraph | undefined,
getSubgraphEnumValue: (subgraphName: string) => string
}

@@ -306,8 +319,9 @@

function addAllEmptySubgraphTypes({
supergraph,
joinSpec,
filteredTypes,
getSubgraph,
}: ExtractArguments): TypesInfo {
function addAllEmptySubgraphTypes(args: ExtractArguments): TypesInfo {
const {
supergraph,
joinSpec,
filteredTypes,
getSubgraph,
} = args;
const typeDirective = joinSpec.typeDirective(supergraph);

@@ -326,12 +340,12 @@

case 'ObjectType':
objOrItfTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
objOrItfTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;
case 'InputObjectType':
inputObjTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
inputObjTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;
case 'EnumType':
enumTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
enumTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;
case 'UnionType':
unionTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), getSubgraph) });
unionTypes.push({ type, subgraphsInfo: addEmptyType(type, type.appliedDirectivesOf(typeDirective), args) });
break;

@@ -361,4 +375,5 @@ case 'ScalarType':

typeApplications: Directive<T, JoinTypeDirectiveArguments>[],
getSubgraph: (application: Directive<any, { graph?: string }>) => Subgraph | undefined,
args: ExtractArguments,
): SubgraphTypeInfo<T> {
const { supergraph, getSubgraph, getSubgraphEnumValue } = args;
// In fed2, we always mark all types with `@join__type` but making sure.

@@ -394,2 +409,29 @@ assert(typeApplications.length > 0, `Missing @join__type on ${type}`)

}
const coreFeatures = supergraph.coreFeatures;
assert(coreFeatures, 'Should have core features');
const contextFeature = coreFeatures.getByIdentity(ContextSpecDefinition.identity);
let supergraphContextDirective: DirectiveDefinition<{ name: string}> | undefined;
if (contextFeature) {
const contextSpec = CONTEXT_VERSIONS.find(contextFeature.url.version);
assert(contextSpec, 'Should have context spec');
supergraphContextDirective = contextSpec.contextDirective(supergraph);
}
if (supergraphContextDirective) {
const contextApplications = type.appliedDirectivesOf(supergraphContextDirective);
// for every application, apply the context directive to the correct subgraph
for (const application of contextApplications) {
const { name } = application.arguments();
const match = name.match(/^(.*)__([A-Za-z]\w*)$/);
const graph = match ? match[1] : undefined;
const context = match ? match[2] : undefined;
assert(graph, `Invalid context name ${name} found in ${application} on ${application.parent}: does not match the expected pattern`);
const subgraphInfo = subgraphsInfo.get(getSubgraphEnumValue(graph));
const contextDirective = subgraphInfo?.subgraph.metadata().contextDirective();
if (subgraphInfo && contextDirective && isFederationDirectiveDefinedInSchema(contextDirective)) {
subgraphInfo.type.applyDirective(contextDirective, {name: context});
}
}
}
return subgraphsInfo;

@@ -623,2 +665,22 @@ }

}
if (joinFieldArgs?.contextArguments) {
const fromContextDirective = subgraph.metadata().fromContextDirective();
if (!isFederationDirectiveDefinedInSchema(fromContextDirective)) {
throw new Error(`@fromContext directive is not defined in the subgraph schema: ${subgraph.name}`);
} else {
for (const arg of joinFieldArgs.contextArguments) {
// this code will remove the subgraph name from the context
const match = arg.context.match(/^.*__([A-Za-z]\w*)$/);
if (!match) {
throw new Error(`Invalid context argument: ${arg.context}`);
}
subgraphField.addArgument(arg.name, decodeType(arg.type, subgraph.schema, subgraph.name));
const argOnField = subgraphField.argument(arg.name);
argOnField?.applyDirective(fromContextDirective, {
field: `\$${match[1]} ${arg.selection}`,
});
}
}
}
const external = !!joinFieldArgs?.external;

@@ -625,0 +687,0 @@ if (external) {

@@ -15,2 +15,3 @@ export * from './definitions';

export * from './specs/federationSpec';
export * from './specs/contextSpec';
export * from './supergraphs';

@@ -27,2 +28,2 @@ export * from './error';

export * from './specs/policySpec';
export * from './specs/connectSpec';
export * from './specs/sourceSpec';

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

import { GraphQLError } from "graphql";
import { Schema } from "./definitions";
import { FeatureDefinition, FeatureDefinitions, FeatureUrl } from "./specs/coreSpec";

@@ -15,2 +17,15 @@

export function validateKnownFeatures(
schema: Schema,
errorCollector: GraphQLError[] = [],
): GraphQLError[] {
registeredFeatures.forEach(definitions => {
const feature = definitions.latest();
if (feature.validateSubgraphSchema !== FeatureDefinition.prototype.validateSubgraphSchema) {
errorCollector.push(...feature.validateSubgraphSchema(schema));
}
});
return errorCollector;
}
/**

@@ -17,0 +32,0 @@ * Removes a feature from the set of known features.

@@ -120,2 +120,7 @@ import { ASTNode, DirectiveLocation, GraphQLError, StringValueNode } from "graphql";

// No-op implementation that can be overridden by subclasses.
validateSubgraphSchema(_schema: Schema): GraphQLError[] {
return [];
}
protected nameInSchema(schema: Schema): string | undefined {

@@ -122,0 +127,0 @@ const feature = this.featureInSchema(schema);

@@ -21,2 +21,4 @@ import {

import { POLICY_VERSIONS } from './policySpec';
import { SOURCE_VERSIONS } from './sourceSpec';
import { CONTEXT_VERSIONS } from './contextSpec';

@@ -27,2 +29,3 @@ export const federationIdentity = 'https://specs.apollo.dev/federation';

FIELD_SET = 'FieldSet',
CONTEXT_FIELD_VALUE = 'ContextFieldValue',
}

@@ -45,2 +48,7 @@

POLICY = 'policy',
SOURCE_API = 'sourceAPI',
SOURCE_TYPE = 'sourceType',
SOURCE_FIELD = 'sourceField',
CONTEXT = 'context',
FROM_CONTEXT = 'fromContext',
}

@@ -172,2 +180,10 @@

}
if (version.gte(new FeatureVersion(2, 7))) {
this.registerSubFeature(SOURCE_VERSIONS.find(new FeatureVersion(0, 1))!);
}
if (version.gte(new FeatureVersion(2, 8))) {
this.registerSubFeature(CONTEXT_VERSIONS.find(new FeatureVersion(0, 1))!);
}
}

@@ -184,4 +200,5 @@ }

.add(new FederationSpecDefinition(new FeatureVersion(2, 6)))
.add(new FederationSpecDefinition(new FeatureVersion(2, 7)));
.add(new FederationSpecDefinition(new FeatureVersion(2, 7)))
.add(new FederationSpecDefinition(new FeatureVersion(2, 8)));
registerKnownFeature(FEDERATION_VERSIONS);

@@ -10,2 +10,3 @@ import { DirectiveLocation, GraphQLError } from 'graphql';

ListType,
InputObjectType,
} from "../definitions";

@@ -40,3 +41,3 @@ import { Subgraph, Subgraphs } from "../federation";

resolvable?: boolean,
isInterfaceObject?: boolean
isInterfaceObject?: boolean,
};

@@ -53,2 +54,8 @@

overrideLabel?: string,
contextArguments?: {
name: string,
type: string,
context: string,
selection: string,
}[],
}

@@ -157,6 +164,21 @@

//progressive override
// progressive override
joinField.addArgument('overrideLabel', schema.stringType());
}
if (this.version.gte(new FeatureVersion(0, 5))) {
const fieldValue = this.addScalarType(schema, 'FieldValue');
// set context
// there are no renames that happen within the join spec, so this is fine
// note that join spec will only used in supergraph schema
const contextArgumentsType = schema.addType(new InputObjectType('join__ContextArgument'));
contextArgumentsType.addField('name', new NonNullType(schema.stringType()));
contextArgumentsType.addField('type', new NonNullType(schema.stringType()));
contextArgumentsType.addField('context', new NonNullType(schema.stringType()));
contextArgumentsType.addField('selection', new NonNullType(fieldValue));
joinField.addArgument('contextArguments', new ListType(new NonNullType(contextArgumentsType)));
}
if (this.isV01()) {

@@ -268,2 +290,3 @@ const joinOwner = this.addDirective(schema, 'owner').addLocations(DirectiveLocation.OBJECT);

// - 0.4: adds the optional `overrideLabel` argument to `@join_field` for progressive override.
// - 0.5: adds the `contextArguments` argument to `@join_field` for setting context.
export const JOIN_VERSIONS = new FeatureDefinitions<JoinSpecDefinition>(joinIdentity)

@@ -273,4 +296,5 @@ .add(new JoinSpecDefinition(new FeatureVersion(0, 1)))

.add(new JoinSpecDefinition(new FeatureVersion(0, 3), new FeatureVersion(2, 0)))
.add(new JoinSpecDefinition(new FeatureVersion(0, 4), new FeatureVersion(2, 7)));
.add(new JoinSpecDefinition(new FeatureVersion(0, 4), new FeatureVersion(2, 7)))
.add(new JoinSpecDefinition(new FeatureVersion(0, 5), new FeatureVersion(2, 8)));
registerKnownFeature(JOIN_VERSIONS);

@@ -17,2 +17,3 @@ import { DocumentNode, GraphQLError } from "graphql";

'https://specs.apollo.dev/join/v0.4',
'https://specs.apollo.dev/join/v0.5',
'https://specs.apollo.dev/tag/v0.1',

@@ -25,2 +26,22 @@ 'https://specs.apollo.dev/tag/v0.2',

export const ROUTER_SUPPORTED_SUPERGRAPH_FEATURES = new Set([
'https://specs.apollo.dev/core/v0.1',
'https://specs.apollo.dev/core/v0.2',
'https://specs.apollo.dev/join/v0.1',
'https://specs.apollo.dev/join/v0.2',
'https://specs.apollo.dev/join/v0.3',
'https://specs.apollo.dev/join/v0.4',
'https://specs.apollo.dev/join/v0.5',
'https://specs.apollo.dev/tag/v0.1',
'https://specs.apollo.dev/tag/v0.2',
'https://specs.apollo.dev/tag/v0.3',
'https://specs.apollo.dev/inaccessible/v0.1',
'https://specs.apollo.dev/inaccessible/v0.2',
'https://specs.apollo.dev/authenticated/v0.1',
'https://specs.apollo.dev/requiresScopes/v0.1',
'https://specs.apollo.dev/policy/v0.1',
'https://specs.apollo.dev/source/v0.1',
'https://specs.apollo.dev/context/v0.1',
]);
const coreVersionZeroDotOneUrl = FeatureUrl.parse('https://specs.apollo.dev/core/v0.1');

@@ -89,2 +110,3 @@

private _subgraphs?: Subgraphs;
private _subgraphNameToGraphEnumValue?: Map<string, string>;

@@ -120,2 +142,5 @@ constructor(

static buildForTests(supergraphSdl: string | DocumentNode, validateSupergraph?: boolean) {
return Supergraph.build(supergraphSdl, { supportedFeatures: ROUTER_SUPPORTED_SUPERGRAPH_FEATURES, validateSupergraph });
}
/**

@@ -136,3 +161,5 @@ * The list of names/urls of the subgraphs contained in this subgraph.

// can leave that to "some day, maybe".
this._subgraphs = extractSubgraphsFromSupergraph(this.schema, this.shouldValidate);
const extractionResults = extractSubgraphsFromSupergraph(this.schema, this.shouldValidate);
this._subgraphs = extractionResults[0];
this._subgraphNameToGraphEnumValue = extractionResults[1];
}

@@ -142,2 +169,11 @@ return this._subgraphs;

subgraphNameToGraphEnumValue(): Map<string, string> {
if (!this._subgraphNameToGraphEnumValue) {
const extractionResults = extractSubgraphsFromSupergraph(this.schema, this.shouldValidate);
this._subgraphs = extractionResults[0];
this._subgraphNameToGraphEnumValue = extractionResults[1];
}
return new Map([...this._subgraphNameToGraphEnumValue]);
}
apiSchema(): Schema {

@@ -144,0 +180,0 @@ return this.schema.toAPISchema();

@@ -444,1 +444,39 @@ /**

}
export function mergeMapOrNull<K,V>(m1: Map<K, V> | null, m2: Map<K, V> | null): Map<K, V> | null {
if (!m1) {
return m2;
}
if (!m2) {
return m1;
}
return new Map<K, V>([...m1, ...m2]);
}
export function composeSets<T>(s1: Set<T> | null, s2: Set<T> | null): Set<T> | null {
if (!s1 && !s2) {
return null;
}
const result = new Set<T>();
s1?.forEach(v => result.add(v));
s2?.forEach(v => result.add(v));
return result;
}
export function setsEqual<T>(s1: Set<T> | null, s2: Set<T> | null): boolean {
if (s1 === s2) {
return true;
}
if (!s1 && !s2) {
return true;
}
if (!s1 || !s2 || s1.size !== s2.size) {
return false;
}
for (const key of s1) {
if (!s2.has(key)) {
return false;
}
}
return true;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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