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.6.3 to 2.7.0

dist/specs/sourceSpec.d.ts

19

dist/error.d.ts

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

OVERRIDE_ON_INTERFACE: ErrorCodeDefinition;
OVERRIDE_LABEL_INVALID: ErrorCodeDefinition;
UNSUPPORTED_FEATURE: ErrorCodeDefinition;

@@ -126,2 +127,20 @@ INVALID_FEDERATION_SUPERGRAPH: ErrorCodeDefinition;

INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE: 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;
};

@@ -128,0 +147,0 @@ export declare const REMOVED_ERRORS: string[][];

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

const OVERRIDE_ON_INTERFACE = makeCodeDefinition('OVERRIDE_ON_INTERFACE', 'The @override directive cannot be used on the fields of an interface type.', { addedIn: '2.3.0' });
const OVERRIDE_LABEL_INVALID = makeCodeDefinition('OVERRIDE_LABEL_INVALID', 'The @override directive `label` argument must match the pattern /^[a-zA-Z][a-zA-Z0-9_\-:./]*$/ or /^percent\((\d{1,2}(\.\d{1,8})?|100)\)$/', { addedIn: '2.7.0' });
const UNSUPPORTED_FEATURE = makeCodeDefinition('UNSUPPORTED_FEATURE', 'Indicates an error due to feature currently unsupported by federation.', { addedIn: '2.1.0' });

