|
| 1 | +# Commerce CIF GraphQL Integration Reference |
| 2 | + |
| 3 | +Reference implementation for integrating 3rd-party commerce platforms with AEM CIF via the Magento GraphQL API, deployed on Adobe I/O Runtime (App Builder). |
| 4 | + |
| 5 | +## Build |
| 6 | + |
| 7 | +- **Runtime:** Node.js 12.x (CI-tested version), compatible with 10/12/14 |
| 8 | +- **Adobe I/O CLI:** Required for build/deploy (`aio` v8.x) |
| 9 | +- `npm install` — install dependencies |
| 10 | +- `aio app build` — build the application |
| 11 | +- `aio app deploy` — deploy to Adobe I/O Runtime |
| 12 | + |
| 13 | +## Testing |
| 14 | + |
| 15 | +- **Unit tests (Mocha + Chai + Sinon):** `npm run unit` — runs all `test/**/*Test.js` files |
| 16 | +- **Lint + unit + coverage:** `npm test` — runs ESLint, then Mocha with nyc coverage (80% line minimum) |
| 17 | +- **Coverage only:** `npm run test-cov` |
| 18 | +- No running server required for tests; mocking via `mock-require` |
| 19 | + |
| 20 | +## Code Style |
| 21 | + |
| 22 | +- **ESLint** with `eslint:recommended`: `npm run lint` |
| 23 | +- Auto-fix: `npx eslint --fix .` |
| 24 | +- **License header required** on all JS files — Apache 2.0 block header enforced by `eslint-plugin-header`; use `--fix` to auto-insert |
| 25 | +- `"use strict"` required (global strict mode) |
| 26 | +- `no-var` enforced (use `const`/`let`), `one-var: never` (one declaration per statement) |
| 27 | +- Ignored: `**/coverage/**`, `dist`, `web-src/src/exc-runtime.js` |
| 28 | + |
| 29 | +## Module Map |
| 30 | + |
| 31 | +| Module | Path | Description | |
| 32 | +|--------|------|-------------| |
| 33 | +| Common | `actions/common/` | Data loaders, data classes, and schema builder shared by all resolvers | |
| 34 | +| Local dispatcher | `actions/local/dispatcher.js` | Main entry point — processes GraphQL requests, hosts local resolvers | |
| 35 | +| Remote cart resolver | `actions/remote/cartResolver.js` | Remote resolver for cart operations, integrated via schema delegation | |
| 36 | +| Documentation | `actions/documentation/` | Schema pruning tool and introspection endpoint for CIF-subset schema | |
| 37 | +| Schema tools | `schemas/` | CLI tools to generate pruned schemas (`generate.js`) and check compatibility (`check.js`) | |
| 38 | +| Web frontend | `web-src/` | GraphiQL web app for testing the GraphQL endpoint | |
| 39 | +| Tests | `test/` | Unit tests mirroring source structure | |
| 40 | + |
| 41 | +## Architecture |
| 42 | + |
| 43 | +- **GraphQL (graphql-js 14 + graphql-tools 3):** Schema-first approach with schema stitching |
| 44 | +- **Resolver pattern:** "Local" resolvers run in the dispatcher action (shared process, shared cache); "remote" resolvers are separate I/O Runtime actions integrated via schema delegation |
| 45 | +- **Data layer:** `*Loader.js` classes fetch data (using `dataloader` for batching); companion data classes convert responses to Magento GraphQL types |
| 46 | +- **Schema building:** `SchemaBuilder.js` builds the executable schema by merging the local schema with remote schemas discovered via introspection |
| 47 | +- **Caching:** Schema cached in global variable (warm containers); optional second-level cache via `@adobe/aio-lib-state` (controlled by `use-aio-cache` in `app.config.yaml`) |
| 48 | +- **App config:** `app.config.yaml` defines all Runtime actions, their inputs, and remote schema wiring (`remoteSchemas` map with merge-priority `order`) |
| 49 | +- **Runtime:** Actions execute on `nodejs:14` containers in Adobe I/O Runtime |
0 commit comments