Skip to content

Commit

Permalink
Merge branch 'main' into nithin/eng-5878-fix-federated-graph-schema-v…
Browse files Browse the repository at this point in the history
…ersion-relation
  • Loading branch information
thisisnithin authored Nov 22, 2024
2 parents 3f9f423 + 34cdc21 commit 01348ef
Show file tree
Hide file tree
Showing 37 changed files with 892 additions and 355 deletions.
2 changes: 2 additions & 0 deletions .github/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paths-ignore:
- 'composition-go/index.global.js'
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
config-file: .github/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
Expand Down
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Binaries are attached to the github release otherwise all images can be found [h
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.70.4](https://github.com/wundergraph/cosmo/compare/[email protected]@0.70.4) (2024-11-21)

**Note:** Version bump only for package wgc

## [0.70.3](https://github.com/wundergraph/cosmo/compare/[email protected]@0.70.3) (2024-11-18)

**Note:** Version bump only for package wgc
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wgc",
"version": "0.70.3",
"version": "0.70.4",
"description": "The official CLI tool to manage the GraphQL Federation Platform Cosmo",
"type": "module",
"main": "dist/index.js",
Expand Down
344 changes: 172 additions & 172 deletions composition-go/index.global.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions composition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Binaries are attached to the github release otherwise all images can be found [h
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.32.0](https://github.com/wundergraph/cosmo/compare/@wundergraph/[email protected]...@wundergraph/[email protected]) (2024-11-21)

### Features

* add validation for V2 [@external](https://github.com/external) directive ([#1392](https://github.com/wundergraph/cosmo/issues/1392)) ([d2a8f73](https://github.com/wundergraph/cosmo/commit/d2a8f73e1c47b62a435ddacc3ceffd7d7abd7b9f)) (@Aenimus)

## [0.31.1](https://github.com/wundergraph/cosmo/compare/@wundergraph/[email protected]...@wundergraph/[email protected]) (2024-11-14)

### Bug Fixes
Expand Down
10 changes: 10 additions & 0 deletions composition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ const subgraphA: Subgraph = {
| name | unique name of the subgraph | string |
| url | unique endpoint for the subgraph | string |
| definitions | an AST representation of the subgraph SDL | graphql.DocumentNode |

### Contributing
Some GraphQL and Federation jargon should begin with a capitalised letter for clarity, e.g.,:
- Argument
- Enum
- Field
- Input Object
- Interface
- Object
When adding or changing errors, please begin these terms with a capital letter.
2 changes: 1 addition & 1 deletion composition/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wundergraph/composition",
"version": "0.31.1",
"version": "0.32.0",
"author": {
"name": "WunderGraph Maintainers",
"email": "[email protected]"
Expand Down
11 changes: 10 additions & 1 deletion composition/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export function undefinedFieldInFieldSetErrorMessage(
): string {
return (
` The following field set is invalid:\n "${fieldSet}"\n` +
` This is because of the selection set corresponding to the field coordinate "${parentTypeName}.${fieldName}".\n` +
` This is because of the selection set corresponding to the Field coordinates "${parentTypeName}.${fieldName}".\n` +
` The type "${parentTypeName}" does not define a field named "${fieldName}".`
);
}
Expand Down Expand Up @@ -1628,3 +1628,12 @@ export function unexpectedNonCompositeOutputTypeError(namedTypeName: string, act
` but received "${actualTypeString}".\nThis should never happen. Please report this issue on GitHub.`,
);
}

export function invalidExternalDirectiveError(fieldCoords: string): Error {
return new Error(
`The Object Field "${fieldCoords}" is invalidly declared "@external". An Object Field should only` +
` be declared "@external" if it is part of a "@key", "@provides", or "@requires" FieldSet, or the Field is` +
` necessary to satisfy an Interface implementation. In the case that none of these conditions is true, the` +
` "@external" directive should be removed.`,
);
}
7 changes: 3 additions & 4 deletions composition/src/federation/federation-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ import {
setParentDataExtensionType,
validateExternalAndShareable,
} from '../schema-building/utils';
import { ObjectExtensionData } from '../schema-building/type-extension-data';

import { renameRootTypes } from './walkers';
import { cloneDeep, union } from 'lodash';
import { cloneDeep } from 'lodash';
import {
DivergentType,
FederateTypeOptions,
Expand Down Expand Up @@ -880,7 +879,7 @@ export class FederationFactory {
return members;
}

recordTagNamesByPath(data: NodeData | ObjectExtensionData, nodePath?: string) {
recordTagNamesByPath(data: NodeData, nodePath?: string) {
const path = nodePath || data.name;
if (data.persistedDirectivesData.tags.size > 0) {
const tagNames = getValueOrDefault(this.tagNamesByPath, path, () => new Set<string>());
Expand Down Expand Up @@ -1101,7 +1100,7 @@ export class FederationFactory {
}

propagateInaccessibilityToExistingChildren(
data: InputObjectDefinitionData | InterfaceDefinitionData | ObjectDefinitionData | ObjectExtensionData,
data: InputObjectDefinitionData | InterfaceDefinitionData | ObjectDefinitionData,
) {
data.isInaccessible = true;
switch (data.kind) {
Expand Down
3 changes: 1 addition & 2 deletions composition/src/federation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
InterfaceDefinitionData,
ObjectDefinitionData,
ParentDefinitionData,
ParentWithFieldsData,
} from '../schema-building/type-definition-data';
import { addIterableValuesToSet, AuthorizationData, EntityData, EntityInterfaceFederationData } from '../utils/utils';
import { Graph } from '../resolvability-graph/graph';
Expand Down Expand Up @@ -131,7 +130,7 @@ export function validateImplicitFieldSets({
// This would be caught as an error elsewhere
continue;
}
const parentDatas: ParentWithFieldsData[] = [objectData];
const parentDatas: CompositeOutputData[] = [objectData];
const definedFields: Set<string>[] = [];
const keyFieldNames = new Set<string>();
const fieldSetConditions: Array<FieldSetCondition> = [];
Expand Down
4 changes: 2 additions & 2 deletions composition/src/federation/walkers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FederationFactory } from './federation-factory';
import { InternalSubgraph } from '../subgraph/subgraph';
import {
CompositeOutputData,
InterfaceDefinitionData,
ObjectDefinitionData,
ParentWithFieldsData,
} from '../schema-building/type-definition-data';
import { visit } from 'graphql';
import { ENTITIES_FIELD, OPERATION_TO_DEFAULT, PARENT_DEFINITION_DATA, SERVICE_FIELD } from '../utils/string-constants';
Expand All @@ -12,7 +12,7 @@ import { operationTypeNodeToDefaultType } from '../ast/utils';
import { renameNamedTypeName } from '../schema-building/type-merging';

export function renameRootTypes(ff: FederationFactory, subgraph: InternalSubgraph) {
let parentData: ParentWithFieldsData | undefined;
let parentData: CompositeOutputData | undefined;
let isParentRootType = false;
let overriddenFieldNames: Set<string> | undefined;
visit(subgraph.definitions, {
Expand Down
1 change: 0 additions & 1 deletion composition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export * from './resolvability-graph/graph-nodes';
export * from './resolvability-graph/utils';
export * from './schema-building/ast';
export * from './schema-building/type-definition-data';
export * from './schema-building/type-extension-data';
export * from './schema-building/type-merging';
export * from './schema-building/utils';
export * from './subgraph/subgraph';
Expand Down
44 changes: 24 additions & 20 deletions composition/src/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ import {
} from '../ast/utils';
import {
addFieldNamesToConfigurationData,
validateArgumentTemplateReferences,
FieldSetData,
InputValidationContainer,
isNodeQuery,
KeyFieldSetData,
validateAndAddConditionalFieldSetsToConfiguration,
validateArgumentTemplateReferences,
validateKeyFieldSets,
} from './utils';
import {
BASE_DIRECTIVE_DEFINITION_BY_DIRECTIVE_NAME,
BASE_DIRECTIVE_DEFINITIONS,
BASE_SCALARS,
EDFS_ARGS_REGEXP,
EVENT_DRIVEN_DIRECTIVE_DEFINITIONS_BY_DIRECTIVE_NAME,
FIELD_SET_SCALAR_DEFINITION,
SCOPE_SCALAR_DEFINITION,
Expand Down Expand Up @@ -105,9 +104,9 @@ import {
invalidEventDrivenMutationResponseTypeErrorMessage,
invalidEventProviderIdErrorMessage,
invalidEventSubjectErrorMessage,
invalidEventSubjectsArgumentErrorMessage,
invalidEventSubjectsErrorMessage,
invalidEventSubjectsItemErrorMessage,
invalidExternalDirectiveError,
invalidImplementedTypeError,
invalidInterfaceImplementationError,
invalidKeyDirectiveArgumentErrorMessage,
Expand Down Expand Up @@ -140,7 +139,6 @@ import {
subgraphInvalidSyntaxError,
subgraphValidationError,
subgraphValidationFailureError,
undefinedEventSubjectsArgumentErrorMessage,
undefinedNatsStreamConfigurationInputErrorMessage,
undefinedObjectLikeParentError,
undefinedRequiredArgumentsErrorMessage,
Expand All @@ -167,7 +165,7 @@ import {
INACCESSIBLE,
KEY,
MUTATION,
N_A,
NOT_APPLICABLE,
NON_NULLABLE_BOOLEAN,
NON_NULLABLE_EDFS_PUBLISH_EVENT_RESULT,
NON_NULLABLE_STRING,
Expand Down Expand Up @@ -203,6 +201,7 @@ import { printTypeNode } from '@graphql-tools/merge';
import { InternalSubgraph, recordSubgraphName, Subgraph } from '../subgraph/subgraph';
import {
externalInterfaceFieldsWarning,
invalidExternalFieldWarning,
invalidOverrideTargetSubgraphNameWarning,
unimplementedInterfaceOutputTypeWarning,
Warning,
Expand All @@ -218,8 +217,8 @@ import {
ExtensionType,
FieldData,
InputValueData,
ObjectDefinitionData,
ParentDefinitionData,
ParentWithFieldsData,
PersistedDirectiveDefinitionData,
SchemaData,
UnionDefinitionData,
Expand All @@ -237,7 +236,6 @@ import {
getUnionNodeByData,
isTypeValidImplementation,
newPersistedDirectivesData,
ObjectData,
} from '../schema-building/utils';
import {
CompositeOutputNode,
Expand Down Expand Up @@ -321,6 +319,7 @@ export class NormalizationFactory {
entityDataByTypeName = new Map<string, EntityData>();
entityInterfaceDataByTypeName = new Map<string, EntityInterfaceSubgraphData>();
eventsConfigurations = new Map<string, EventConfiguration[]>();
unvalidatedExternalFieldCoords = new Set<string>();
interfaceTypeNamesWithAuthorizationDirectives = new Set<string>();
internalGraph: Graph;
isCurrentParentExtension = false;
Expand Down Expand Up @@ -352,7 +351,7 @@ export class NormalizationFactory {
for (const [baseDirectiveName, baseDirectiveDefinition] of BASE_DIRECTIVE_DEFINITION_BY_DIRECTIVE_NAME) {
this.directiveDefinitionByDirectiveName.set(baseDirectiveName, baseDirectiveDefinition);
}
this.subgraphName = subgraphName || N_A;
this.subgraphName = subgraphName || NOT_APPLICABLE;
this.internalGraph = internalGraph;
this.internalGraph.setSubgraphName(this.subgraphName);
this.schemaDefinition = {
Expand Down Expand Up @@ -1050,7 +1049,7 @@ export class NormalizationFactory {
}
}

validateInterfaceImplementations(data: ParentWithFieldsData) {
validateInterfaceImplementations(data: CompositeOutputData) {
if (data.implementedInterfaceTypeNames.size < 1) {
return;
}
Expand All @@ -1059,19 +1058,16 @@ export class NormalizationFactory {
const invalidImplementationTypeStringByTypeName = new Map<string, string>();
let doesInterfaceImplementItself = false;
for (const interfaceName of data.implementedInterfaceTypeNames) {
const implementationData = this.parentDefinitionDataByTypeName.get(interfaceName);
if (!implementationData) {
const interfaceData = this.parentDefinitionDataByTypeName.get(interfaceName);
if (!interfaceData) {
this.errors.push(undefinedTypeError(interfaceName));
continue;
}
if (implementationData.kind !== Kind.INTERFACE_TYPE_DEFINITION) {
invalidImplementationTypeStringByTypeName.set(
implementationData.name,
kindToTypeString(implementationData.kind),
);
if (interfaceData.kind !== Kind.INTERFACE_TYPE_DEFINITION) {
invalidImplementationTypeStringByTypeName.set(interfaceData.name, kindToTypeString(interfaceData.kind));
continue;
}
if (data.name === implementationData.name) {
if (data.name === interfaceData.name) {
doesInterfaceImplementItself = true;
continue;
}
Expand All @@ -1080,7 +1076,8 @@ export class NormalizationFactory {
unimplementedFields: [],
};
let hasErrors = false;
for (const [fieldName, interfaceField] of implementationData.fieldDataByFieldName) {
for (const [fieldName, interfaceField] of interfaceData.fieldDataByFieldName) {
this.unvalidatedExternalFieldCoords.delete(`${data.name}.${fieldName}`);
let hasNestedErrors = false;
const fieldData = data.fieldDataByFieldName.get(fieldName);
if (!fieldData) {
Expand Down Expand Up @@ -1516,7 +1513,7 @@ export class NormalizationFactory {
}

validateEventDrivenRootType(
data: ObjectData,
data: ObjectDefinitionData,
invalidEventsDirectiveDataByRootFieldPath: Map<string, InvalidRootTypeFieldEventsDirectiveData>,
invalidResponseTypeStringByRootFieldPath: Map<string, string>,
invalidResponseTypeNameByMutationPath: Map<string, string>,
Expand Down Expand Up @@ -1772,7 +1769,7 @@ export class NormalizationFactory {
}
}

validateAndAddKeyToConfiguration(parentData: ParentWithFieldsData, keyFieldSetData: KeyFieldSetData) {
validateAndAddKeyToConfiguration(parentData: CompositeOutputData, keyFieldSetData: KeyFieldSetData) {
const configurationData = getOrThrowError(
this.configurationDataByParentTypeName,
getParentTypeName(parentData),
Expand Down Expand Up @@ -2106,6 +2103,13 @@ export class NormalizationFactory {
if (this.isSubgraphEventDrivenGraph) {
this.validateEventDrivenSubgraph();
}
for (const fieldCoords of this.unvalidatedExternalFieldCoords) {
if (this.isSubgraphVersionTwo) {
this.errors.push(invalidExternalDirectiveError(fieldCoords));
} else {
this.warnings.push(invalidExternalFieldWarning(fieldCoords, this.subgraphName));
}
}
if (this.errors.length > 0) {
return { errors: this.errors, warnings: this.warnings };
}
Expand Down
Loading

0 comments on commit 01348ef

Please sign in to comment.