Skip to content

Commit

Permalink
feat: refactor edfs and add kafka support (#770)
Browse files Browse the repository at this point in the history
Co-authored-by: Aenimus <daviditstutt@gmail.com>
  • Loading branch information
StarpTech and Aenimus authored May 14, 2024
1 parent 486e3a1 commit d659067
Show file tree
Hide file tree
Showing 98 changed files with 4,599 additions and 2,148 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/router-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ jobs:
with:
fetch-depth: 0

- name: Log in to Docker Container registry (With write access)
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{secrets.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_PASSWORD}}

- uses: actions/cache@v4
with:
path: |
Expand Down Expand Up @@ -181,5 +188,4 @@ jobs:
dockerfile: router/Dockerfile
token: ${{secrets.GITHUB_TOKEN}}
image_name: router
image_description: "Cosmo Router"

image_description: "Cosmo Router"
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ prerequisites: setup-dev-tools

infra-up: dc-dev

edfs-infra-up:
docker compose -f docker-compose.yml --profile edfs up --remove-orphans --detach

edfs-infra-down:
docker compose -f docker-compose.yml --profile edfs down --remove-orphans

infra-down:
docker compose -f docker-compose.yml down --remove-orphans
docker compose -f docker-compose.yml --profile dev down --remove-orphans

infra-build:
docker compose -f docker-compose.yml build
docker compose -f docker-compose.yml --profile dev build

infra-restart:
docker compose -f docker-compose.yml down && make infra-up
docker compose -f docker-compose.yml --profile dev down && make infra-up

infra-down-v:
docker compose -f docker-compose.yml down --remove-orphans -v
docker compose -f docker-compose.yml --profile dev down --remove-orphans -v

seed:
pnpm -r run --filter './controlplane' seed
Expand Down Expand Up @@ -85,8 +91,9 @@ start-studio:
start-router:
(cd router && make dev)

DC_FLAGS=
dc-dev:
docker compose --file docker-compose.yml up --remove-orphans --detach --build
docker compose --file docker-compose.yml --profile dev up --remove-orphans --detach $(DC_FLAGS)

dc-stack:
docker compose --file docker-compose.cosmo.yml up --remove-orphans --detach
Expand Down
14 changes: 7 additions & 7 deletions aws-lambda-router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/akrylysov/algnhsa v1.1.0
github.com/aws/aws-lambda-go v1.43.0
github.com/stretchr/testify v1.9.0
github.com/wundergraph/cosmo/router v0.0.0-20240510075230-4f973c1d5647
github.com/wundergraph/cosmo/router v0.0.0-20240506080018-92e5b30c2df6
go.uber.org/zap v1.26.0
)

