Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenimus committed Jan 23, 2025
1 parent 8aed067 commit f5a4ae4
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 358 deletions.
14 changes: 7 additions & 7 deletions composition-go/index.global.js

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions composition/src/federation/federation-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,20 +426,12 @@ export class FederationFactory {
configurationData.keys = implicitKeys;
return;
}
// TODO don't assess non-conditional keys
const existingKeyByFieldSet = new Map<string, RequiredFieldConfiguration>(
configurationData.keys.map((key) => [key.selectionSet, key]),
);
const existingKeys = new Set<string>(configurationData.keys.map((key) => key.selectionSet));
for (const implicitKey of implicitKeys) {
const existingKey = existingKeyByFieldSet.get(implicitKey.selectionSet);
if (existingKey) {
if (implicitKey.conditions?.length) {
existingKey.conditions = implicitKey.conditions;
}
if (existingKeys.has(implicitKey.selectionSet)) {
continue;
}
configurationData.keys.push(implicitKey);
// existingKeyByFieldSet.add(implicitKey.selectionSet);
}
}

Expand Down Expand Up @@ -489,7 +481,6 @@ export class FederationFactory {
continue;
}
configurationData.keys.push(implicitKey);
existingKeys.add(implicitKey.selectionSet);
}
}

Expand Down
25 changes: 16 additions & 9 deletions composition/src/federation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { getTypeNodeNamedTypeName, MutableFieldNode } from '../schema-building/a
import { BREAK, Kind, visit } from 'graphql/index';
import { BASE_SCALARS } from '../utils/constants';
import { isKindAbstract } from '../ast/utils';
import { getNormalizedFieldSet, KeyFieldSetData } from '../normalization/utils';
import { KeyFieldSetData } from '../normalization/utils';
import { GraphNode } from '../resolvability-graph/graph-nodes';
import {
concatenatePath,
Expand Down Expand Up @@ -163,6 +163,7 @@ export function validateImplicitKeyFieldSets({
subgraphName,
() => new Map<string, KeyFieldSetData>(),
);
// Only key targets that are resolvable in at least one subgraph are added to documentNodeByKeyFieldSet
for (const [keyFieldSet, documentNode] of entityData.documentNodeByKeyFieldSet) {
const keyFieldSetData = keyFieldSetDataByFieldSet.get(keyFieldSet);
if (keyFieldSetData) {
Expand Down Expand Up @@ -326,17 +327,17 @@ export function validateImplicitKeyFieldSets({
continue;
}
const validFieldSetConditions: Array<FieldSetConditionRouterData> = [];
for (const [preEntityPath, leafByPostEntityPath] of potentialFieldSetConditions) {
for (const [preEntityPath, fieldByPostEntityPath] of potentialFieldSetConditions) {
// It is not yet known whether the current path ia a super-condition or a sub-condition.
const superCondition = conditionByPreEntityPath.get(preEntityPath);
if (!superCondition) {
continue;
}
if (leafByPostEntityPath.size === conditionalFieldCount) {
if (fieldByPostEntityPath.size === conditionalFieldCount) {
validFieldSetConditions.push(newFieldSetConditionRouterData(superCondition));
continue;
}
for (const [otherPreEntityPath, otherLeafConditionByPostEntityPath] of potentialFieldSetConditions) {
for (const [otherPreEntityPath, otherFieldConditionByPostEntityPath] of potentialFieldSetConditions) {
// Do not compare a condition to itself.
if (preEntityPath === otherPreEntityPath) {
continue;
Expand All @@ -353,13 +354,13 @@ export function validateImplicitKeyFieldSets({
continue;
}
// Now that a sub-condition has been determined, add its own provided key fields to the super-condition.
for (const [postEntityPath, leafCondition] of otherLeafConditionByPostEntityPath) {
if (!leafByPostEntityPath.get(postEntityPath)) {
leafByPostEntityPath.set(postEntityPath, leafCondition);
for (const [postEntityPath, leafCondition] of otherFieldConditionByPostEntityPath) {
if (!fieldByPostEntityPath.get(postEntityPath)) {
fieldByPostEntityPath.set(postEntityPath, leafCondition);
}
}
// If all conditional key fields are provided, the implicit key is satisfied on the super-condition path.
if (leafByPostEntityPath.size === conditionalFieldCount) {
if (fieldByPostEntityPath.size === conditionalFieldCount) {
validFieldSetConditions.push(newFieldSetConditionData(superCondition));
break;
}
Expand All @@ -368,8 +369,14 @@ export function validateImplicitKeyFieldSets({
implicitKeys.push({
fieldName: '',
selectionSet: keyFieldSet,
disableEntityResolver: true,
...(validFieldSetConditions.length > 0 ? { conditions: validFieldSetConditions } : {}),
...(keyFieldSetData ? {} : { disableEntityResolver: true }),
});
keyFieldSetDataByFieldSet.set(keyFieldSet, {
documentNode,
isUnresolvable: true,
normalizedFieldSet: keyFieldSet,
rawFieldSet: keyFieldSet,
});
if (graphNode) {
graphNode.satisfiedFieldSets.add(keyFieldSet);
Expand Down
Loading

0 comments on commit f5a4ae4

Please sign in to comment.