Skip to content

Commit ced739c

Browse files
committed
fix: Simplify build pipeline and remove dead script code
- Wire yarn build:merchandising-api to build-with-enhanced-schema.js so the production build always fetches a fresh schema and injects descriptions - Delete inject-descriptions.js (unused; logic lives in fetch-and-enhance-schema.js) - Remove dead code in build-with-enhanced-schema.js (redundant require, unused export) - Remove unused generateConfig variable in run-spectaql-with-cleanup.js - Remove injectDescriptions from fetch-and-enhance-schema.js exports (not used externally) - Update README.md and spectaql/README.md to reflect the simplified build workflow - Rebuild index.html with latest enhanced schema
1 parent 730fb95 commit ced739c

File tree

9 files changed

+250
-752
lines changed

9 files changed

+250
-752
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ If you have questions, open an issue and ask us. We look forward to hearing from
6060

6161
## GraphQL API reference generator
6262

63-
The Merchandising GraphQL API reference is generated using [SpectaQL](https://github.com/anvilco/spectaql). It uses live introspection against the GraphQL endpoint and a metadata overlay to filter the schema down to the documented queries and types.
63+
The Merchandising GraphQL API reference is generated using [SpectaQL](https://github.com/anvilco/spectaql). It fetches the live schema via introspection, injects custom descriptions from a metadata overlay, and filters the schema down to the include only the queries and types supported by Adobe Commerce Optimizer catalog service operations.
6464

6565
### Quick start
6666

@@ -90,10 +90,10 @@ To generate a live preview during local development, run: `yarn dev:merchandisin
9090
If the schema or metadata descriptions change, rebuild and test the API reference locally:
9191

9292
1. Create a branch from `main`.
93-
2. Regenerate the API reference using the enhanced build (includes custom descriptions):
93+
2. Regenerate the API reference:
9494

9595
```bash
96-
node scripts/build-with-enhanced-schema.js
96+
yarn build:merchandising-api
9797
```
9898

9999
3. Verify the output in your browser.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"test": "remark src/pages --frail",
3434
"build:admin-api": "spectaql --target-file index.html --config spectaql/config-admin.yml",
3535
"dev:admin-api": "spectaql --target-file index.html --config spectaql/config-admin.yml --development-mode",
36-
"build:merchandising-api": "node scripts/run-spectaql-with-cleanup.js --target-file index.html --config spectaql/config-merchandising-temp.yml",
36+
"build:merchandising-api": "node scripts/build-with-enhanced-schema.js",
3737
"dev:merchandising-api": "node scripts/run-spectaql-with-cleanup.js --target-file index.html --config spectaql/config-merchandising-temp.yml --development-mode",
3838
"build:graphql": "yarn build:admin-api && yarn build:merchandising-api",
3939
"lint": "docker run --rm -e RUN_LOCAL=true --env-file .github/super-linter.env -v \"$PWD\":/tmp/lint github/super-linter:slim-v5"

scripts/build-with-enhanced-schema.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ async function buildWithEnhancedSchema() {
2121

2222
// Step 2: Generate SpectaQL config pointing to the enhanced schema
2323
console.log('🚀 Step 2: Generating SpectaQL configuration...');
24-
require('./generate-spectaql-config');
25-
2624
const fs = require('fs');
2725
const { tempConfigPath } = require('./generate-spectaql-config');
2826
let tempConfig = fs.readFileSync(tempConfigPath, 'utf8');
@@ -88,9 +86,4 @@ async function buildWithEnhancedSchema() {
8886
}
8987
}
9088

91-
// Run if called directly
92-
if (require.main === module) {
93-
buildWithEnhancedSchema();
94-
}
95-
96-
module.exports = { buildWithEnhancedSchema };
89+
buildWithEnhancedSchema();

scripts/fetch-and-enhance-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,4 @@ if (require.main === module) {
323323
main();
324324
}
325325

326-
module.exports = { main, injectDescriptions };
326+
module.exports = { main };

scripts/inject-descriptions.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

scripts/run-spectaql-with-cleanup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ if (args.length === 0) {
2121

2222
// First, generate the config file
2323
console.log('Generating SpectaQL configuration...');
24-
const generateConfig = require('./generate-spectaql-config');
2524

2625
// Switch the temp config to use the enhanced schema file instead of the live URL.
2726
// The enhanced-schema.json contains descriptions injected from the metadata file

spectaql/README.md

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This directory contains [SpectaQL](https://github.com/anvilco/spectaql) configur
1515
|---|---|
1616
| `config-merchandising.yml` | Main SpectaQL config. Defines where to get the schema, what to document/hide, metadata paths, server info, intro text, theme, and the output directory (`static/graphql-api/merchandising-api`). |
1717
| `metadata-merchandising.json` | Filtering and description metadata. Marks unwanted queries, types, enums, unions, input objects, and interfaces as `undocumented: true` so SpectaQL excludes them. Also contains custom descriptions for query arguments under `FIELD_ARGUMENT`. |
18-
| `enhanced-schema.json` | Cached introspection result with custom descriptions already injected. Used for enhanced/offline builds instead of hitting the live endpoint. Generated by `scripts/fetch-and-enhance-schema.js`. |
18+
| `enhanced-schema.json` | Cached introspection result with custom descriptions already injected. Used for dev builds instead of hitting the live endpoint on every rebuild. Generated by `scripts/fetch-and-enhance-schema.js`. |
1919
| `config-merchandising-temp.yml` | Auto-generated temp config. A copy of the main config with `${TENANT_ID}` placeholders replaced by the actual environment variable value. Deleted automatically after the build. |
2020
| `config-admin.yml` | Configuration for the Admin API (reference not currently implemented). |
2121
| `comdox-theme/` | Custom SpectaQL theme. Contains Handlebars partial overrides (`type.hbs` and `_query-or-mutation-or-subscription.hbs`) that customize how types and queries render in the HTML output. |
@@ -25,10 +25,9 @@ This directory contains [SpectaQL](https://github.com/anvilco/spectaql) configur
2525
| Script | Role |
2626
|---|---|
2727
| `generate-spectaql-config.js` | Reads `config-merchandising.yml`, substitutes `${TENANT_ID}` from your `.env` file, writes the temp config, and cleans up on exit. |
28-
| `run-spectaql-with-cleanup.js` | Orchestrates the **standard build**: generates the temp config, spawns SpectaQL as a child process, then cleans up the temp file. This is what `yarn build:merchandising-api` runs. |
28+
| `run-spectaql-with-cleanup.js` | Orchestrates the **dev build**: generates the temp config, switches it to use `enhanced-schema.json`, spawns SpectaQL as a child process, then cleans up the temp file. This is what `yarn dev:merchandising-api` runs. |
2929
| `fetch-and-enhance-schema.js` | Fetches a live introspection result from the GraphQL endpoint, then injects custom descriptions from `metadata-merchandising.json` into the raw schema. Saves the result to `enhanced-schema.json`. |
30-
| `inject-descriptions.js` | Standalone module with the same description-injection logic, packaged as a SpectaQL preprocessing function. |
31-
| `build-with-enhanced-schema.js` | Orchestrates the **enhanced build**: (1) fetches and enhances the schema, (2) generates the temp config and rewrites it to point at `enhanced-schema.json` instead of the live URL, (3) runs SpectaQL. |
30+
| `build-with-enhanced-schema.js` | Orchestrates the **production build**: (1) fetches a fresh schema and injects descriptions from `metadata-merchandising.json`, (2) generates the temp config and rewrites it to point at `enhanced-schema.json` instead of the live URL, (3) runs SpectaQL. This is what `yarn build:merchandising-api` runs. |
3231

3332
### Environment and output
3433

@@ -115,55 +114,38 @@ node scripts/fetch-and-enhance-schema.js
115114

116115
## Build commands
117116

118-
There are two build paths. Both produce `static/graphql-api/merchandising-api/index.html`.
117+
Both build paths produce `static/graphql-api/merchandising-api/index.html`.
119118

120-
### Standard build (live endpoint)
119+
### Production build
121120

122-
Uses live introspection to fetch the schema and applies metadata filtering:
121+
Fetches a fresh schema from the live endpoint, injects all custom descriptions from `metadata-merchandising.json`, and runs SpectaQL:
123122

124123
```bash
125124
yarn build:merchandising-api
126-
127-
# Or run in development mode with live preview
128-
yarn dev:merchandising-api
129125
```
130126

131-
What happens during a standard build:
127+
What happens during a production build:
132128

133-
1. `generate-spectaql-config.js` reads the YAML config, replaces `${TENANT_ID}`, and writes the temp config
134-
1. `run-spectaql-with-cleanup.js` spawns SpectaQL with the temp config.
135-
1. SpectaQL introspects the live GraphQL endpoint.
136-
1. SpectaQL applies `metadata-merchandising.json` to filter out unwanted queries/types and inject descriptions via its built-in metadata system
129+
1. `fetch-and-enhance-schema.js` fetches the live introspection result and injects descriptions from `metadata-merchandising.json` directly into the schema JSON.
130+
1. The result is saved to `enhanced-schema.json`.
131+
1. `generate-spectaql-config.js` reads the YAML config, replaces `${TENANT_ID}`, and writes the temp config.
132+
1. The temp config is rewritten to use `introspectionFile: spectaql/enhanced-schema.json` instead of the live URL.
133+
1. SpectaQL runs against the local enhanced schema file.
137134
1. The custom theme partials override the default rendering.
138135
1. Output lands in `static/graphql-api/merchandising-api/index.html`.
139136
1. The temp config file is cleaned up.
140137

141-
### Enhanced build (with description injection)
138+
### Dev build (fast iteration)
142139

143-
The standard build uses the live schema as-is, so any query arguments that lack descriptions in the live schema appear blank. The enhanced build solves this by fetching the live schema, injecting the custom descriptions defined in `metadata-merchandising.json` (especially `FIELD_ARGUMENT` entries), and then running SpectaQL against the enhanced schema.
140+
Uses the existing `enhanced-schema.json` on disk — no live API call. Useful when iterating on metadata descriptions, theme templates, or config without waiting for a schema fetch:
144141

145142
```bash
146-
node scripts/build-with-enhanced-schema.js
147-
```
148-
149-
You can also pass extra SpectaQL flags, for example:
150-
151-
```bash
152-
node scripts/build-with-enhanced-schema.js --development-mode
143+
yarn dev:merchandising-api
153144
```
154145

155-
If you omit all arguments, it defaults to `--target-file index.html --config spectaql/config-merchandising-temp.yml`.
146+
This starts SpectaQL in watch mode with a live preview at `http://localhost:4400`. It rebuilds automatically when source files change.
156147

157-
What happens during an enhanced build:
158-
159-
1. `fetch-and-enhance-schema.js` fetches the live introspection result and injects `FIELD_ARGUMENT` descriptions directly into the schema JSON
160-
1. The result is saved to `enhanced-schema.json`.
161-
1. The temp config is generated and rewritten to use `introspectionFile: spectaql/enhanced-schema.json` instead of the live URL.
162-
1. SpectaQL runs against the local enhanced schema file.
163-
1. Output lands in `static/graphql-api/merchandising-api/index.html`.
164-
1. The temp config file is cleaned up.
165-
166-
Use the enhanced build whenever `metadata-merchandising.json` includes custom descriptions that you want reflected in the generated API reference.
148+
> **Note:** The dev build does not refresh `enhanced-schema.json`. If the live schema has changed or you have updated `metadata-merchandising.json`, run `yarn build:merchandising-api` to get a fresh result.
167149

168150
### Update the cached schema only
169151

@@ -173,24 +155,23 @@ To fetch and enhance the schema without running SpectaQL:
173155
node scripts/fetch-and-enhance-schema.js
174156
```
175157

176-
This saves the result to `enhanced-schema.json`. To use it for offline builds, the config already points to this file via `introspectionFile: spectaql/enhanced-schema.json`.
158+
This saves the result to `enhanced-schema.json` and is useful when you want to inspect the schema before building.
177159

178160
## Update the API reference
179161

180162
If the schema or metadata descriptions change, rebuild and test the API reference locally:
181163

182164
1. Create a branch from `main`.
183-
2. If you updated custom descriptions in `metadata-merchandising.json`, use the enhanced build:
184-
185-
```bash
186-
node scripts/build-with-enhanced-schema.js
187-
```
165+
1. Make your changes to `metadata-merchandising.json`, theme templates, or config.
166+
1. Run the production build to regenerate the schema and documentation:
188167

189-
Otherwise, use the standard build: `yarn build:merchandising-api`
168+
```bash
169+
yarn build:merchandising-api
170+
```
190171

191-
3. Open `static/graphql-api/merchandising-api/index.html` in your browser and verify the output.
192-
4. Commit the updated `index.html` and `enhanced-schema.json` files.
193-
5. After updates are approved, a documentation team member merges the PR and publishes the updates to the [developer site](https://developer.adobe.com/commerce/services/merchandising-services/).
172+
1. Open `static/graphql-api/merchandising-api/index.html` in your browser and verify the output.
173+
1. Commit the updated `index.html` and `enhanced-schema.json` files.
174+
1. After updates are approved, a documentation team member merges the PR and publishes the updates to the [developer site](https://developer.adobe.com/commerce/services/merchandising-services/).
194175

195176
## Generated output
196177

spectaql/enhanced-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77228,6 +77228,6 @@
7722877228
}
7722977229
},
7723077230
"extensions": {
77231-
"request-id": "34e01da2-9625-4e49-aa0a-2c562effd918"
77231+
"request-id": "a75167ce-c2a3-4c78-82c4-d114a98c1411"
7723277232
}
7723377233
}

0 commit comments

Comments
 (0)