@@ -206,2 +207,20 @@ const INVALID_FEDERATION_SUPERGRAPH = makeCodeDefinition('INVALID_FEDERATION_SUPERGRAPH', 'Indicates that a schema provided for an Apollo Federation supergraph is not a valid supergraph schema.', { 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_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' });
exports.ERROR_CATEGORIES = {

@@ -283,2 +302,3 @@ DIRECTIVE_FIELDS_MISSING_EXTERNAL,

OVERRIDE_ON_INTERFACE,
OVERRIDE_LABEL_INVALID,
UNSUPPORTED_FEATURE,

@@ -294,2 +314,20 @@ INVALID_FEDERATION_SUPERGRAPH,

INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE,
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,
};

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

15

dist/extractSubgraphsFromSupergraph.js

@@ -289,8 +289,8 @@ "use strict";

for (const application of fieldApplications) {
const args = application.arguments();
if (!args.graph) {
const joinFieldArgs = application.arguments();
if (!joinFieldArgs.graph) {
continue;
}
const { type: subgraphType, subgraph } = subgraphsInfo.get(args.graph);
addSubgraphField({ field, type: subgraphType, subgraph, isShareable, joinFieldArgs: args });
const { type: subgraphType, subgraph } = subgraphsInfo.get(joinFieldArgs.graph);
addSubgraphField({ field, type: subgraphType, subgraph, isShareable, joinFieldArgs });
}

@@ -429,7 +429,10 @@ }

const usedOverridden = !!(joinFieldArgs === null || joinFieldArgs === void 0 ? void 0 : joinFieldArgs.usedOverridden);
if (usedOverridden) {
if (usedOverridden && !(joinFieldArgs === null || joinFieldArgs === void 0 ? void 0 : joinFieldArgs.overrideLabel)) {
subgraphField.applyDirective(subgraph.metadata().externalDirective(), { 'reason': '[overridden]' });
}
if (joinFieldArgs === null || joinFieldArgs === void 0 ? void 0 : joinFieldArgs.override) {
subgraphField.applyDirective(subgraph.metadata().overrideDirective(), { 'from': joinFieldArgs.override });
subgraphField.applyDirective(subgraph.metadata().overrideDirective(), {
from: joinFieldArgs.override,
...(joinFieldArgs.overrideLabel ? { label: joinFieldArgs.overrideLabel } : {})
});
}

@@ -436,0 +439,0 @@ if (isShareable && !external && !usedOverridden) {

9

dist/federation.d.ts

@@ -7,2 +7,3 @@ 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 = "_";

@@ -43,2 +44,3 @@ export declare const FEDERATION_UNNAMED_SUBGRAPH_NAME = "<unnamed>";

from: string;
label?: string;
}>;

@@ -71,2 +73,5 @@ extendsDirective(): DirectiveDefinition<Record<string, never>>;

}>;
sourceAPIDirective(): Post20FederationDirectiveDefinition<SourceAPIDirectiveArgs>;
sourceTypeDirective(): Post20FederationDirectiveDefinition<SourceTypeDirectiveArgs>;
sourceFieldDirective(): Post20FederationDirectiveDefinition<SourceFieldDirectiveArgs>;
allFederationDirectives(): DirectiveDefinition[];

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

export declare function setSchemaAsFed2Subgraph(schema: Schema): void;
export declare const FEDERATION2_LINK_WITH_FULL_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.6\", 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.6\", 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.7\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\", \"@authenticated\", \"@requiresScopes\", \"@policy\", \"@sourceAPI\", \"@sourceType\", \"@sourceField\"])";
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 function asFed2SubgraphDocument(document: DocumentNode, options?: {

@@ -111,0 +116,0 @@ addAsSchemaExtension?: boolean;

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

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

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

__exportStar(require("./specs/policySpec"), 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);

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

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

@@ -119,2 +120,3 @@ protected directiveNameInSchema(schema: Schema, directiveName: string): string | undefined;

constructor(identity: string, name: string, version: FeatureVersion, element?: string | undefined);
static maybeParse(input: string, node?: ASTNode): FeatureUrl | undefined;
static parse(input: string, node?: ASTNode): FeatureUrl;

@@ -121,0 +123,0 @@ static decode(node: StringValueNode): FeatureUrl;

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

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

@@ -509,2 +512,10 @@ const feature = this.featureInSchema(schema);

}
static maybeParse(input, node) {
try {
return FeatureUrl.parse(input, node);
}
catch (err) {
return undefined;
}
}
static parse(input, node) {

@@ -511,0 +522,0 @@ const url = new url_1.URL(input);

@@ -20,3 +20,6 @@ import { FeatureDefinition, FeatureDefinitions, FeatureVersion } from "./coreSpec";

REQUIRES_SCOPES = "requiresScopes",
POLICY = "policy"
POLICY = "policy",
SOURCE_API = "sourceAPI",
SOURCE_TYPE = "sourceType",
SOURCE_FIELD = "sourceField"
}

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

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

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

@@ -38,2 +39,5 @@ var FederationTypeName;

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

@@ -103,7 +107,19 @@ const fieldSetTypeSpec = (0, directiveAndTypeSpecification_1.createScalarTypeSpecification)({ name: FederationTypeName.FIELD_SET });

this.registerSubFeature(inaccessibleSpec_1.INACCESSIBLE_VERSIONS.getMinimumRequiredVersion(version));
this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
name: FederationDirectiveName.OVERRIDE,
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: [{ name: 'from', type: (schema) => new definitions_1.NonNullType(schema.stringType()) }],
}));
if (version >= (new coreSpec_1.FeatureVersion(2, 7))) {
this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
name: FederationDirectiveName.OVERRIDE,
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: [
{ name: 'from', type: (schema) => new definitions_1.NonNullType(schema.stringType()) },
{ name: 'label', type: (schema) => schema.stringType() },
],
}));
}
else {
this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
name: FederationDirectiveName.OVERRIDE,
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: [{ name: 'from', type: (schema) => new definitions_1.NonNullType(schema.stringType()) }],
}));
}
if (version.gte(new coreSpec_1.FeatureVersion(2, 1))) {

@@ -131,2 +147,5 @@ this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({

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

@@ -142,4 +161,5 @@ }

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

@@ -21,3 +21,9 @@ import { GraphQLError } from 'graphql';

usedOverridden?: boolean;
overrideLabel?: string;
};
export type JoinDirectiveArguments = {
graphs: string[];
name: string;
args?: Record<string, any>;
};
export declare class JoinSpecDefinition extends FeatureDefinition {

@@ -35,2 +41,3 @@ constructor(version: FeatureVersion, minimumFederationVersion?: FeatureVersion);

}>;
directiveDirective(schema: Schema): DirectiveDefinition<JoinDirectiveArguments>;
typeDirective(schema: Schema): DirectiveDefinition<JoinTypeDirectiveArguments>;

@@ -37,0 +44,0 @@ implementsDirective(schema: Schema): DirectiveDefinition<{

@@ -76,2 +76,10 @@ "use strict";

}
if (this.version.gte(new coreSpec_1.FeatureVersion(0, 4))) {
const joinDirective = this.addDirective(schema, 'directive').addLocations(graphql_1.DirectiveLocation.SCHEMA, graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.INTERFACE, graphql_1.DirectiveLocation.FIELD_DEFINITION);
joinDirective.repeatable = true;
joinDirective.addArgument('graphs', new definitions_1.ListType(new definitions_1.NonNullType(graphEnum)));
joinDirective.addArgument('name', new definitions_1.NonNullType(schema.stringType()));
joinDirective.addArgument('args', this.addScalarType(schema, 'DirectiveArguments'));
joinField.addArgument('overrideLabel', schema.stringType());
}
if (this.isV01()) {

@@ -133,2 +141,5 @@ const joinOwner = this.addDirective(schema, 'owner').addLocations(graphql_1.DirectiveLocation.OBJECT);

}
directiveDirective(schema) {
return this.directive(schema, 'directive');
}
typeDirective(schema) {

@@ -160,4 +171,5 @@ return this.directive(schema, 'type');

.add(new JoinSpecDefinition(new coreSpec_1.FeatureVersion(0, 2)))
.add(new JoinSpecDefinition(new coreSpec_1.FeatureVersion(0, 3), new coreSpec_1.FeatureVersion(2, 0)));
.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)));
(0, knownCoreFeatures_1.registerKnownFeature)(exports.JOIN_VERSIONS);
//# sourceMappingURL=joinSpec.js.map

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

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

