From 22ab0d6cf4d5c5413552021ac508a19d7232e9fc Mon Sep 17 00:00:00 2001 From: SirLouen Date: Sat, 21 Nov 2026 22:51:33 +0100 Subject: [PATCH 1/2] feat(pluginkit): read a plugin's graphql key from its manifest --- pluginkit/wire/manifest.go | 6 ++- pluginkit/wire/manifest_identity_test.go | 3 +- pluginkit/wire/manifest_index_test.go | 7 ++-- pluginkit/wire/manifest_keys_test.go | 5 ++- pluginkit/wire/manifest_test.go | 47 +++++++++++++++++++----- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/pluginkit/wire/manifest.go b/pluginkit/wire/manifest.go index 5564523..bcc7eec 100644 --- a/pluginkit/wire/manifest.go +++ b/pluginkit/wire/manifest.go @@ -20,6 +20,8 @@ type Manifest struct { Name string `json:"name"` Backend string `json:"backend,omitempty"` Frontend string `json:"frontend,omitempty"` + // GraphQL marks a plugin whose backend extends the application's GraphQL API. + GraphQL bool `json:"graphql,omitempty"` Description string `json:"description,omitempty"` Version string `json:"version,omitempty"` @@ -120,8 +122,8 @@ type manifest Manifest // typedKeys are the manifest keys Manifest has a field for. var typedKeys = []string{ - "id", "name", "backend", "frontend", "description", "version", "license", "did", "requires", "tested", "engines", - "uninstall", "hooks", "defines", "jobs", "settings", "menu", "screens", "screen_capabilities", + "id", "name", "backend", "frontend", "graphql", "description", "version", "license", "did", "requires", "tested", + "engines", "uninstall", "hooks", "defines", "jobs", "settings", "menu", "screens", "screen_capabilities", } // isTypedKey reports whether key is the json name of a field of Manifest. diff --git a/pluginkit/wire/manifest_identity_test.go b/pluginkit/wire/manifest_identity_test.go index e6a8e6d..25ff1f0 100644 --- a/pluginkit/wire/manifest_identity_test.go +++ b/pluginkit/wire/manifest_identity_test.go @@ -13,7 +13,8 @@ import ( ) // everyNewKey is every key a manifest may name beside the ones wire has always read. -const everyNewKey = `"description": "Sells seats for the events a site holds.", +const everyNewKey = `"graphql": true, + "description": "Sells seats for the events a site holds.", "version": "2.0.0", "license": "Apache-2.0", "did": "did:plc:example", diff --git a/pluginkit/wire/manifest_index_test.go b/pluginkit/wire/manifest_index_test.go index 8c839a2..a3b3ebc 100644 --- a/pluginkit/wire/manifest_index_test.go +++ b/pluginkit/wire/manifest_index_test.go @@ -38,6 +38,7 @@ const fullIndex = `[ "name": "Events", "backend": "example.com/myapp/plugins/events", "frontend": "@myapp/plugin-events", + "graphql": true, "description": "Sells seats for the events a site holds.", "version": "2.0.0", "license": "Apache-2.0", @@ -115,7 +116,7 @@ const fullIndex = `[ "screen_capabilities": { "seats": "events.manage" }, - "graphql": true + "myapp_featured": true }, { "id": "feed", @@ -169,8 +170,8 @@ func TestManifestIndexLeavesOutAnAbsentOrEmptyOptionalKey(t *testing.T) { t.Parallel() got := runForIndex(t, map[string]string{ - "feed": withKeys(feedManifest, - `"uninstall": false, "engines": [], "requires": {}, "settings": [{"key": "seats", "type": "count"}]`), + "feed": withKeys(feedManifest, `"graphql": false, "uninstall": false, "engines": [], "requires": {}, `+ + `"settings": [{"key": "seats", "type": "count"}]`), }) want := `[ diff --git a/pluginkit/wire/manifest_keys_test.go b/pluginkit/wire/manifest_keys_test.go index 7fbc8db..f502039 100644 --- a/pluginkit/wire/manifest_keys_test.go +++ b/pluginkit/wire/manifest_keys_test.go @@ -14,6 +14,7 @@ func wrongCaseKeys() map[string]wrongShape { `"DESCRIPTION": "Sells seats"`, `the key "DESCRIPTION" must be spelled "description"`, }, "a top level key in mixed case": {`"Version": "2.0.0"`, `the key "Version" must be spelled "version"`}, + "graphql spelled as its Go field": {`"GraphQL": true`, `the key "GraphQL" must be spelled "graphql"`}, "a top level key beside its own spelling": {`"Name": "Other"`, `the key "Name" must be spelled "name"`}, "a top level key with an underscore": { `"Screen_Capabilities": {"seats": "a"}`, `the key "Screen_Capabilities" must be spelled "screen_capabilities"`, @@ -84,7 +85,7 @@ func repeatedKeys() map[string]wrongShape { func TestLoadReadsAKeyOfDataAsWritten(t *testing.T) { t.Parallel() - got := feedWith(t, `"GraphQL": true, "note": 1, "Note": 2, "ver-sion": "a", "ver_sion": "b", `+ + got := feedWith(t, `"Featured": true, "note": 1, "Note": 2, "ver-sion": "a", "ver_sion": "b", `+ `"pages": [{"Word": "forums", "word": "topics"}], "requires": {"App": ">=1", "app": ">=2"}, `+ `"screen_capabilities": {"Seats": "events.manage"}, "settings": [{"key": "a", "type": "b", "Note": 1}]`) @@ -92,7 +93,7 @@ func TestLoadReadsAKeyOfDataAsWritten(t *testing.T) { assertSame(t, got.ScreenCapabilities, map[string]string{"Seats": "events.manage"}) assertSame(t, got.Settings, []Setting{{Key: "a", Type: "b"}}) assertSame(t, got.Extra, map[string]json.RawMessage{ - "GraphQL": json.RawMessage(`true`), + "Featured": json.RawMessage(`true`), "note": json.RawMessage(`1`), "Note": json.RawMessage(`2`), "ver-sion": json.RawMessage(`"a"`), diff --git a/pluginkit/wire/manifest_test.go b/pluginkit/wire/manifest_test.go index 5069b59..bec72b1 100644 --- a/pluginkit/wire/manifest_test.go +++ b/pluginkit/wire/manifest_test.go @@ -18,6 +18,7 @@ const fullManifest = `{ "name": "Events", "backend": "example.com/myapp/plugins/events", "frontend": "@myapp/plugin-events", + "graphql": true, "description": "Sells seats for the events a site holds.", "version": "2.0.0", "license": "Apache-2.0", @@ -43,7 +44,7 @@ const fullManifest = `{ ], "screens": "@myapp/plugin-events/screens", "screen_capabilities": {"seats": "events.manage"}, - "graphql": true + "myapp_featured": true }` // number returns a pointer to value, as a setting's limits hold it. @@ -63,6 +64,7 @@ func fullManifestRead() Manifest { Name: "Events", Backend: "example.com/myapp/plugins/events", Frontend: "@myapp/plugin-events", + GraphQL: true, Description: "Sells seats for the events a site holds.", Version: "2.0.0", License: "Apache-2.0", @@ -94,7 +96,7 @@ func fullManifestRead() Manifest { }, Screens: "@myapp/plugin-events/screens", ScreenCapabilities: map[string]string{"seats": "events.manage"}, - Extra: map[string]json.RawMessage{"graphql": json.RawMessage(`true`)}, + Extra: map[string]json.RawMessage{"myapp_featured": json.RawMessage(`true`)}, } } @@ -297,24 +299,48 @@ func TestADescriptionReachesTheIndexAndReadsBack(t *testing.T) { assertSame(t, read, written) } +func TestLoadReadsTheGraphqlKeyIntoItsOwnFieldAndNotIntoExtra(t *testing.T) { + t.Parallel() + + got := feedWith(t, `"graphql": true`) + + assertSame(t, got.GraphQL, true) + assertSame(t, got.Extra, map[string]json.RawMessage(nil)) +} + +func TestTheGraphqlKeyReachesTheIndexBesideTheFrontendAndReadsBack(t *testing.T) { + t.Parallel() + + written := Manifest{ID: "feed", Name: "Feed", Frontend: "@myapp/plugin-feed", GraphQL: true, Version: "1.0.0"} + + data, err := json.Marshal(written) + + assertErrorFree(t, err) + assertSame(t, string(data), + `{"id":"feed","name":"Feed","frontend":"@myapp/plugin-feed","graphql":true,"version":"1.0.0"}`) + var read Manifest + assertErrorFree(t, json.Unmarshal(data, &read)) + assertSame(t, read, written) +} + func TestLoadKeepsAnUnknownKeyInExtra(t *testing.T) { t.Parallel() - got := feedWith(t, `"graphql": true, "pages": [{"word": "forums"}], "note": null`) + got := feedWith(t, `"myapp_featured": true, "pages": [{"word": "forums"}], "note": null`) assertSame(t, got.Extra, map[string]json.RawMessage{ - "graphql": json.RawMessage(`true`), - "pages": json.RawMessage(`[{"word": "forums"}]`), - "note": json.RawMessage(`null`), + "myapp_featured": json.RawMessage(`true`), + "pages": json.RawMessage(`[{"word": "forums"}]`), + "note": json.RawMessage(`null`), }) } func TestLoadReadsANullAsAnAbsentKey(t *testing.T) { t.Parallel() - got := feedWith(t, `"description": null, "version": null, "requires": null, "engines": null, "uninstall": null, `+ - `"hooks": null, "defines": null, "jobs": null, "settings": null, "menu": null, "screens": null, `+ - `"screen_capabilities": null`) + got := feedWith(t, `"graphql": null, "description": null, "version": null, "requires": null, "engines": null, `+ + `"uninstall": null, "hooks": null, "defines": null, "jobs": null, "settings": null, "menu": null, `+ + `"screens": null, "screen_capabilities": null`) want, err := loadOne(t, "feed", feedManifest) assertErrorFree(t, err) @@ -423,6 +449,9 @@ type wrongShape struct{ keys, want string } // wrongTypes lists keys of the wrong JSON type, and what the decoder says of each. func wrongTypes() map[string]wrongShape { return map[string]wrongShape{ + "a string for graphql": { + `"graphql": "yes"`, "json: cannot unmarshal string into Go struct field manifest.graphql of type bool", + }, "a number for description": { `"description": 5`, "json: cannot unmarshal number into Go struct field manifest.description of type string", From 74d9bdad54c147bffd72904e8892f8c7c8769553 Mon Sep 17 00:00:00 2001 From: SirLouen Date: Sat, 21 Nov 2026 22:51:33 +0100 Subject: [PATCH 2/2] docs(pluginkit): list the graphql manifest field under Unreleased --- pluginkit/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pluginkit/CHANGELOG.md b/pluginkit/CHANGELOG.md index ada4747..fdc0f80 100644 --- a/pluginkit/CHANGELOG.md +++ b/pluginkit/CHANGELOG.md @@ -13,6 +13,7 @@ Releases of this module are tagged `pluginkit/vX.Y.Z`. Releases up to - `pluginstoretest.Run` checks any `PluginStore` against the contract, and `pluginstoretest.NewMemory` is a store in memory that keeps it. - `Installed` lists one `InstalledPlugin` per installed plugin, with the JSON names `id`, `name`, `description`, `version`, `status`, `paused_step` and `paused_reason`, sorted by name without regard to case, then by id. It leaves out a plugin the records hold as not installed and a record with no manifest, and lists a manifest with no record as active. The step and the reason are empty unless the plugin is paused. - `wire.Manifest` reads `description`, which no longer sits in `Extra`, a breaking change. +- `wire.Manifest` reads `graphql` as `GraphQL`, which no longer sits in `Extra`, a breaking change. - `wire` rejects a manifest that spells a key it reads in another case, such as `Name`, repeats a name in one object, or holds text that is not valid UTF-8, as bytes or as an escaped surrogate with no pair, a breaking change. - `RegisterEach` and `Register` take only plugins with an `ID() string` method, and fail at `StepRegister` a plugin whose `ID` is not its entry's id, or a `Register` that answers no plugin, a breaking change. - `Protect` takes the plugin's id and a `RouteSettings`, which holds the middleware as `Wrap`, a breaking change.