Skip to content

feat(create-plugin): generate RTK Query API clients in the experimental-app-sdk addition - #2890

Draft
amalavet wants to merge 2 commits into
mainfrom
ale/app-sdk-api-client
Draft

amalavet wants to merge 2 commits into
mainfrom
ale/app-sdk-api-client

Conversation

@amalavet

@amalavet amalavet commented Sep 17, 2026

Copy link
Copy Markdown

What this PR does / why we need it:

Extends the experimental-app-sdk addition so an app plugin also gets typed RTK Query clients for its kinds and custom routes, generated the same way core Grafana generates @grafana/api-clients:

src/app-sdk-manifest.json
  → grafana cli write-openapi          (grafana/grafana#132068, main)
  → .config/app-sdk/openapi/*.json     (gitignored)
  → grafana-api-clients generate       (grafana/grafana#132913, @grafana/api-clients bin)
  → src/api/generated/<version>/{baseAPI,index,endpoints.gen}.ts

Added to the scaffold, following the shape of generate-kinds.mjs:

  • .config/app-sdk/generate-api-client.mjs — downloads the pinned Grafana release's grafana binary once into node_modules/.cache/grafana/<version>/ (GRAFANA_BIN overrides), runs write-openapi, then npx grafana-api-clients generate.
  • npm scripts generate:api-client and generate (kinds + clients); existing scripts are never overwritten.
  • dependencies @grafana/api-clients, @reduxjs/toolkit, react-redux.
  • .gitignore entry for the intermediate OpenAPI documents.
  • drift workflow now runs generate and checks src/api/generated too.
  • .config/app-sdk/README.md, kinds/README.md, .config/AGENTS/app-sdk.md describe the hooks and store wiring.

Today every app plugin hand-rolls a getBackendSrv() wrapper per kind; this gives them the same generated hooks core's frontend uses (useList<Kind>Query, useCreate<Kind>Mutation, …), with cache invalidation, for free.

Which issue(s) this PR fixes:

Related to grafana/grafana-app-sdk#1493, grafana/grafana-app-platform-squad#111

Special notes for your reviewer:

  • Depends on two unreleased pieces in grafana/grafana; both are usable today without waiting:
    • grafana cli write-openapi is on main only. The script pins nightly build 13.3.0-35040200895 (commit b8b4b49a, resolvable via the build id = Actions run id) and documents how to pick another. Switch to 13.3.0 once tagged.
    • The grafana-api-clients bin is API Clients: add grafana-api-clients generate CLI for app plugins grafana#132913. The script installs @grafana/api-clients@^13.3.0 on first run; until that is on npm, GRAFANA_PR=132913 npm run generate:api-client installs the tarball that PR's CI built (every grafana PR packs all @grafana/* into the buildPr artifact) using gh. The addition itself no longer adds @grafana/api-clients to package.json, so add experimental-app-sdk installs cleanly.
  • Verified end to end on grafana/grafana-app-sdk-testing-plugin (kind + status + 3 custom routes): add experimental-app-sdk from this branch on a clean checkout, then GRAFANA_PR=132913 npm run generate:api-client — installed the PR build, downloaded Grafana, rendered v0alpha1 + v1alpha1, generated both clients; tsc reports 0 errors in src/api/generated.
  • Idempotent like the rest of the addition: re-running skips existing files/scripts/gitignore entry.
  • Steve: this branches from upstream main, not your fork (the addition isn't on stevesg/main). Happy to retarget.

PR involved assistance from anthropic:claude-fable-5-1

@cla-assistant

cla-assistant Bot commented Sep 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Sep 17, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@grafana-catalog-project-bot grafana-catalog-project-bot Bot moved this from 📬 Triage to 🧑‍💻 In development in Grafana Catalog Team Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🧑‍💻 In development

Development

Successfully merging this pull request may close these issues.

1 participant