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
10 changes: 2 additions & 8 deletions composition-go/composition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@ func normalizeWhiteSpace(s string) string {
func TestFederateSubgraphs(t *testing.T) {
const (
expectedSDL = `
directive @authenticated on ENUM | FIELD_DEFINITION | INTERFACE | OBJECT | SCALAR

directive @deprecated(reason: String = "No longer supported") on ARGUMENT_DEFINITION | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @inaccessible on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION

directive @requiresScopes(scopes: [[openfed__Scope!]!]!) on ENUM | FIELD_DEFINITION | INTERFACE | OBJECT | SCALAR

directive @tag(name: String!) repeatable on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION
directive @authenticated on ENUM | FIELD_DEFINITION | INTERFACE | OBJECT | SCALAR

scalar openfed__Scope

Expand Down
370 changes: 185 additions & 185 deletions composition-go/index.global.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions composition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ export * from './schema-building/utils';
export * from './subgraph/types';
export * from './types/types';
export * from './utils/composition-version';
export * from './utils/params';
export * from './utils/string-constants';
export * from './utils/types';
export * from './utils/utils';
export * from './warnings/types';

// v1
export * from './v1/constants/constants';
export * from './v1/constants/directive-definitions';
export * from './v1/constants/integers';
export * from './v1/constants/non-directive-definitions';
export * from './v1/constants/strings';
export * from './v1/constants/type-nodes';
export * from './v1/federation/utils';
export * from './v1/federation/walkers';
export * from './v1/federation/types';
Expand All @@ -36,7 +43,5 @@ export * from './v1/normalization/types';
export * from './v1/normalization/walkers';
export * from './v1/schema-building/type-merging';
export * from './v1/subgraph/subgraph';
export * from './v1/utils/constants';
export * from './v1/utils/utils';
export * from './v1/utils/string-constants';
export * from './v1/warnings/warnings';
6 changes: 3 additions & 3 deletions composition/src/normalization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../schema-building/types';
import { Graph } from '../resolvability-graph/graph';
import { InternalSubgraph } from '../subgraph/types';
import { DirectiveName } from '../types/types';
import { DirectiveName, TypeName } from '../types/types';

export type NormalizationFailure = {
errors: Array<Error>;
Expand All @@ -23,8 +23,8 @@ export type NormalizationSuccess = {
authorizationDataByParentTypeName: Map<string, AuthorizationData>;
concreteTypeNamesByAbstractTypeName: Map<string, Set<string>>;
conditionalFieldDataByCoordinates: Map<string, ConditionalFieldData>;
configurationDataByTypeName: Map<string, ConfigurationData>;
directiveDefinitionByDirectiveName: Map<DirectiveName, DirectiveDefinitionNode>;
configurationDataByTypeName: Map<TypeName, ConfigurationData>;
directiveDefinitionByName: Map<DirectiveName, DirectiveDefinitionNode>;
entityInterfaces: Map<string, EntityInterfaceSubgraphData>;
entityDataByTypeName: Map<string, EntityData>;
fieldCoordsByNamedTypeName: Map<string, Set<string>>;
Expand Down
2 changes: 1 addition & 1 deletion composition/src/schema-building/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function getMutableUnionNode(nameNode: NameNode): MutableUnionNode {
};
}

export type MutableTypeDefinitionNode =
export type MutableDefinitionNode =
| MutableDirectiveDefinitionNode
| MutableEnumNode
| MutableInputObjectNode
Expand Down
64 changes: 10 additions & 54 deletions composition/src/schema-building/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BooleanValueNode,
ConstDirectiveNode,
ConstValueNode,
DefinitionNode,
DirectiveDefinitionNode,
EnumValueDefinitionNode,
EnumValueNode,
Expand All @@ -26,6 +27,7 @@ import {
ExtensionType,
ExternalFieldData,
FieldData,
InputObjectDefinitionData,
InputValueData,
InterfaceDefinitionData,
NodeData,
Expand All @@ -35,7 +37,7 @@ import {
PersistedDirectivesData,
SchemaData,
} from './types';
import { MutableFieldNode, MutableInputValueNode, MutableTypeDefinitionNode } from './ast';
import { MutableDefinitionNode, MutableFieldNode, MutableInputValueNode } from './ast';
import { ObjectTypeNode, setToNameNodeArray, stringToNameNode } from '../ast/utils';
import {
incompatibleInputValueDefaultValuesError,
Expand All @@ -46,7 +48,6 @@ import { SubscriptionFilterValue } from '../router-configuration/types';
import {
ARGUMENT,
AUTHENTICATED,
AUTHORIZATION_DIRECTIVES,
BOOLEAN_SCALAR,
DEPRECATED,
DEPRECATED_DEFAULT_ARGUMENT_VALUE,
Expand All @@ -58,7 +59,6 @@ import {
INPUT_NODE_KINDS,
INT_SCALAR,
MUTATION,
NON_REPEATABLE_PERSISTED_DIRECTIVES,
OUTPUT_NODE_KINDS,
PERSISTED_CLIENT_DIRECTIVES,
QUERY,
Expand All @@ -69,7 +69,6 @@ import {
SHAREABLE,
STRING_SCALAR,
SUBSCRIPTION,
TAG,
} from '../utils/string-constants';
import {
generateRequiresScopesDirective,
Expand Down Expand Up @@ -285,7 +284,7 @@ export function setParentDataExtensionType(existingData: ParentDefinitionData, i
existingData.extensionType = ExtensionType.NONE;
}

function upsertDeprecatedDirective(
export function upsertDeprecatedDirective(
persistedDirectivesData: PersistedDirectivesData,
incomingDirectiveNode: ConstDirectiveNode,
) {
Expand All @@ -299,7 +298,7 @@ function upsertDeprecatedDirective(
}
}

function upsertTagDirectives(
export function upsertTagDirectives(
persistedDirectivesData: PersistedDirectivesData,
incomingDirectiveNodes: ConstDirectiveNode[],
) {
Expand All @@ -310,42 +309,6 @@ function upsertTagDirectives(
}
}

export function extractPersistedDirectives(
persistedDirectivesData: PersistedDirectivesData,
directivesByDirectiveName: Map<DirectiveName, ConstDirectiveNode[]>,
persistedDirectiveDefinitionByDirectiveName: Map<DirectiveName, DirectiveDefinitionNode>,
): PersistedDirectivesData {
for (const [directiveName, directiveNodes] of directivesByDirectiveName) {
// @authenticated and @requiresScopes are handled differently
if (
AUTHORIZATION_DIRECTIVES.has(directiveName) ||
!persistedDirectiveDefinitionByDirectiveName.has(directiveName)
) {
continue;
}
if (directiveName === DEPRECATED) {
persistedDirectivesData.isDeprecated = true;
upsertDeprecatedDirective(persistedDirectivesData, directiveNodes[0]);
continue;
}
if (directiveName === TAG) {
upsertTagDirectives(persistedDirectivesData, directiveNodes);
continue;
}
const existingDirectives = persistedDirectivesData.directivesByDirectiveName.get(directiveName);
if (!existingDirectives) {
persistedDirectivesData.directivesByDirectiveName.set(directiveName, [...directiveNodes]);
continue;
}
// Only add one instance of certain directives.
if (NON_REPEATABLE_PERSISTED_DIRECTIVES.has(directiveName)) {
continue;
}
existingDirectives.push(...directiveNodes);
}
return persistedDirectivesData;
}

export function propagateAuthDirectives(parentData: ParentDefinitionData, authData?: AuthorizationData) {
if (!authData) {
return;
Expand Down Expand Up @@ -468,17 +431,6 @@ export function getClientPersistedDirectiveNodes<T extends NodeData>(nodeData: T
return persistedDirectiveNodes;
}

export function getNodeForRouterSchemaByData<T extends ParentDefinitionData | EnumValueData>(
data: T,
persistedDirectiveDefinitionByDirectiveName: Map<DirectiveName, DirectiveDefinitionNode>,
errors: Error[],
): T['node'] {
data.node.name = stringToNameNode(data.name);
data.node.description = data.description;
data.node.directives = getRouterPersistedDirectiveNodes(data, persistedDirectiveDefinitionByDirectiveName, errors);
return data.node;
}

export function getClientSchemaFieldNodeByFieldData(fieldData: FieldData): MutableFieldNode {
const directives = getClientPersistedDirectiveNodes(fieldData);
const argumentNodes: MutableInputValueNode[] = [];
Expand Down Expand Up @@ -557,7 +509,7 @@ function addValidatedArgumentNodes(
}

export function addValidPersistedDirectiveDefinitionNodeByData(
definitions: MutableTypeDefinitionNode[],
definitions: (MutableDefinitionNode | DefinitionNode)[],
data: PersistedDirectiveDefinitionData,
persistedDirectiveDefinitionByDirectiveName: Map<DirectiveName, DirectiveDefinitionNode>,
errors: Error[],
Expand Down Expand Up @@ -783,6 +735,10 @@ export function isFieldData(data: ChildData | NodeData | SchemaData): data is Fi
return data.kind === Kind.FIELD_DEFINITION;
}

export function isInputObjectDefinitionData(data: ParentDefinitionData): data is InputObjectDefinitionData {
return data.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION;
}

export function isInputNodeKind(kind: Kind): kind is InputNodeKind {
return INPUT_NODE_KINDS.has(kind);
}
Expand Down
6 changes: 3 additions & 3 deletions composition/src/subgraph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export type Subgraph = {

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

export type InternalSubgraph = {
conditionalFieldDataByCoordinates: Map<string, ConditionalFieldData>;
configurationDataByTypeName: Map<string, ConfigurationData>;
configurationDataByTypeName: Map<TypeName, ConfigurationData>;
definitions: DocumentNode;
directiveDefinitionByDirectiveName: Map<DirectiveName, DirectiveDefinitionNode>;
directiveDefinitionByName: Map<DirectiveName, DirectiveDefinitionNode>;
entityInterfaces: Map<string, EntityInterfaceSubgraphData>;
isVersionTwo: boolean;
keyFieldNamesByParentTypeName: Map<string, Set<string>>;
Expand Down
14 changes: 14 additions & 0 deletions composition/src/utils/params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type AddToSetParams<T> = {
source: Iterable<T>;
target: Set<T>;
};

export type AddOptionalToSetParams<T> = {
target: Set<T>;
source?: Iterable<T>;
};

export type AddMapEntriesParams<K, V> = {
source: Map<K, V>;
target: Map<K, V>;
};
14 changes: 12 additions & 2 deletions composition/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from './string-constants';
import { invalidKeyFatalError } from '../errors/errors';
import { stringToNameNode } from '../ast/utils';
import { AddMapEntriesParams, AddOptionalToSetParams, AddToSetParams } from './params';

export function getOrThrowError<K, V>(map: Map<K, V>, key: K, mapName: string): V {
const value = map.get(key);
Expand Down Expand Up @@ -55,7 +56,16 @@ export function numberToOrdinal(num: number): string {
}
}

export function addIterableValuesToSet<T>(source: Array<T> | Iterable<T>, target: Set<T>) {
export function addIterableToSet<T>({ source, target }: AddToSetParams<T>) {
for (const value of source) {
target.add(value);
}
}

export function addOptionalIterableToSet<T>({ source, target }: AddOptionalToSetParams<T>) {
if (!source) {
return;
}
for (const value of source) {
target.add(value);
}
Expand Down Expand Up @@ -242,7 +252,7 @@ export function copyArrayValueMap<K, V>(source: Map<K, Array<V>>): Map<K, Array<
return output;
}

export function addMapEntries<K, V>(source: Map<K, V>, target: Map<K, V>) {
export function addMapEntries<K, V>({ source, target }: AddMapEntriesParams<K, V>) {
for (const [key, value] of source) {
target.set(key, value);
}
Expand Down
Loading
Loading