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
82 changes: 41 additions & 41 deletions composition-go/index.global.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions composition/src/router-configuration/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FieldName, TypeName } from '../types/types';

export type NatsEventType = 'subscribe' | 'publish' | 'request';

export type KafkaEventType = 'subscribe' | 'publish';
Expand Down Expand Up @@ -72,21 +74,22 @@ export type FieldSetConditionDataParams = {
};

export type RequiredFieldConfiguration = {
fieldName: string;
fieldName: FieldName;
selectionSet: string;
conditions?: Array<FieldSetConditionData>;
disableEntityResolver?: boolean;
};

export type ConfigurationData = {
fieldNames: Set<string>;
fieldNames: Set<FieldName>;
isRootNode: boolean;
typeName: string;
entityInterfaceConcreteTypeNames?: Set<string>;
typeName: TypeName;
entityInterfaceConcreteTypeNames?: Set<TypeName>;
events?: EventConfiguration[];
externalFieldNames?: Set<string>;
externalFieldNames?: Set<FieldName>;
isInterfaceObject?: boolean;
provides?: RequiredFieldConfiguration[];
keys?: RequiredFieldConfiguration[];
requireFetchReasonsFieldNames?: Array<FieldName>;
requires?: RequiredFieldConfiguration[];
};
3 changes: 2 additions & 1 deletion composition/src/router-configuration/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigurationData, FieldSetConditionData, FieldSetConditionDataParams } from './types';
import { FieldName } from '../types/types';

