cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

feat: support grpc plugins with ts and bun

Open SkArchon opened this issue 1 month ago • 6 comments

This PR implements typescript plugins with bun.

  • There are no changes in the router, because we build a binary in the same name format it expects {platform}-{arch}

  • This PR also removes the template TS constants into template files, which are appended into the previous constants dynamically. This makes it easier to manage a growing number of templates, instead of going through TS strings. Includes a CI check to verify that any template changes are generated and committed.

  • To keep thing simple we didn't add a separate folder for the ts router plugin router-plugin-ts, this will be done in a follow up pr, after everything is approved.

  • The node health check package dynamically loads fs using an eval causing a null error when bundled with bun, it works when not bundled. https://github.com/protobufjs/protobuf.js/issues/997#issuecomment-3183117147, adds a workaround for now, to investigate further. We also used bun patch to override the internal __dirname because it is hardcoded to the directory the binary was compiled at on compile time (this especially breaks cosmo cloud plugins since the docker directory is temporary for building).

  • Adds courses demo

Summary by CodeRabbit

  • New Features

    • Multi-language plugin support: create, generate, test and build TypeScript (Bun) plugins alongside Go plugins with automatic language detection and appropriate templates.
    • New TypeScript plugin demo and project scaffolds included.
  • Chores

    • Bun toolchain and CI setup added; template compilation and build scripts updated to support TS/Bun workflows.

Checklist

  • [ ] I have discussed my proposed changes in an issue and have received approval to proceed.
  • [ ] I have followed the coding standards of the project.
  • [ ] Tests or benchmarks have been added or updated.
  • [ ] Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • [ ] I have read the Contributors Guide.

SkArchon avatar Oct 22 '25 15:10 SkArchon

[!IMPORTANT]

Review skipped

Review was skipped due to path filters

:no_entry: Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds language-aware plugin generation/build/test flows (Go and TypeScript/Bun), replaces single goModulePath with structured ProtoOption[] across proto generation, introduces many TS and Go templates, updates toolchain to be language-aware, adds template compiler and CI steps, and adds a demo Bun plugin with tests.

Changes

