Skip to content

Commit

Permalink
fix: edfs__NatsStreamConfiguration validation (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
alepane21 authored Dec 18, 2024
1 parent 4ff287a commit d453eab
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 141 deletions.
110 changes: 55 additions & 55 deletions composition-go/index.global.js

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions composition/src/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ import {
subgraphInvalidSyntaxError,
subgraphValidationError,
subgraphValidationFailureError,
undefinedNatsStreamConfigurationInputErrorMessage,
undefinedObjectLikeParentError,
undefinedRequiredArgumentsErrorMessage,
undefinedTypeError,
unexpectedKindFatalError,
} from '../errors/errors';
import {
AUTHENTICATED,
CONSUMER_INACTIVE_THRESHOLD,
CONSUMER_NAME,
DEFAULT_EDFS_PROVIDER_ID,
EDFS_KAFKA_PUBLISH,
Expand All @@ -167,10 +167,11 @@ import {
INACCESSIBLE,
KEY,
MUTATION,
NOT_APPLICABLE,
NON_NULLABLE_BOOLEAN,
NON_NULLABLE_EDFS_PUBLISH_EVENT_RESULT,
NON_NULLABLE_INT,
NON_NULLABLE_STRING,
NOT_APPLICABLE,
OPERATION_TO_DEFAULT,
OVERRIDE,
PROVIDER_ID,
Expand All @@ -196,7 +197,6 @@ import {
SUCCESS,
TOPIC,
TOPICS,
CONSUMER_INACTIVE_THRESHOLD,
} from '../utils/string-constants';
import { buildASTSchema } from '../buildASTSchema/buildASTSchema';
import { ConfigurationData, EventConfiguration, NatsEventType } from '../router-configuration/router-configuration';
Expand Down Expand Up @@ -1697,20 +1697,38 @@ export class NormalizationFactory {
if (streamConfigurationInputData.kind !== Kind.INPUT_OBJECT_TYPE_DEFINITION) {
return false;
}
if (streamConfigurationInputData.inputValueDataByValueName.size != 2) {
if (streamConfigurationInputData.inputValueDataByValueName.size != 3) {
return false;
}
const requiredInputValueNames = new Set<string>([CONSUMER_NAME, STREAM_NAME]);
for (const [inputValueName, inputValueData] of streamConfigurationInputData.inputValueDataByValueName) {
if (!requiredInputValueNames.has(inputValueName)) {
return false;
}
requiredInputValueNames.delete(inputValueName);
if (printTypeNode(inputValueData.type) !== NON_NULLABLE_STRING) {
return false;
switch (inputValueName) {
case CONSUMER_INACTIVE_THRESHOLD: {
if (printTypeNode(inputValueData.type) !== NON_NULLABLE_INT) {
return false;
}
if (
!inputValueData.defaultValue ||
inputValueData.defaultValue.kind !== Kind.INT ||
inputValueData.defaultValue.value !== `${DEFAULT_CONSUMER_INACTIVE_THRESHOLD}`
) {
return false;
}
break;
}
case CONSUMER_NAME:
// intentional fallthrough
case STREAM_NAME: {
if (printTypeNode(inputValueData.type) !== NON_NULLABLE_STRING) {
return false;
}
break;
}
default: {
return false;
}
}
}
return requiredInputValueNames.size < 1;
return true;
}

validateEventDrivenSubgraph(definitions: Array<DefinitionNode>) {
Expand Down
1 change: 1 addition & 0 deletions composition/src/utils/string-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const NOT_APPLICABLE = 'N/A';
export const NAME = 'name';
export const NON_NULLABLE_EDFS_PUBLISH_EVENT_RESULT = 'edfs__PublishResult!';
export const NON_NULLABLE_BOOLEAN = 'Boolean!';
export const NON_NULLABLE_INT = 'Int!';
export const NON_NULLABLE_STRING = 'String!';
export const NOT_UPPER = 'NOT';
export const NULL = 'Null';
Expand Down
Loading

0 comments on commit d453eab

Please sign in to comment.