@@ -18,0 +19,0 @@ 'https://specs.apollo.dev/tag/v0.2',

{
"name": "@apollo/federation-internals",
"version": "2.6.3",
"version": "2.7.0",
"description": "Apollo Federation internal utilities",

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

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

const OVERRIDE_LABEL_INVALID = makeCodeDefinition(
'OVERRIDE_LABEL_INVALID',
'The @override directive `label` argument must match the pattern /^[a-zA-Z][a-zA-Z0-9_\-:./]*$/ or /^percent\((\d{1,2}(\.\d{1,8})?|100)\)$/',
{ addedIn: '2.7.0' },
);
const UNSUPPORTED_FEATURE = makeCodeDefinition(

@@ -559,3 +565,109 @@ 'UNSUPPORTED_FEATURE',

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' },
);
export const ERROR_CATEGORIES = {

@@ -638,2 +750,3 @@ DIRECTIVE_FIELDS_MISSING_EXTERNAL,

OVERRIDE_ON_INTERFACE,
OVERRIDE_LABEL_INVALID,
UNSUPPORTED_FEATURE,

@@ -649,2 +762,21 @@ INVALID_FEDERATION_SUPERGRAPH,

INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE,
// Errors related to @sourceAPI, @sourceType, and/or @sourceField
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,
};

@@ -651,0 +783,0 @@

@@ -421,11 +421,11 @@ import {

for (const application of fieldApplications) {
const args = application.arguments();
const joinFieldArgs = application.arguments();
// We use a @join__field with no graph to indicates when a field in the supergraph does not come
// directly from any subgraph and there is thus nothing to do to "extract" it.
if (!args.graph) {
if (!joinFieldArgs.graph) {
continue;
}
const { type: subgraphType, subgraph } = subgraphsInfo.get(args.graph)!;
addSubgraphField({ field, type: subgraphType, subgraph, isShareable, joinFieldArgs: args});
const { type: subgraphType, subgraph } = subgraphsInfo.get(joinFieldArgs.graph)!;
addSubgraphField({ field, type: subgraphType, subgraph, isShareable, joinFieldArgs });
}

@@ -619,7 +619,10 @@ }

const usedOverridden = !!joinFieldArgs?.usedOverridden;
if (usedOverridden) {
if (usedOverridden && !joinFieldArgs?.overrideLabel) {
subgraphField.applyDirective(subgraph.metadata().externalDirective(), {'reason': '[overridden]'});
}
if (joinFieldArgs?.override) {
subgraphField.applyDirective(subgraph.metadata().overrideDirective(), {'from': joinFieldArgs.override});
subgraphField.applyDirective(subgraph.metadata().overrideDirective(), {
from: joinFieldArgs.override,
...(joinFieldArgs.overrideLabel ? { label: joinFieldArgs.overrideLabel } : {})
});
}

@@ -626,0 +629,0 @@ if (isShareable && !external && !usedOverridden) {

@@ -26,1 +26,2 @@ export * from './definitions';

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

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

import { GraphQLError } from "graphql";
import { Schema } from "./definitions";
import { FeatureDefinition, FeatureDefinitions, FeatureUrl } from "./specs/coreSpec";
const registeredFeatures: Map<string, FeatureDefinitions> = new Map();
const registeredFeatures = new Map<string, FeatureDefinitions>();

@@ -15,2 +17,15 @@ export function registerKnownFeature(definitions: FeatureDefinitions) {

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 {

@@ -754,3 +759,10 @@ const feature = this.featureInSchema(schema);

/// Parse a spec URL or throw
public static maybeParse(input: string, node?: ASTNode): FeatureUrl | undefined {
try {
return FeatureUrl.parse(input, node);
} catch (err) {
return undefined;
}
}
/// Parse a spec URL or throw
public static parse(input: string, node?: ASTNode): FeatureUrl {

@@ -757,0 +769,0 @@ const url = new URL(input)

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

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

@@ -44,2 +45,5 @@ export const federationIdentity = 'https://specs.apollo.dev/federation';

POLICY = 'policy',
SOURCE_API = 'sourceAPI',
SOURCE_TYPE = 'sourceType',
SOURCE_FIELD = 'sourceField',
}

@@ -129,7 +133,18 @@

this.registerDirective(createDirectiveSpecification({
name: FederationDirectiveName.OVERRIDE,
locations: [DirectiveLocation.FIELD_DEFINITION],
args: [{ name: 'from', type: (schema) => new NonNullType(schema.stringType()) }],
}));
if (version >= (new FeatureVersion(2, 7))) {
this.registerDirective(createDirectiveSpecification({
name: FederationDirectiveName.OVERRIDE,
locations: [DirectiveLocation.FIELD_DEFINITION],
args: [
{ name: 'from', type: (schema) => new NonNullType(schema.stringType()) },
{ name: 'label', type: (schema) => schema.stringType() },
],
}));
} else {
this.registerDirective(createDirectiveSpecification({
name: FederationDirectiveName.OVERRIDE,
locations: [DirectiveLocation.FIELD_DEFINITION],
args: [{ name: 'from', type: (schema) => new NonNullType(schema.stringType()) }],
}));
}

@@ -161,2 +176,6 @@ if (version.gte(new FeatureVersion(2, 1))) {

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

@@ -172,4 +191,5 @@ }

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

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

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

@@ -50,4 +51,11 @@ import { Subgraph, Subgraphs } from "../federation";

usedOverridden?: boolean,
overrideLabel?: string,
}
export type JoinDirectiveArguments = {
graphs: string[],
name: string,
args?: Record<string, any>,
};
export class JoinSpecDefinition extends FeatureDefinition {

@@ -131,2 +139,23 @@ constructor(version: FeatureVersion, minimumFederationVersion?: FeatureVersion) {

if (this.version.gte(new FeatureVersion(0, 4))) {
const joinDirective = this.addDirective(schema, 'directive').addLocations(
DirectiveLocation.SCHEMA,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.FIELD_DEFINITION,
);
joinDirective.repeatable = true;
// Note this 'graphs' argument is plural, since the same directive
// application can appear on the same schema element in multiple subgraphs.
// Repetition of a graph in this 'graphs' list is allowed, and corresponds
// to repeated application of the same directive in the same subgraph, which
// is allowed.
joinDirective.addArgument('graphs', new ListType(new NonNullType(graphEnum)));
joinDirective.addArgument('name', new NonNullType(schema.stringType()));
joinDirective.addArgument('args', this.addScalarType(schema, 'DirectiveArguments'));
//progressive override
joinField.addArgument('overrideLabel', schema.stringType());
}
if (this.isV01()) {

@@ -198,2 +227,6 @@ const joinOwner = this.addDirective(schema, 'owner').addLocations(DirectiveLocation.OBJECT);

directiveDirective(schema: Schema): DirectiveDefinition<JoinDirectiveArguments> {
return this.directive(schema, 'directive')!;
}
typeDirective(schema: Schema): DirectiveDefinition<JoinTypeDirectiveArguments> {

@@ -234,7 +267,9 @@ return this.directive(schema, 'type')!;

// - 0.3: adds the `isInterfaceObject` argument to `@join__type`, and make the `graph` in `@join__field` skippable.
// - 0.4: adds the optional `overrideLabel` argument to `@join_field` for progressive override.
export const JOIN_VERSIONS = new FeatureDefinitions<JoinSpecDefinition>(joinIdentity)
.add(new JoinSpecDefinition(new FeatureVersion(0, 1)))
.add(new JoinSpecDefinition(new FeatureVersion(0, 2)))
.add(new JoinSpecDefinition(new FeatureVersion(0, 3), new FeatureVersion(2, 0)));
.add(new JoinSpecDefinition(new FeatureVersion(0, 3), new FeatureVersion(2, 0)))
.add(new JoinSpecDefinition(new FeatureVersion(0, 4), new FeatureVersion(2, 7)));
registerKnownFeature(JOIN_VERSIONS);

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

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

@@ -18,0 +19,0 @@ 'https://specs.apollo.dev/tag/v0.2',

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 not supported yet

Sorry, the diff of this file is not supported yet

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