export function newFieldSetConditionData({
fieldCoordinatesPath,
Expand All @@ -12,7 +13,7 @@ export function newFieldSetConditionData({

export function newConfigurationData(isEntity: boolean, renamedTypeName: string): ConfigurationData {
return {
fieldNames: new Set<string>(),
fieldNames: new Set<FieldName>(),
isRootNode: isEntity,
typeName: renamedTypeName,
};
Expand Down
1 change: 1 addition & 0 deletions composition/src/schema-building/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export type ObjectDefinitionData = {
node: MutableObjectNode;
persistedDirectivesData: PersistedDirectivesData;
renamedTypeName: string;
requireFetchReasonsFieldNames: Set<FieldName>;
subgraphNames: Set<string>;
description?: StringValueNode;
};
Expand Down
4 changes: 2 additions & 2 deletions composition/src/schema-building/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ export function isParentDataRootType(parentData: ParentDefinitionData): boolean
return parentData.isRootType;
}

export function isParentDataInterfaceType(parentData: ParentDefinitionData): boolean {
return parentData.kind === Kind.INTERFACE_TYPE_DEFINITION;
export function isInterfaceDefinitionData(data: ParentDefinitionData): data is InterfaceDefinitionData {
return data.kind === Kind.INTERFACE_TYPE_DEFINITION;
}

export function setParentDataExtensionType(existingData: ParentDefinitionData, incomingData: ParentDefinitionData) {
Expand Down
5 changes: 3 additions & 2 deletions composition/src/subgraph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ParentDefinitionData,
PersistedDirectiveDefinitionData,
} from '../schema-building/types';
import { TypeName } from '../types/types';

export type Subgraph = {
definitions: DocumentNode;
Expand All @@ -14,9 +15,9 @@ export type Subgraph = {
};

export type SubgraphConfig = {
configurationDataByTypeName: Map<string, ConfigurationData>;
configurationDataByTypeName: Map<TypeName, ConfigurationData>;
isVersionTwo: boolean;
parentDefinitionDataByTypeName: Map<string, ParentDefinitionData>;
parentDefinitionDataByTypeName: Map<TypeName, ParentDefinitionData>;
schema: GraphQLSchema;
};

Expand Down
3 changes: 2 additions & 1 deletion composition/src/utils/string-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const PARENT_DEFINITION_DATA = 'parentDefinitionDataByTypeName';
export const PARENT_DEFINITION_DATA_MAP = 'parentDefinitionDataByParentTypeName';
export const PARENT_EXTENSION_DATA_MAP = 'parentExtensionDataByParentTypeName';
export const PERIOD = '.';
export const REQUIRE_FETCH_REASONS = 'openfed__requireFetchReasons';
export const PROVIDER_ID = 'providerId';
export const PROVIDES = 'provides';
export const PUBLISH = 'publish';
Expand Down Expand Up @@ -165,7 +166,7 @@ export const EXECUTABLE_DIRECTIVE_LOCATIONS = new Set<string>([
export const ROOT_TYPE_NAMES = new Set<string>([MUTATION, QUERY, SUBSCRIPTION]);
export const AUTHORIZATION_DIRECTIVES = new Set<string>([AUTHENTICATED, REQUIRES_SCOPES]);
export const PERSISTED_CLIENT_DIRECTIVES = new Set<string>([DEPRECATED]);
export const INHERITABLE_DIRECTIVE_NAMES = new Set<string>([EXTERNAL, SHAREABLE]);
export const INHERITABLE_DIRECTIVE_NAMES = new Set<string>([EXTERNAL, REQUIRE_FETCH_REASONS, SHAREABLE]);
export const IGNORED_FIELDS = new Set<string>([ENTITIES_FIELD, SERVICE_FIELD]);

export const INPUT_NODE_KINDS = new Set<Kind>([
Expand Down
3 changes: 2 additions & 1 deletion composition/src/v1/federation/federation-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ import {
InvalidRequiredInputValueData,
} from '../../utils/types';
import { FederateSubgraphsContractV1Params, FederateSubgraphsWithContractsV1Params, FederationParams } from './types';
import { ContractName, FieldCoords, SubgraphName, TypeName } from '../../types/types';
import { ContractName, FieldCoords, FieldName, SubgraphName, TypeName } from '../../types/types';

export class FederationFactory {
authorizationDataByParentTypeName: Map<string, AuthorizationData>;
Expand Down Expand Up @@ -1132,6 +1132,7 @@ export class FederationFactory {
kind: sourceData.kind,
name: stringToNameNode(sourceData.renamedTypeName || sourceData.name),
},
requireFetchReasonsFieldNames: new Set<FieldName>(),
renamedTypeName: sourceData.renamedTypeName,
subgraphNames: new Set(sourceData.subgraphNames),
};
Expand Down
20 changes: 16 additions & 4 deletions composition/src/v1/normalization/directive-definition-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
LINK_DEFINITION,
OVERRIDE_DEFINITION,
PROVIDES_DEFINITION,
REQUIRE_FETCH_REASONS_DEFINITION,
REQUIRED_FIELDSET_TYPE_NODE,
REQUIRED_STRING_TYPE_NODE,
REQUIRES_DEFINITION,
Expand All @@ -36,6 +37,8 @@ import {
AS,
AUTHENTICATED,
BOOLEAN_SCALAR,
CHANNEL,
CHANNELS,
COMPOSE_DIRECTIVE,
CONDITION,
CONFIGURE_CHILD_DESCRIPTIONS,
Expand All @@ -49,6 +52,8 @@ import {
EDFS_NATS_REQUEST,
EDFS_NATS_STREAM_CONFIGURATION,
EDFS_NATS_SUBSCRIBE,
EDFS_REDIS_PUBLISH,
EDFS_REDIS_SUBSCRIBE,
ENUM_UPPER,
ENUM_VALUE_UPPER,
EXTENDS,
Expand All @@ -74,6 +79,7 @@ import {
PROVIDER_ID,
PROVIDES,
REASON,
REQUIRE_FETCH_REASONS,
REQUIRES,
REQUIRES_SCOPES,
RESOLVABLE,
Expand All @@ -94,10 +100,6 @@ import {
TOPICS,
UNION_UPPER,
URL_LOWER,
CHANNEL,
CHANNELS,
EDFS_REDIS_PUBLISH,
EDFS_REDIS_SUBSCRIBE,
} from '../../utils/string-constants';

export const AUTHENTICATED_DEFINITION_DATA: DirectiveDefinitionData = {
Expand Down Expand Up @@ -439,6 +441,16 @@ export const NATS_SUBSCRIBE_DEFINITION_DATA: DirectiveDefinitionData = {
requiredArgumentNames: new Set<string>([SUBJECTS]),
};

export const REQUIRE_FETCH_REASONS_DEFINITION_DATA: DirectiveDefinitionData = {
argumentTypeNodeByArgumentName: new Map<string, ArgumentData>(),
isRepeatable: true,
locations: new Set<string>([FIELD_DEFINITION_UPPER, OBJECT_UPPER]),
name: REQUIRE_FETCH_REASONS,
node: REQUIRE_FETCH_REASONS_DEFINITION,
optionalArgumentNames: new Set<string>(),
requiredArgumentNames: new Set<string>(),
};

export const REDIS_PUBLISH_DEFINITION_DATA: DirectiveDefinitionData = {
argumentTypeNodeByArgumentName: new Map<string, ArgumentData>([
[
Expand Down
38 changes: 27 additions & 11 deletions composition/src/v1/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
LINK_IMPORT_DEFINITION,
LINK_PURPOSE_DEFINITION,
MAX_OR_SCOPES,
REQUIRE_FETCH_REASONS_DEFINITION,
SCOPE_SCALAR_DEFINITION,
SUBSCRIPTION_FIELD_CONDITION_DEFINITION,
SUBSCRIPTION_FILTER_CONDITION_DEFINITION,
Expand Down Expand Up @@ -310,6 +311,7 @@ import {
PUBLISH,
QUERY,
REQUEST,
REQUIRE_FETCH_REASONS,
REQUIRES_SCOPES,
RESOLVABLE,
ROOT_TYPE_NAMES,
Expand Down Expand Up @@ -356,6 +358,7 @@ import {
} from './types';
import { newConfigurationData, newFieldSetConditionData } from '../../router-configuration/utils';
import { ImplementationErrors, InvalidFieldImplementation } from '../../utils/types';
import { FieldName } from '../../types/types';

export function normalizeSubgraphFromString(subgraphSDL: string, noLocation = true): NormalizationResult {
const { error, documentNode } = safeParse(subgraphSDL, noLocation);
Expand Down Expand Up @@ -385,6 +388,7 @@ export class NormalizationFactory {
definedDirectiveNames = new Set<string>();
directiveDefinitionByDirectiveName = new Map<string, DirectiveDefinitionNode>();
directiveDefinitionDataByDirectiveName = initializeDirectiveDefinitionDatas();
doesParentObjectRequireFetchReasons = false;
edfsDirectiveReferences = new Set<string>();
errors: Error[] = [];
entityDataByTypeName = new Map<string, EntityData>();
Expand Down Expand Up @@ -555,14 +559,18 @@ export class NormalizationFactory {
fieldDirectivesByDirectiveName: Map<string, Array<ConstDirectiveNode>>,
inheritedDirectiveNames: Set<string>,
) {
if (this.isParentObjectShareable && !fieldDirectivesByDirectiveName.has(SHAREABLE)) {
fieldDirectivesByDirectiveName.set(SHAREABLE, [generateSimpleDirective(SHAREABLE)]);
inheritedDirectiveNames.add(SHAREABLE);
}
if (this.isParentObjectExternal && !fieldDirectivesByDirectiveName.has(EXTERNAL)) {
fieldDirectivesByDirectiveName.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 (this.isParentObjectShareable && !fieldDirectivesByDirectiveName.has(SHAREABLE)) {
fieldDirectivesByDirectiveName.set(SHAREABLE, [generateSimpleDirective(SHAREABLE)]);
inheritedDirectiveNames.add(SHAREABLE);
}
return fieldDirectivesByDirectiveName;
}

Expand Down Expand Up @@ -591,6 +599,7 @@ export class NormalizationFactory {
continue;
}
this.isParentObjectExternal ||= directiveName === EXTERNAL;
this.doesParentObjectRequireFetchReasons ||= directiveName === REQUIRE_FETCH_REASONS;
this.isParentObjectShareable ||= directiveName === SHAREABLE;
}
Comment thread
ysmolski marked this conversation as resolved.
return directivesByDirectiveName;
Expand Down Expand Up @@ -1251,7 +1260,7 @@ export class NormalizationFactory {
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
const directivesByDirectiveName = this.extractDirectives(
node,
parentData?.directivesByDirectiveName || new Map<string, ConstDirectiveNode[]>(),
parentData?.directivesByDirectiveName ?? new Map<string, ConstDirectiveNode[]>(),
);
const isRootType = this.isTypeNameRootType(typeName);
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName, isRootType);
Expand Down Expand Up @@ -1290,6 +1299,7 @@ export class NormalizationFactory {
name: typeName,
node: getMutableObjectNode(node.name),
persistedDirectivesData: newPersistedDirectivesData(),
requireFetchReasonsFieldNames: new Set<FieldName>(),
renamedTypeName: this.getRenamedRootTypeName(typeName),
subgraphNames: new Set<string>([this.subgraphName]),
description: formatDescription('description' in node ? node.description : undefined),
Expand Down Expand Up @@ -2868,12 +2878,6 @@ export class NormalizationFactory {
definitions.push(EDFS_NATS_STREAM_CONFIGURATION_DEFINITION);
}

if (this.referencedDirectiveNames.has(LINK)) {
definitions.push(LINK_DEFINITION);
definitions.push(LINK_IMPORT_DEFINITION);
definitions.push(LINK_PURPOSE_DEFINITION);
}

if (invalidEventsDirectiveDataByRootFieldPath.size > 0) {
errorMessages.push(invalidRootTypeFieldEventsDirectivesErrorMessage(invalidEventsDirectiveDataByRootFieldPath));
}
Expand Down Expand Up @@ -3321,12 +3325,21 @@ export class NormalizationFactory {
definitions.push(SUBSCRIPTION_FIELD_CONDITION_DEFINITION);
definitions.push(SUBSCRIPTION_FILTER_VALUE_DEFINITION);
}

if (this.referencedDirectiveNames.has(LINK)) {
definitions.push(LINK_DEFINITION);
definitions.push(LINK_IMPORT_DEFINITION);
definitions.push(LINK_PURPOSE_DEFINITION);
}
if (this.referencedDirectiveNames.has(CONFIGURE_DESCRIPTION)) {
definitions.push(CONFIGURE_DESCRIPTION_DEFINITION);
}
if (this.referencedDirectiveNames.has(CONFIGURE_CHILD_DESCRIPTIONS)) {
definitions.push(CONFIGURE_CHILD_DESCRIPTIONS_DEFINITION);
}
if (this.referencedDirectiveNames.has(REQUIRE_FETCH_REASONS)) {
definitions.push(REQUIRE_FETCH_REASONS_DEFINITION);
}
for (const directiveDefinition of this.customDirectiveDefinitions.values()) {
definitions.push(directiveDefinition);
}
Expand Down Expand Up @@ -3459,6 +3472,9 @@ 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) {
configurationData.requireFetchReasonsFieldNames = [...parentData.requireFetchReasonsFieldNames];
}
break;
case Kind.SCALAR_TYPE_DEFINITION:
if (parentData.extensionType === ExtensionType.REAL) {
Expand Down
7 changes: 5 additions & 2 deletions composition/src/v1/normalization/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ import {
NATS_PUBLISH_DEFINITION_DATA,
NATS_REQUEST_DEFINITION_DATA,
NATS_SUBSCRIBE_DEFINITION_DATA,
REDIS_PUBLISH_DEFINITION_DATA,
REDIS_SUBSCRIBE_DEFINITION_DATA,
OVERRIDE_DEFINITION_DATA,
PROVIDES_DEFINITION_DATA,
REDIS_PUBLISH_DEFINITION_DATA,
REDIS_SUBSCRIBE_DEFINITION_DATA,
REQUIRE_FETCH_REASONS_DEFINITION_DATA,
REQUIRES_DEFINITION_DATA,
REQUIRES_SCOPES_DEFINITION_DATA,
SHAREABLE_DEFINITION_DATA,
Expand Down Expand Up @@ -72,6 +73,7 @@ import {
PERIOD,
PROVIDES,
QUERY,
REQUIRE_FETCH_REASONS,
REQUIRES,
REQUIRES_SCOPES,
SHAREABLE,
Expand Down Expand Up @@ -404,6 +406,7 @@ export function initializeDirectiveDefinitionDatas(): Map<string, DirectiveDefin
[LINK, LINK_DEFINITION_DATA],
[OVERRIDE, OVERRIDE_DEFINITION_DATA],
[PROVIDES, PROVIDES_DEFINITION_DATA],
[REQUIRE_FETCH_REASONS, REQUIRE_FETCH_REASONS_DEFINITION_DATA],
[REQUIRES, REQUIRES_DEFINITION_DATA],
[REQUIRES_SCOPES, REQUIRES_SCOPES_DEFINITION_DATA],
[SHAREABLE, SHAREABLE_DEFINITION_DATA],
Expand Down
10 changes: 8 additions & 2 deletions composition/src/v1/normalization/walkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { extractFieldSetValue, newFieldSetData } from './utils';
import { EVENT_DIRECTIVE_NAMES } from '../utils/string-constants';
import {
getRenamedRootTypeName,
isInterfaceDefinitionData,
isParentDataCompositeOutputType,
isParentDataInterfaceType,
isTypeNameRootType,
newPersistedDirectivesData,
} from '../../schema-building/utils';
Expand All @@ -40,6 +40,7 @@ import {
IGNORED_FIELDS,
PARENT_DEFINITION_DATA,
PROVIDES,
REQUIRE_FETCH_REASONS,
REQUIRES,
SERVICE_OBJECT,
SUBSCRIPTION_FILTER,
Expand Down Expand Up @@ -362,11 +363,14 @@ export function upsertParentsAndChildren(nf: NormalizationFactory, document: Doc
const directivesByDirectiveName = nf.extractDirectives(node, new Map<string, ConstDirectiveNode[]>());
const inheritedDirectiveNames = new Set<string>();
// Add parent-level shareable and external to the field extraction and repeatable validation
if (!isParentDataInterfaceType(parentData)) {
if (!isInterfaceDefinitionData(parentData)) {
nf.addInheritedDirectivesToFieldData(directivesByDirectiveName, inheritedDirectiveNames);
if (directivesByDirectiveName.has(EXTERNAL)) {
nf.unvalidatedExternalFieldCoords.add(`${nf.originalParentTypeName}.${fieldName}`);
}
if (nf.doesParentObjectRequireFetchReasons || directivesByDirectiveName.has(REQUIRE_FETCH_REASONS)) {
parentData.requireFetchReasonsFieldNames.add(fieldName);
}
}
const fieldData = nf.addFieldDataByNode(
parentData.fieldDataByName,
Expand Down Expand Up @@ -521,6 +525,7 @@ export function upsertParentsAndChildren(nf: NormalizationFactory, document: Doc
nf.renamedParentTypeName = '';
nf.lastParentNodeKind = Kind.NULL;
nf.isParentObjectExternal = false;
nf.doesParentObjectRequireFetchReasons = false;
nf.isParentObjectShareable = false;
},
},
Expand All @@ -546,6 +551,7 @@ export function upsertParentsAndChildren(nf: NormalizationFactory, document: Doc
nf.renamedParentTypeName = '';
nf.lastParentNodeKind = Kind.NULL;
nf.isParentObjectExternal = false;
nf.doesParentObjectRequireFetchReasons = false;
nf.isParentObjectShareable = false;
},
},
Expand Down
Loading
Loading