Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
298 changes: 149 additions & 149 deletions composition-go/index.global.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions composition/src/ast/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,7 @@ export type ObjectTypeNode = ObjectTypeDefinitionNode | ObjectTypeExtensionNode;
export type ScalarTypeNode = ScalarTypeDefinitionNode | ScalarTypeExtensionNode;
export type SchemaNode = SchemaDefinitionNode | SchemaExtensionNode;
export type UnionTypeNode = UnionTypeDefinitionNode | UnionTypeExtensionNode;

export type InterfaceNodeKind = Kind.INTERFACE_TYPE_DEFINITION | Kind.INTERFACE_TYPE_EXTENSION;
export type ObjectNodeKind = Kind.OBJECT_TYPE_DEFINITION | Kind.OBJECT_TYPE_EXTENSION;
export type CompositeOutputNodeKind = InterfaceNodeKind | ObjectNodeKind;
41 changes: 21 additions & 20 deletions composition/src/schema-building/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export enum ExtensionType {

export type EnumDefinitionData = {
appearances: number;
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
enumValueDataByValueName: Map<string, EnumValueData>;
extensionType: ExtensionType;
Expand All @@ -66,21 +66,21 @@ export type EnumDefinitionData = {
name: string;
node: MutableEnumNode;
persistedDirectivesData: PersistedDirectivesData;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

export type EnumValueData = {
appearances: number;
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
federatedCoords: string;
kind: Kind.ENUM_VALUE_DEFINITION;
name: string;
node: MutableEnumValueNode;
parentTypeName: string;
persistedDirectivesData: PersistedDirectivesData;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

Expand All @@ -96,7 +96,7 @@ export type ExternalFieldData = {

export type FieldData = {
argumentDataByName: Map<string, InputValueData>;
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
externalFieldDataBySubgraphName: Map<string, ExternalFieldData>;
federatedCoords: string;
Expand All @@ -118,7 +118,7 @@ export type FieldData = {
};

export type InputObjectDefinitionData = {
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
extensionType: ExtensionType;
inputValueDataByName: Map<string, InputValueData>;
Expand All @@ -127,12 +127,12 @@ export type InputObjectDefinitionData = {
name: string;
node: MutableInputObjectNode;
persistedDirectivesData: PersistedDirectivesData;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

export type InputValueData = {
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
federatedCoords: string;
includeDefaultValue: boolean;
Expand All @@ -146,16 +146,16 @@ export type InputValueData = {
originalParentTypeName: string;
persistedDirectivesData: PersistedDirectivesData;
renamedParentTypeName: string;
requiredSubgraphNames: Set<string>;
subgraphNames: Set<string>;
requiredSubgraphNames: Set<SubgraphName>;
subgraphNames: Set<SubgraphName>;
type: MutableTypeNode;
defaultValue?: ConstValueNode;
description?: StringValueNode;
fieldName?: string;
};

export type InterfaceDefinitionData = {
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
extensionType: ExtensionType;
fieldDataByName: Map<string, FieldData>;
Expand All @@ -166,12 +166,13 @@ export type InterfaceDefinitionData = {
name: string;
node: MutableInterfaceNode;
persistedDirectivesData: PersistedDirectivesData;
subgraphNames: Set<string>;
requireFetchReasonsFieldNames: Set<FieldName>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

export type ObjectDefinitionData = {
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
extensionType: ExtensionType;
fieldDataByName: Map<FieldName, FieldData>;
Expand All @@ -185,7 +186,7 @@ export type ObjectDefinitionData = {
persistedDirectivesData: PersistedDirectivesData;
renamedTypeName: string;
requireFetchReasonsFieldNames: Set<FieldName>;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

Expand All @@ -194,7 +195,7 @@ export type PersistedDirectiveDefinitionData = {
executableLocations: Set<string>;
name: string;
repeatable: boolean;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

Expand All @@ -213,7 +214,7 @@ export type ScalarDefinitionData = {
name: string;
node: MutableScalarNode;
persistedDirectivesData: PersistedDirectivesData;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

Expand All @@ -226,15 +227,15 @@ export type SchemaData = {
};

export type UnionDefinitionData = {
configureDescriptionDataBySubgraphName: Map<string, ConfigureDescriptionData>;
configureDescriptionDataBySubgraphName: Map<SubgraphName, ConfigureDescriptionData>;
directivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>;
extensionType: ExtensionType;
kind: Kind.UNION_TYPE_DEFINITION;
name: string;
memberByMemberTypeName: Map<string, NamedTypeNode>;
node: MutableUnionNode;
persistedDirectivesData: PersistedDirectivesData;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
description?: StringValueNode;
};

Expand Down Expand Up @@ -269,7 +270,7 @@ export type EntityData = {
documentNodeByKeyFieldSet: Map<string, DocumentNode>;
keyFieldSets: Set<string>;
keyFieldSetDatasBySubgraphName: Map<string, Map<string, KeyFieldSetData>>;
subgraphNames: Set<string>;
subgraphNames: Set<SubgraphName>;
typeName: string;
};

Expand Down Expand Up @@ -320,7 +321,7 @@ export type ConditionalFieldData = {

export type EntityInterfaceFederationData = {
concreteTypeNames: Set<string>;
fieldDatasBySubgraphName: Map<string, Array<SimpleFieldData>>;
fieldDatasBySubgraphName: Map<SubgraphName, Array<SimpleFieldData>>;
interfaceFieldNames: Set<string>;
interfaceObjectFieldNames: Set<string>;
interfaceObjectSubgraphs: Set<string>;
Expand Down
1 change: 1 addition & 0 deletions composition/src/v1/federation/federation-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ export class FederationFactory {
kind: sourceData.kind,
name: stringToNameNode(sourceData.name),
},
requireFetchReasonsFieldNames: new Set<FieldName>(),
subgraphNames: new Set(sourceData.subgraphNames),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ export const REDIS_SUBSCRIBE_DEFINITION_DATA: DirectiveDefinitionData = {
export const REQUIRE_FETCH_REASONS_DEFINITION_DATA: DirectiveDefinitionData = {
argumentTypeNodeByArgumentName: new Map<string, ArgumentData>(),
isRepeatable: true,
locations: new Set<string>([FIELD_DEFINITION_UPPER, OBJECT_UPPER]),
locations: new Set<string>([FIELD_DEFINITION_UPPER, INTERFACE_UPPER, OBJECT_UPPER]),
name: REQUIRE_FETCH_REASONS,
node: REQUIRE_FETCH_REASONS_DEFINITION,
optionalArgumentNames: new Set<string>(),
Expand Down
66 changes: 41 additions & 25 deletions composition/src/v1/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ import {
import {
addScopes,
fieldDatasToSimpleFieldDatas,
isCompositeOutputNodeKind,
isNodeKindObject,
isObjectDefinitionData,
kindToConvertedTypeString,
mapToArrayOfValues,
newAuthorizationData,
Expand Down Expand Up @@ -375,7 +377,7 @@ import {
import { newConfigurationData, newFieldSetConditionData } from '../../router-configuration/utils';
import { ImplementationErrors, InvalidFieldImplementation } from '../../utils/types';
import { FieldName, SubgraphName } from '../../types/types';
import { ValidateOneOfDirectiveParams } from './params';
import { HandleFieldInheritableDirectivesParams, ValidateOneOfDirectiveParams } from './params';

export function normalizeSubgraphFromString(subgraphSDL: string, noLocation = true): NormalizationResult {
const { error, documentNode } = safeParse(subgraphSDL, noLocation);
Expand Down Expand Up @@ -405,9 +407,9 @@ export class NormalizationFactory {
definedDirectiveNames = new Set<string>();
directiveDefinitionByDirectiveName = new Map<string, DirectiveDefinitionNode>();
directiveDefinitionDataByDirectiveName = initializeDirectiveDefinitionDatas();
doesParentObjectRequireFetchReasons = false;
doesParentRequireFetchReasons = false;
edfsDirectiveReferences = new Set<string>();
errors: Error[] = [];
errors = new Array<Error>();
entityDataByTypeName = new Map<string, EntityData>();
entityInterfaceDataByTypeName = new Map<string, EntityInterfaceSubgraphData>();
eventsConfigurations = new Map<string, EventConfiguration[]>();
Expand Down Expand Up @@ -438,7 +440,7 @@ export class NormalizationFactory {
referencedDirectiveNames = new Set<string>();
referencedTypeNames = new Set<string>();
renamedParentTypeName = '';
subgraphName: string;
subgraphName: SubgraphName;
unvalidatedExternalFieldCoords = new Set<string>();
usesEdfsNatsStreamConfiguration: boolean = false;
warnings: Array<Warning> = [];
Expand Down Expand Up @@ -572,23 +574,33 @@ export class NormalizationFactory {
}
}

addInheritedDirectivesToFieldData(
fieldDirectivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>,
inheritedDirectiveNames: Set<string>,
) {
if (this.isParentObjectExternal && !fieldDirectivesByDirectiveName.has(EXTERNAL)) {
fieldDirectivesByDirectiveName.set(EXTERNAL, [generateSimpleDirective(EXTERNAL)]);
handleFieldInheritableDirectives({
directivesByDirectiveName,
fieldName,
inheritedDirectiveNames,
parentData,
}: HandleFieldInheritableDirectivesParams) {
if (this.doesParentRequireFetchReasons && !directivesByDirectiveName.has(REQUIRE_FETCH_REASONS)) {
directivesByDirectiveName.set(REQUIRE_FETCH_REASONS, [generateSimpleDirective(REQUIRE_FETCH_REASONS)]);
inheritedDirectiveNames.add(REQUIRE_FETCH_REASONS);
}
if (this.doesParentRequireFetchReasons || directivesByDirectiveName.has(REQUIRE_FETCH_REASONS)) {
parentData.requireFetchReasonsFieldNames.add(fieldName);
}
if (!isObjectDefinitionData(parentData)) {
Comment thread
Aenimus marked this conversation as resolved.
return;
}
if (this.isParentObjectExternal && !directivesByDirectiveName.has(EXTERNAL)) {
directivesByDirectiveName.set(EXTERNAL, [generateSimpleDirective(EXTERNAL)]);
inheritedDirectiveNames.add(EXTERNAL);
}
if (this.doesParentObjectRequireFetchReasons && !fieldDirectivesByDirectiveName.has(REQUIRE_FETCH_REASONS)) {
fieldDirectivesByDirectiveName.set(REQUIRE_FETCH_REASONS, [generateSimpleDirective(REQUIRE_FETCH_REASONS)]);
inheritedDirectiveNames.add(REQUIRE_FETCH_REASONS);
if (directivesByDirectiveName.has(EXTERNAL)) {
this.unvalidatedExternalFieldCoords.add(`${parentData.name}.${fieldName}`);
}
if (this.isParentObjectShareable && !fieldDirectivesByDirectiveName.has(SHAREABLE)) {
fieldDirectivesByDirectiveName.set(SHAREABLE, [generateSimpleDirective(SHAREABLE)]);
if (this.isParentObjectShareable && !directivesByDirectiveName.has(SHAREABLE)) {
directivesByDirectiveName.set(SHAREABLE, [generateSimpleDirective(SHAREABLE)]);
inheritedDirectiveNames.add(SHAREABLE);
}
return fieldDirectivesByDirectiveName;
}

extractDirectives(
Expand All @@ -612,11 +624,14 @@ export class NormalizationFactory {
} else {
getValueOrDefault(directivesByDirectiveName, directiveName, () => []).push(directiveNode);
}
if (!isCompositeOutputNodeKind(node.kind)) {
continue;
}
this.doesParentRequireFetchReasons ||= directiveName === REQUIRE_FETCH_REASONS;
if (!isNodeKindObject(node.kind)) {
continue;
}
this.isParentObjectExternal ||= directiveName === EXTERNAL;
this.doesParentObjectRequireFetchReasons ||= directiveName === REQUIRE_FETCH_REASONS;
this.isParentObjectShareable ||= directiveName === SHAREABLE;
}
return directivesByDirectiveName;
Expand Down Expand Up @@ -1019,7 +1034,7 @@ export class NormalizationFactory {
executableLocations,
name,
repeatable: node.repeatable,
subgraphNames: new Set<string>([this.subgraphName]),
subgraphNames: new Set<SubgraphName>([this.subgraphName]),
description: formatDescription(node.description),
});
}
Expand Down Expand Up @@ -1159,7 +1174,7 @@ export class NormalizationFactory {
originalParentTypeName: this.originalParentTypeName,
persistedDirectivesData: newPersistedDirectivesData(),
renamedParentTypeName: parentTypeName,
subgraphNames: new Set<string>([this.subgraphName]),
subgraphNames: new Set<SubgraphName>([this.subgraphName]),
type: getMutableTypeNode(node.type, fieldCoords, this.errors),
directivesByDirectiveName,
description: formatDescription(node.description),
Expand Down Expand Up @@ -1216,8 +1231,8 @@ export class NormalizationFactory {
originalParentTypeName: originalParentTypeName,
persistedDirectivesData: newPersistedDirectivesData(),
renamedParentTypeName: federatedParentTypeName,
requiredSubgraphNames: new Set<string>(isTypeRequired(node.type) ? [this.subgraphName] : []),
subgraphNames: new Set<string>([this.subgraphName]),
requiredSubgraphNames: new Set<SubgraphName>(isTypeRequired(node.type) ? [this.subgraphName] : []),
subgraphNames: new Set<SubgraphName>([this.subgraphName]),
type: getMutableTypeNode(node.type, originalParentTypeName, this.errors),
defaultValue: node.defaultValue, // TODO validate
description: formatDescription(node.description),
Expand Down Expand Up @@ -1266,7 +1281,8 @@ export class NormalizationFactory {
name: typeName,
node: getMutableInterfaceNode(node.name),
persistedDirectivesData: newPersistedDirectivesData(),
subgraphNames: new Set<string>([this.subgraphName]),
requireFetchReasonsFieldNames: new Set<FieldName>(),
subgraphNames: new Set<SubgraphName>([this.subgraphName]),
description: formatDescription('description' in node ? node.description : undefined),
};
this.extractConfigureDescriptionsData(newParentData);
Expand Down Expand Up @@ -1345,7 +1361,7 @@ export class NormalizationFactory {
persistedDirectivesData: newPersistedDirectivesData(),
requireFetchReasonsFieldNames: new Set<FieldName>(),
renamedTypeName: this.getRenamedRootTypeName(typeName),
subgraphNames: new Set<string>([this.subgraphName]),
subgraphNames: new Set<SubgraphName>([this.subgraphName]),
description: formatDescription('description' in node ? node.description : undefined),
};
this.extractConfigureDescriptionsData(newParentData);
Expand Down Expand Up @@ -1433,7 +1449,7 @@ export class NormalizationFactory {
name: typeName,
node: getMutableInputObjectNode(node.name),
persistedDirectivesData: newPersistedDirectivesData(),
subgraphNames: new Set<string>([this.subgraphName]),
subgraphNames: new Set<SubgraphName>([this.subgraphName]),
description: formatDescription('description' in node ? node.description : undefined),
};
this.extractConfigureDescriptionsData(newParentData);
Expand Down Expand Up @@ -3617,7 +3633,7 @@ export class NormalizationFactory {
if (parentData.fieldDataByName.size < 1 && !isNodeQuery(parentTypeName, operationTypeNode)) {
this.errors.push(noFieldDefinitionsError(kindToNodeType(parentData.kind), parentTypeName));
}
if (isObject && parentData.requireFetchReasonsFieldNames.size > 0) {
if (parentData.requireFetchReasonsFieldNames.size > 0) {
configurationData.requireFetchReasonsFieldNames = [...parentData.requireFetchReasonsFieldNames];
}
break;
Expand Down
12 changes: 10 additions & 2 deletions composition/src/v1/normalization/params.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { FieldName } from '../../types/types';
import { InputObjectDefinitionData } from '../../schema-building/types';
import type { DirectiveName, FieldName } from '../../types/types';
import type { CompositeOutputData, InputObjectDefinitionData } from '../../schema-building/types';
import type { ConstDirectiveNode } from 'graphql';

export type ValidateOneOfDirectiveParams = {
data: InputObjectDefinitionData;
requiredFieldNames: Set<FieldName>;
};

export type HandleFieldInheritableDirectivesParams = {
directivesByDirectiveName: Map<DirectiveName, ConstDirectiveNode[]>;
fieldName: FieldName;
inheritedDirectiveNames: Set<DirectiveName>;
parentData: CompositeOutputData;
};
Loading
Loading