Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composition-go/index.global.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions composition/src/subgraph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
ParentDefinitionData,
PersistedDirectiveDefinitionData,
} from '../schema-building/types';
import { DirectiveName, TypeName } from '../types/types';
import { DirectiveName, FieldName, SubgraphName, TypeName } from '../types/types';
import { SchemaDefinitionNode, SchemaExtensionNode } from 'graphql/index';

export type Subgraph = {
definitions: DocumentNode;
name: string;
name: SubgraphName;
url: string;
};

Expand All @@ -20,6 +21,7 @@ export type SubgraphConfig = {
isVersionTwo: boolean;
parentDefinitionDataByTypeName: Map<TypeName, ParentDefinitionData>;
schema: GraphQLSchema;
schemaNode?: SchemaDefinitionNode | SchemaExtensionNode;
};

export type InternalSubgraph = {
Expand All @@ -29,12 +31,13 @@ export type InternalSubgraph = {
directiveDefinitionByName: Map<DirectiveName, DirectiveDefinitionNode>;
entityInterfaces: Map<string, EntityInterfaceSubgraphData>;
isVersionTwo: boolean;
keyFieldNamesByParentTypeName: Map<string, Set<string>>;
keyFieldNamesByParentTypeName: Map<TypeName, Set<string>>;
name: string;
operationTypes: Map<string, OperationTypeNode>;
overriddenFieldNamesByParentTypeName: Map<string, Set<string>>;
overriddenFieldNamesByParentTypeName: Map<TypeName, Set<FieldName>>;
parentDefinitionDataByTypeName: Map<string, ParentDefinitionData>;
persistedDirectiveDefinitionDataByDirectiveName: Map<DirectiveName, PersistedDirectiveDefinitionData>;
schema: GraphQLSchema;
schemaNode?: SchemaDefinitionNode | SchemaExtensionNode;
url: string;
};
52 changes: 35 additions & 17 deletions composition/src/v1/federation/federation-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class FederationFactory {
inaccessibleCoords = new Set<string>();
inaccessibleRequiredInputValueErrorByCoords = new Map<string, Error>();
internalGraph: Graph;
internalSubgraphBySubgraphName: Map<string, InternalSubgraph>;
internalSubgraphBySubgraphName: Map<SubgraphName, InternalSubgraph>;
invalidORScopesCoords = new Set<string>();
isMaxDepth = false;
isVersionTwo = false;
Expand Down Expand Up @@ -2884,14 +2884,23 @@ export class FederationFactory {
},
{ assumeValid: true, assumeValidSDL: true },
);
const subgraphConfigBySubgraphName = new Map<string, SubgraphConfig>();
for (const subgraph of this.internalSubgraphBySubgraphName.values()) {
subgraphConfigBySubgraphName.set(subgraph.name, {
configurationDataByTypeName: subgraph.configurationDataByTypeName,
directiveDefinitionByName: subgraph.directiveDefinitionByName,
isVersionTwo: subgraph.isVersionTwo,
parentDefinitionDataByTypeName: subgraph.parentDefinitionDataByTypeName,
schema: subgraph.schema,
const subgraphConfigBySubgraphName = new Map<SubgraphName, SubgraphConfig>();
for (const {
configurationDataByTypeName,
directiveDefinitionByName,
isVersionTwo,
name,
parentDefinitionDataByTypeName,
schema,
schemaNode,
} of this.internalSubgraphBySubgraphName.values()) {
subgraphConfigBySubgraphName.set(name, {
configurationDataByTypeName: configurationDataByTypeName,
directiveDefinitionByName: directiveDefinitionByName,
isVersionTwo: isVersionTwo,
parentDefinitionDataByTypeName: parentDefinitionDataByTypeName,
schema: schema,
schemaNode,
});
}
for (const authorizationData of this.authorizationDataByParentTypeName.values()) {
Expand Down Expand Up @@ -3177,14 +3186,23 @@ export class FederationFactory {
},
{ assumeValid: true, assumeValidSDL: true },
);
const subgraphConfigBySubgraphName = new Map<string, SubgraphConfig>();
for (const subgraph of this.internalSubgraphBySubgraphName.values()) {
subgraphConfigBySubgraphName.set(subgraph.name, {
configurationDataByTypeName: subgraph.configurationDataByTypeName,
directiveDefinitionByName: subgraph.directiveDefinitionByName,
isVersionTwo: subgraph.isVersionTwo,
parentDefinitionDataByTypeName: subgraph.parentDefinitionDataByTypeName,
schema: subgraph.schema,
const subgraphConfigBySubgraphName = new Map<SubgraphName, SubgraphConfig>();
for (const {
configurationDataByTypeName,
directiveDefinitionByName,
isVersionTwo,
name,
parentDefinitionDataByTypeName,
schema,
schemaNode,
} of this.internalSubgraphBySubgraphName.values()) {
subgraphConfigBySubgraphName.set(name, {
configurationDataByTypeName,
directiveDefinitionByName,
isVersionTwo,
parentDefinitionDataByTypeName,
schema,
schemaNode,
});
}
for (const authorizationData of this.authorizationDataByParentTypeName.values()) {
Expand Down
21 changes: 11 additions & 10 deletions composition/src/v1/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3804,19 +3804,19 @@ export class NormalizationFactory {
}

export function batchNormalize(subgraphs: Subgraph[]): BatchNormalizationResult {
const authorizationDataByParentTypeName = new Map<string, AuthorizationData>();
const concreteTypeNamesByAbstractTypeName = new Map<string, Set<string>>();
const entityDataByTypeName = new Map<string, EntityData>();
const internalSubgraphBySubgraphName = new Map<string, InternalSubgraph>();
const authorizationDataByParentTypeName = new Map<TypeName, AuthorizationData>();
const concreteTypeNamesByAbstractTypeName = new Map<TypeName, Set<TypeName>>();
const entityDataByTypeName = new Map<TypeName, EntityData>();
const internalSubgraphBySubgraphName = new Map<SubgraphName, InternalSubgraph>();
const allOverridesByTargetSubgraphName = new Map<string, Map<string, Set<string>>>();
const overrideSourceSubgraphNamesByFieldPath = new Map<string, string[]>();
const duplicateOverriddenFieldPaths = new Set<string>();
const parentDefinitionDataMapsBySubgraphName = new Map<string, Map<string, ParentDefinitionData>>();
const subgraphNames = new Set<string>();
const nonUniqueSubgraphNames = new Set<string>();
const invalidNameErrorMessages: string[] = [];
const parentDefinitionDataMapsBySubgraphName = new Map<SubgraphName, Map<TypeName, ParentDefinitionData>>();
const subgraphNames = new Set<SubgraphName>();
const nonUniqueSubgraphNames = new Set<SubgraphName>();
const invalidNameErrorMessages: Array<string> = [];
const invalidORScopesCoords = new Set<string>();
const fieldCoordsByNamedTypeName = new Map<string, Set<string>>();
const fieldCoordsByNamedTypeName = new Map<TypeName, Set<string>>();
const warnings: Array<Warning> = [];
const validationErrors: Array<Error> = [];
// Record the subgraph names first, so that subgraph references can be validated
Expand Down Expand Up @@ -3893,11 +3893,12 @@ export function batchNormalize(subgraphs: Subgraph[]): BatchNormalizationResult
keyFieldNamesByParentTypeName: normalizationResult.keyFieldNamesByParentTypeName,
name: subgraphName,
operationTypes: normalizationResult.operationTypes,
overriddenFieldNamesByParentTypeName: new Map<string, Set<string>>(),
overriddenFieldNamesByParentTypeName: new Map<TypeName, Set<FieldName>>(),
parentDefinitionDataByTypeName: normalizationResult.parentDefinitionDataByTypeName,
persistedDirectiveDefinitionDataByDirectiveName:
normalizationResult.persistedDirectiveDefinitionDataByDirectiveName,
schema: normalizationResult.schema,
schemaNode: normalizationResult.schemaNode,
url: subgraph.url,
});
}
Expand Down
21 changes: 20 additions & 1 deletion composition/tests/v1/federation-factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
SCALAR,
ScalarDefinitionData,
SHAREABLE,
stringToNamedTypeNode,
stringToNameNode,
Subgraph,
SubgraphName,
} from '../../src';
Expand Down Expand Up @@ -1023,7 +1025,10 @@ describe('FederationFactory tests', () => {
});

test('that renaming a root type also renames field return types of the same type #2.1', () => {
const { federatedGraphSchema } = federateSubgraphsSuccess([subgraphV, subgraphX], ROUTER_COMPATIBILITY_VERSION_ONE);
const { federatedGraphSchema, subgraphConfigBySubgraphName } = federateSubgraphsSuccess(
[subgraphV, subgraphX],
ROUTER_COMPATIBILITY_VERSION_ONE,
);
expect(schemaToSortedNormalizedString(federatedGraphSchema)).toStrictEqual(
normalizeString(
SCHEMA_QUERY_DEFINITION +
Expand All @@ -1047,6 +1052,20 @@ describe('FederationFactory tests', () => {
`,
),
);
const xConfig = subgraphConfigBySubgraphName.get(subgraphX.name);
expect(xConfig).toBeDefined();
expect(xConfig!.schemaNode).toStrictEqual({
description: undefined,
directives: [],
kind: Kind.SCHEMA_DEFINITION,
operationTypes: [
{
kind: Kind.OPERATION_TYPE_DEFINITION,
operation: 'query',
type: stringToNamedTypeNode('Queries'),
},
],
});
});

test('that renaming a root type also renames field return types of the same type #2.2', () => {
Expand Down
Loading