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

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion composition/src/normalization/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Warning } from '../warnings/types';
import { DirectiveDefinitionNode, DocumentNode, GraphQLSchema, OperationTypeNode } from 'graphql';
import {
DirectiveDefinitionNode,
DocumentNode,
GraphQLSchema,
OperationTypeNode,
SchemaDefinitionNode,
SchemaExtensionNode,
} from 'graphql';
import { ConfigurationData } from '../router-configuration/types';
import {
AuthorizationData,
Expand Down Expand Up @@ -42,6 +49,7 @@ export type NormalizationSuccess = {
subgraphString: string;
success: true;
warnings: Array<Warning>;
schemaNode?: SchemaDefinitionNode | SchemaExtensionNode;
};

export type NormalizationResult = NormalizationFailure | NormalizationSuccess;
Expand Down
29 changes: 17 additions & 12 deletions composition/src/v1/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
OperationTypeNode,
print,
SchemaDefinitionNode,
SchemaExtensionNode,
StringValueNode,
TypeDefinitionNode,
TypeExtensionNode,
Expand All @@ -41,7 +42,6 @@ import {
SchemaNode,
setToNamedTypeNodeArray,
stringToNamedTypeNode,
stringToNameNode,
UnionTypeNode,
} from '../../ast/utils';
import {
Expand Down Expand Up @@ -262,7 +262,6 @@ import {
CONSUMER_INACTIVE_THRESHOLD,
CONSUMER_NAME,
DEFAULT_EDFS_PROVIDER_ID,
DEPRECATED,
DESCRIPTION_OVERRIDE,
EDFS_KAFKA_PUBLISH,
EDFS_KAFKA_SUBSCRIBE,
Expand Down Expand Up @@ -308,7 +307,6 @@ import {
PROVIDER_TYPE_REDIS,
PUBLISH,
QUERY,
REASON,
REQUEST,
REQUIRE_FETCH_REASONS,
REQUIRES_SCOPES,
Expand Down Expand Up @@ -365,7 +363,6 @@ import { ImplementationErrors, InvalidFieldImplementation } from '../../utils/ty
import { DirectiveName, FieldName, SubgraphName, TypeName } from '../../types/types';
import { HandleFieldInheritableDirectivesParams, ValidateOneOfDirectiveParams } from './params';
import { EDFS_NATS_STREAM_CONFIGURATION_DEFINITION } from '../constants/non-directive-definitions';
import { DEFAULT_DEPRECATION_REASON } from 'graphql/index';

export function normalizeSubgraphFromString(subgraphSDL: string, noLocation = true): NormalizationResult {
const { error, documentNode } = safeParse(subgraphSDL, noLocation);
Expand Down Expand Up @@ -3486,18 +3483,25 @@ export class NormalizationFactory {
definitions.push(...dependencies);
}

#addSchemaDefinitionNode(definitions: Array<DefinitionNode>): void {
#addSchemaDefinitionNode(definitions: Array<DefinitionNode>): SchemaDefinitionNode | SchemaExtensionNode | undefined {
const schemaNode = this.getSchemaNodeByData(this.schemaData);
if (schemaNode.operationTypes.length > 0) {
definitions.push(schemaNode);
return;
return schemaNode;
}
if (schemaNode.directives?.length) {
definitions.push({
directives: schemaNode.directives,
kind: Kind.SCHEMA_EXTENSION,
});

if (!schemaNode.directives?.length) {
return;
}
return {
directives: schemaNode.directives,
kind: Kind.SCHEMA_EXTENSION,
};
// @TODO this currently breaks engine
// definitions.push({
// directives: schemaNode.directives,
// kind: Kind.SCHEMA_EXTENSION,
// });
}

normalize(document: DocumentNode): NormalizationResult {
Expand All @@ -3507,7 +3511,7 @@ export class NormalizationFactory {
const definitions: DefinitionNode[] = [];
this.#addDirectiveDefinitionsToDocument(definitions);
this.validateDirectives(this.schemaData, SCHEMA);
this.#addSchemaDefinitionNode(definitions);
const schemaNode = this.#addSchemaDefinitionNode(definitions);
for (const [parentTypeName, parentData] of this.parentDefinitionDataByTypeName) {
this.validateDirectives(parentData, parentTypeName);
}
Expand Down Expand Up @@ -3789,6 +3793,7 @@ export class NormalizationFactory {
overridesByTargetSubgraphName: this.overridesByTargetSubgraphName,
parentDefinitionDataByTypeName: this.parentDefinitionDataByTypeName,
persistedDirectiveDefinitionDataByDirectiveName,
schemaNode,
subgraphAST: newAST,
subgraphString: print(newAST),
schema: buildASTSchema(newAST, { addInvalidExtensionOrphans: true, assumeValid: true, assumeValidSDL: true }),
Expand Down
8 changes: 7 additions & 1 deletion composition/tests/v1/directives/directives.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
DEPRECATED,
DEPRECATED_DEFINITION,
DirectiveName,
FIRST_ORDINAL,
INACCESSIBLE,
Expand Down Expand Up @@ -301,7 +303,8 @@ describe('Directive tests', () => {
);
});

test('that directives declared after schema definitions and extensions are still valid #2', () => {
// Schema extensions cannot be added to the SDL currently because it breaks the engine
test.skip('that directives declared after schema definitions and extensions are still valid #2', () => {
const { schema } = normalizeSubgraphSuccess(nbaaa, ROUTER_COMPATIBILITY_VERSION_ONE);
expect(schemaToSortedNormalizedString(schema)).toBe(
normalizeString(
Expand Down Expand Up @@ -400,11 +403,13 @@ describe('Directive tests', () => {
type Query {
a: ID @inaccessible
b: ID @tag(name: "name")
c: ID @deprecated(reason: "No longer supported")
}`,
),
);
expect(directiveDefinitionByName).toStrictEqual(
new Map<DirectiveName, DirectiveDefinitionNode>([
[DEPRECATED, DEPRECATED_DEFINITION],
[INACCESSIBLE, INACCESSIBLE_DEFINITION],
[TAG, TAG_DEFINITION],
]),
Expand Down Expand Up @@ -634,6 +639,7 @@ const faaaa: Subgraph = {
type Query {
a: ID @inaccessible
b: ID @tag(name: "name")
c: ID @deprecated
}
`),
};
Loading