Expand Down Expand Up @@ -50,14 +50,14 @@ require (
github.com/joho/godotenv v1.5.1 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/kingledion/go-tools v0.6.0 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nats-io/nats.go v1.31.0 // indirect
github.com/nats-io/nkeys v0.4.6 // indirect
github.com/nats-io/nats.go v1.34.1 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -80,7 +80,7 @@ require (
github.com/tidwall/sjson v1.2.5 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.32 // indirect
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.36 // 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 All @@ -100,10 +100,10 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.withmatt.com/connect-brotli v0.4.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
Expand Down
21 changes: 8 additions & 13 deletions aws-lambda-router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ github.com/kingledion/go-tools v0.6.0 h1:y8C/4mWoHgLkO45dB+Y/j0o4Y4WUB5lDTAcMPMt
github.com/kingledion/go-tools v0.6.0/go.mod h1:qcDJQxBui/H/hterGb90GMlLs9Yi7QrwaJL8OGdbsms=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down Expand Up @@ -185,10 +184,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADymtkpts=
github.com/nats-io/nats.go v1.34.1 h1:syWey5xaNHZgicYBemv0nohUPPmaLteiBEUT6Q5+F/4=
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
Expand Down Expand Up @@ -271,10 +268,9 @@ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4d
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8=
github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc=
github.com/wundergraph/cosmo/router v0.0.0-20240510075230-4f973c1d5647 h1:vu9l9YZ887S3R34VTDypttCyJpNSvgps6EkROT2KwEA=
github.com/wundergraph/cosmo/router v0.0.0-20240510075230-4f973c1d5647/go.mod h1:0Os7PmwUcmINmOUcE5TfojzCJNspl+p4Hel2UL+/zgc=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.32 h1:IgHLvbraxK2tKNn/XH4XR+oLQZ7kA71DfejLfmarCrM=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.32/go.mod h1:hNR2C7S1M+c9Ap24tHCEMe9gFY9K3smX46x5E1U1NQw=
github.com/wundergraph/cosmo/router v0.0.0-20240506080018-92e5b30c2df6 h1:SeNEyM5zbBiC6Oq/q7AdCJAyZ75xvP62HX75BOhwTeI=
github.com/wundergraph/cosmo/router v0.0.0-20240506080018-92e5b30c2df6/go.mod h1:0Os7PmwUcmINmOUcE5TfojzCJNspl+p4Hel2UL+/zgc=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.36 h1:d+xvzVPUTjsK0hUrdnfJ1F2fEWGM2OvlopsNW7fG7dw=
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 Expand Up @@ -325,8 +321,7 @@ golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc=
golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -350,8 +345,8 @@ golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
382 changes: 193 additions & 189 deletions composition-go/index.global.js

Large diffs are not rendered by default.

68 changes: 44 additions & 24 deletions composition/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,9 @@ 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 ("@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` +
` "@edfs__publish")—must not define any resolvers.\n` +
`Consequently, any "@key" definitions must also include the "resolvable: false" argument.\n` +
`Moreover, only fields that compose part of an entity's (composite) key and are` +
` declared "@external" are permitted.\n` +
errorMessages.join('\n'),
);
Expand All @@ -968,11 +969,11 @@ 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 "@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` +
` directive:\n Mutation type fields must define either a edfs publish or request directive."\n` +
` Query type fields must define "@edfs__natsRequest"\n Subscription type fields must define an edfs subscribe` +
` directive\n The following root field path` +
(invalidEventsDirectiveDataByRootFieldPath.size > 1 ? 's are' : ' is') +
`invalid:\n`;
` invalid:\n`;
for (const [fieldPath, data] of invalidEventsDirectiveDataByRootFieldPath) {
if (!data.definesDirectives) {
message += ` The root field path "${fieldPath}" does not define any valid events directives.\n`;
Expand Down Expand Up @@ -1018,17 +1019,17 @@ export function invalidRootTypeFieldResponseTypesEventDrivenErrorMessage(
return message;
}

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

export function invalidEventDrivenStreamConfigurationInputFieldsErrorMessage(
export function invalidNatsStreamInputFieldsErrorMessage(
missingRequiredFieldNames: string[],
duplicateRequiredFieldNames: string[],
invalidRequiredFieldNames: string[],
invalidFieldNames: string[],
): string {
let message = invalidEventDrivenStreamConfigurationInputErrorMessage;
let message = invalidNatsStreamInputErrorMessage;
const errorMessages: string[] = [];
if (missingRequiredFieldNames.length > 0) {
errorMessages.push(
Expand Down Expand Up @@ -1061,7 +1062,7 @@ export function invalidEventDrivenStreamConfigurationInputFieldsErrorMessage(
errorMessages.push(
`The following field` +
(invalidFieldNames.length > 1 ? `s are` : ` is`) +
` not part of a valid "edfs__StreamConfiguration" input definition: "` +
` not part of a valid "edfs__NatsStreamConfiguration" input definition: "` +
invalidFieldNames.join(QUOTATION_JOIN) +
`".`,
);
Expand Down Expand Up @@ -1141,16 +1142,22 @@ 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 consumerName: String!\n streamName: String!\n }`;
export const undefinedNatsStreamConfigurationInputErrorMessage =
` The input object "edfs__NatsStreamConfiguration" must be defined in the event-driven graph to satisfy the` +
` "@edfs__natsSubscribe" directive.\n The following input must be defined in the event-driven graph:\n` +
` input edfs__NatsStreamConfiguration {\n consumerName: 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` +
export const invalidNatsStreamConfigurationDefinitionErrorMessage =
` The input object "edfs__NatsStreamConfiguration" that was defined in the Event Driven graph is invalid and must` +
` instead have the following definition:\n input edfs__NatsStreamConfiguration {\n` +
` consumerName: String!\n streamName: String!\n }`;

export function invalidEdfsDirectiveName(directiveName: string): Error {
return new Error(
`Could not retrieve definition for Event-Driven Federated Subscription directive "${directiveName}".`,
);
}

export function invalidImplementedTypeError(
typeName: string,
invalidImplementationTypeStringByTypeName: Map<string, string>,
Expand All @@ -1170,15 +1177,22 @@ 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 function invalidEventSubjectErrorMessage(argumentName: string): string {
return `The "${argumentName}" argument must be string with a minimum length of one.`;
}

export const invalidEventSubjectsErrorMessage = `The "subjects" argument must be a list of strings.`;
export function invalidEventSubjectsErrorMessage(argumentName: string): string {
return `The "${argumentName}" 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 function invalidEventSubjectsItemErrorMessage(argumentName: string): string {
return (
`Each item in the "${argumentName}" 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 const invalidEventProviderIdErrorMessage = `If explicitly defined, the "providerId" argument must be a string with a minimum length of one.`;

export function invalidEventDirectiveError(directiveName: string, fieldPath: string, errorMessages: string[]): Error {
return new Error(
Expand Down Expand Up @@ -1222,3 +1236,9 @@ export function invalidUnionMemberTypeError(typeName: string, invalidMembers: st
invalidMembers.join(`\n `),
);
}

export function invalidRootTypeError(typeName: string): Error {
return new Error(
`Expected type "${typeName}" to be a root type but could not find its respective OperationTypeNode.`,
);
}
Loading

0 comments on commit d659067

Please sign in to comment.