Cohort / File(s) Summary
CLI plugin commands
cli/src/commands/router/commands/plugin/commands/build.ts, cli/src/commands/router/commands/plugin/commands/generate.ts, cli/src/commands/router/commands/plugin/commands/init.ts, cli/src/commands/router/commands/plugin/commands/test.ts
Add language detection/guarding; branch flows for go vs ts; switch to ProtoOption[] for proto generation; update signatures, render contexts, and error handling.
Toolchain & runtime helpers
cli/src/commands/router/commands/plugin/toolchain.ts
Large refactor: language-specific host/platform resolution and tool mappings; add getLanguage, validateAndGetGoModulePath, getGoModulePathProtoOption; add TS helpers (installTsDependencies, typeCheckTs, runTsTests, buildTsBinaries); rename buildBinariesbuildGoBinaries; propagate language and protoOptions.
Template compiler & packaging
cli/scripts/compile-templates.ts, cli/package.json, .github/workflows/cli-ci.yaml
Add template compilation script, prebuild scripts to compile templates, and CI step to run template compilation.
Templates — core / export surface
cli/src/commands/router/commands/plugin/templates/plugin.ts, cli/src/commands/router/commands/plugin/templates/project.ts, cli/src/commands/router/commands/plugin/templates/plugin/*, cli/src/commands/router/commands/plugin/templates/project/*
Restructure exported template keys (rename/remove/add entries: gitignore, makefile, cursorignore, readmePluginMd, schemaGraphql, graphYaml, routerConfigYaml, etc.).
Templates — Go
cli/src/commands/router/commands/plugin/templates/go.ts, cli/src/commands/router/commands/plugin/templates/go/*
Add Go-specific templates: Dockerfile, go.mod.template, main.go.template, tests, README partials, cursor rules, and export surface for Go templates.
Templates — TypeScript / Bun
cli/src/commands/router/commands/plugin/templates/typescript.ts, cli/src/commands/router/commands/plugin/templates/typescript/*
Add TS/Bun templates: package.json.template, plugin.ts.template, plugin-server.ts.template, tests, tsconfig, Dockerfile, debug/build scripts, health proto patch and protobufjs inquire patch.
Protobuf/GraphQL tooling (protographic)
protographic/src/sdl-to-proto-visitor.ts, protographic/src/index.ts, protographic/tests/sdl-to-proto/*
Replace goPackage?: string with protoOptions?: ProtoOption[]; add exported ProtoOption type; emit proto options from protoOptions; update tests to new shape.
gRPC service codegen callsites
cli/src/commands/grpc-service/commands/generate.ts
Build and pass ProtoOption[] (via getGoModulePathProtoOption) to compileGraphQLToProto instead of raw goPackage string.
Install tooling script
scripts/install-proto-tools.sh
Add Bun/Node download/install helpers, bun/node platform mappings, and language-aware install flow with INSTALL_COMMON_TOOLS toggle.
CI/workflows & Makefiles
.github/workflows/router-ci.yaml, .github/workflows/cli-ci.yaml, demo/Makefile
Add Bun setup step in router CI, template compile step in CLI CI, extend demo Makefile with Bun/Go build targets and integration copy steps.
Demo — Courses plugin (TS/Bun)
demo/pkg/subgraphs/courses/*
Add new TypeScript/Bun demo plugin: package.json, tsconfig.json, schema.graphql, src/plugin.ts, src/plugin-server.ts, tests, patches, and integrate into demo graph/Makefile.
Router tests
router-tests/router_plugin_test.go
Expand tests to cover courses plugin scenarios and additional request cases; add restart tests and split assertions for clarity.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

  • Files/areas to focus on:
    • cli/src/commands/router/commands/plugin/toolchain.ts — platform mappings, language branching, tool install and version logic, and protoOptions propagation.
    • CLI command wiring (build.ts, generate.ts, init.ts, test.ts) — language detection, signature changes, and error short-circuits.
    • protographic/src/sdl-to-proto-visitor.ts and related exports/tests — correctness of emitted proto option lines and API compatibility.
    • Template compiler cli/scripts/compile-templates.ts and resulting template modules — property naming, escaping, and runtime expectations.
    • Demo Bun plugin, patches, and CI changes — build/test/runtime stability (Bun/Node integration).

Possibly related PRs

  • wundergraph/cosmo#2079 — Implements similar multi-language plugin/toolchain and template scaffolding changes; likely touches the same CLI/toolchain surfaces.
  • wundergraph/cosmo#2037 — Related changes to proto option handling in the SDL→proto visitor; overlaps with the protographic refactor to ProtoOption[].
  • wundergraph/cosmo#2008 — Alters generateProtoAndMapping and proto-generation callsites; appears to modify the same function signature and related code paths.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.44% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature being added: support for TypeScript and Bun-based gRPC plugins.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 22 '25 15:10 coderabbitai[bot]

Router image scan passed

:white_check_mark: No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-0798c30d4b8861887fe72a344d9e336ba5e14c60

github-actions[bot] avatar Oct 22 '25 15:10 github-actions[bot]

@coderabbitai full review

SkArchon avatar Oct 29 '25 15:10 SkArchon

✅ Actions performed

Full review triggered.

coderabbitai[bot] avatar Oct 29 '25 15:10 coderabbitai[bot]

@coderabbitai review

SkArchon avatar Oct 29 '25 15:10 SkArchon

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Oct 29 '25 15:10 coderabbitai[bot]

I don't see any integration tests in the router that call the Courses subgraph.

Noroth avatar Nov 17 '25 08:11 Noroth

FYI: Discussed with Dustin that we only install tools specific per language (right now we install bun when using go plugins), will update and push soon

SkArchon avatar Nov 18 '25 11:11 SkArchon

@coderabbitai review

SkArchon avatar Nov 18 '25 18:11 SkArchon

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Nov 18 '25 18:11 coderabbitai[bot]

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Nov 18 '25 18:11 coderabbitai[bot]