Skip to content

Commit

Permalink
feat: support edfs subscription stream/consumer; multiple subjects (#685
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Aenimus authored Apr 9, 2024
1 parent 2c112ae commit c70b2ae
Show file tree
Hide file tree
Showing 35 changed files with 2,017 additions and 756 deletions.
2 changes: 1 addition & 1 deletion aws-lambda-router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ require (
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.16 // indirect
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.18 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.23.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions aws-lambda-router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ github.com/vektah/gqlparser/v2 v2.5.10 h1:6zSM4azXC9u4Nxy5YmdmGu4uKamfwsdKTwp5zs
github.com/vektah/gqlparser/v2 v2.5.10/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc=
github.com/wundergraph/cosmo/router v0.0.0-20240408162133-ab9e5ff1354c h1:V4Vck4bCtke9pQakVfwuIUSePTsfXGq0VajkUjM04sk=
github.com/wundergraph/cosmo/router v0.0.0-20240408162133-ab9e5ff1354c/go.mod h1:lqE0/08ftrRa9MHslKl4xbsjkLh9NNXxF7qHWRDdF04=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.16 h1:9H/pLmwEPZmM6iIv7N5wXGGgEKxGW14ewWFW+qfpZAQ=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.16/go.mod h1:e71oBiNorTfjTi6eDRCFoIoJiFWcwiQ0eObm75VzJh0=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.18 h1:usS2RAwc/isWbj/xNQGrl3Ss0N3wKNSJwAoDn/S0a4U=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.18/go.mod h1:e71oBiNorTfjTi6eDRCFoIoJiFWcwiQ0eObm75VzJh0=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
Expand Down
388 changes: 205 additions & 183 deletions composition-go/index.global.js

Large diffs are not rendered by default.

104 changes: 95 additions & 9 deletions composition/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,8 @@ export function orScopesLimitError(maxOrScopes: number, hostPaths: string[]): Er

export function invalidEventDrivenGraphError(errorMessages: string[]): Error {
return new Error(
`An "Event Driven" graph—a subgraph that defines event driven directives ("@eventsPublish", "@eventsRequest", and` +
` "@eventsPublish")—must not define any resolvers. Consequently, any "@key" definitions must also include the` +
`An "Event Driven" graph—a subgraph that defines event driven directives ("@edfs__publish", "@edfs__request", and` +
` "@edfs__publish")—must not define any resolvers. Consequently, any "@key" definitions must also include the` +
` "resolvable: false" argument. Moreover, only fields that compose part of an entity's (composite) key and are` +
` declared "@external" are permitted.\n` +
errorMessages.join('\n'),
Expand All @@ -949,8 +949,8 @@ export function invalidRootTypeFieldEventsDirectivesErrorMessage(
): string {
let message =
` Root type fields defined in an Event Driven graph must define a valid events` +
` directive:\n Mutation type fields must define either "@eventsPublish" or "@eventsRequest"\n` +
` Query type fields must define "@eventsRequest"\n Subscription type fields must define "@eventsSubscribe"\n` +
` directive:\n Mutation type fields must define either "@edfs__publish" or "@edfs__request"\n` +
` Query type fields must define "@edfs__request"\n Subscription type fields must define "@edfs__subscribe"\n` +
` The following root field path` +
(invalidEventsDirectiveDataByRootFieldPath.size > 1 ? 's are' : ' is') +
`invalid:\n`;
Expand All @@ -969,12 +969,12 @@ export function invalidRootTypeFieldEventsDirectivesErrorMessage(
return message;
}

export function invalidEventsDrivenMutationResponseTypeErrorMessage(
export function invalidEventDrivenMutationResponseTypeErrorMessage(
invalidResponseTypeStringByMutationPath: Map<string, string>,
): string {
let message =
` Mutation type fields defined in an Event Driven graph must return the non-nullable type` +
` "PublishEventResult!", which has the following definition:\n type PublishEventResult {\n` +
` "edfs__PublishResult!", which has the following definition:\n type edfs__PublishResult {\n` +
` success: Boolean!\n }\n However, the following mutation field path` +
(invalidResponseTypeStringByMutationPath.size > 1 ? `s are` : ` is`) +
` invalid:\n`;
Expand All @@ -999,6 +999,62 @@ export function invalidRootTypeFieldResponseTypesEventDrivenErrorMessage(
return message;
}

export const invalidEventDrivenStreamConfigurationInputErrorMessage =
`The "streamConfiguration" argument must be a valid input object with the following form:\n` +
` input edfs__StreamConfiguration {\n consumer: String!\n streamName: String!\n }`;

export function invalidEventDrivenStreamConfigurationInputFieldsErrorMessage(
missingRequiredFieldNames: string[],
duplicateRequiredFieldNames: string[],
invalidRequiredFieldNames: string[],
invalidFieldNames: string[],
): string {
let message = invalidEventDrivenStreamConfigurationInputErrorMessage;
const errorMessages: string[] = [];
if (missingRequiredFieldNames.length > 0) {
errorMessages.push(
`The following required field` +
(missingRequiredFieldNames.length > 1 ? `s were` : ` was`) +
` not defined: "` +
missingRequiredFieldNames.join(QUOTATION_JOIN) +
`".`,
);
}
if (duplicateRequiredFieldNames.length > 0) {
errorMessages.push(
`The following required field` +
(duplicateRequiredFieldNames.length > 1 ? `s were` : ` was`) +
` defined more than once: "` +
duplicateRequiredFieldNames.join(QUOTATION_JOIN) +
`".`,
);
}
if (invalidRequiredFieldNames.length > 0) {
errorMessages.push(
`The following required field` +
(invalidRequiredFieldNames.length > 1 ? `s were` : ` was`) +
` not type "String!" with a minimum length of 1: "` +
invalidRequiredFieldNames.join(QUOTATION_JOIN) +
`".`,
);
}
if (invalidFieldNames.length > 0) {
errorMessages.push(
`The following field` +
(invalidFieldNames.length > 1 ? `s are` : ` is`) +
` not part of a valid "edfs__StreamConfiguration" input definition: "` +
invalidFieldNames.join(QUOTATION_JOIN) +
`".`,
);
}
message +=
`\n However, the provided input was invalid for the following reason` +
(errorMessages.length > 1 ? `s` : ``) +
`:\n ` +
errorMessages.join(`\n `);
return message;
}

export function invalidKeyFieldSetsEventDrivenErrorMessage(
invalidKeyFieldSetsByEntityTypeName = new Map<string, string[]>(),
): string {
Expand Down Expand Up @@ -1062,9 +1118,19 @@ export function nonKeyComposingObjectTypeNamesEventDrivenErrorMessage(typeNames:
);
}

export const invalidPublishEventResultObjectErrorMessage =
` The object "PublishEventResult" that was defined in the Event Driven graph is invalid and must instead have` +
` the following definition:\n type PublishEventResult {\n success: Boolean!\n }`;
export const invalidEdfsPublishResultObjectErrorMessage =
` The object "edfs__PublishResult" that was defined in the Event Driven graph is invalid and must instead have` +
` the following definition:\n type edfs__PublishResult {\n success: Boolean!\n }`;

export const undefinedStreamConfigurationInputErrorMessage =
` The input object "edfs__StreamConfiguration" must be defined in the event-driven graph to satisfy the` +
`"@edfs__subscribe" directive.\n Define the following input in your event-driven graph:\n` +
` input edfs__StreamConfiguration {\n consumer: String!\n streamName: String!\n }`;

export const invalidStreamConfigurationInputErrorMessage =
` The input object "edfs__StreamConfiguration" that was defined in the Event Driven graph is invalid and must` +
` instead have the following definition:\n input edfs__StreamConfiguration {\n` +
` consumer: String!\n streamName: String!\n }`;

export function invalidImplementedTypeError(
typeName: string,
Expand All @@ -1084,3 +1150,23 @@ export function invalidImplementedTypeError(
export function selfImplementationError(typeName: string): Error {
return new Error(` The interface "${typeName}" must not implement itself.`);
}

export const invalidEventSubjectErrorMessage = `The "subject" argument must be string with a minimum length of one.`;

export const invalidEventSubjectsErrorMessage = `The "subjects" argument must be a list of strings.`;

export const invalidEventSubjectsItemErrorMessage =
`Each item in the "subjects" argument list must be a string with a minimum length of one.` +
` However, at least one value provided in the list was invalid.`;

export const invalidEventSourceNameErrorMessage = `If explicitly defined, the "sourceName" argument must be a string with a minimum length of one.`;

export function invalidEventDirectiveError(directiveName: string, fieldPath: string, errorMessages: string[]): Error {
return new Error(
`The event directive "${directiveName}" declared on "${fieldPath}" is invalid for the following` +
` reason` +
(errorMessages.length > 1 ? `s` : ``) +
`:\n ` +
errorMessages.join(`\n `),
);
}
Loading

0 comments on commit c70b2ae

Please sign in to comment.