fix(schema): support absolute schema paths#721
Conversation
Schema file paths were resolved with path.join(servicePath, schema), which prefixes absolute paths with the service directory and makes them resolve to a non-existent file (producing an empty schema). Use path.resolve instead: relative paths still resolve against the service directory, while absolute paths are honored as-is. Glob expansion and schema stitching are unaffected. Adds tests for absolute-path resolution and a relative-path regression guard. Closes #382
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR fixes schema file path resolution in the serverless-appsync-plugin by switching from ChangesSchema path resolution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
fix(schema): support absolute
schemapathsCloses #382
Problem
schemafile paths were resolved withpath.join(servicePath, schema).path.jointreats every argument as a segment, so an absolute schema path gets incorrectly
prefixed with the service directory:
The result is that an absolute
schemapath silently resolves to nothing: globbingreturns no files and an empty schema is produced. This is the exact limitation reported
in #382 (originally against the v1
get-config.js), and it is still present on the v2line in
src/resources/Schema.ts.Fix
Use
path.resolveinstead ofpath.join:path.resolvekeeps the existing behaviour for relative paths (resolved against theservice directory) while leaving absolute paths untouched. This is the one-line change
proposed by the reporter, applied to the current code location. Glob expansion,
schema stitching, and the Windows-path handling (
.replace(/\\/g, '/')) are allunaffected.
Tests
Added two cases to
src/__tests__/schema.test.ts:should support absolute schema paths regardless of servicePath— setsservicePathto a directory that does not contain the schema and passes anabsolute path to a fixture; asserts the schema is still read. (Fails on
master:generateSchema()returns"".)should resolve relative schema paths against servicePath— regression guardconfirming relative paths still resolve against the service directory.
The existing relative-path / glob / stitching snapshots are unchanged.
Verification
npm run build— OKnpm run lint— 0 errorsnpm test— 21 suites / 347 tests pass; 216 snapshots unchangednpm run test:e2e— 31 suites / 90 tests passVerified the patch applies cleanly to a fresh
origin/master(978c4cb) and that theschema suite (10 tests) passes there after
npm ci && npm run build.Credit
The fix approach (
join→resolve) was proposed by @ankon in #382. I have not added aCo-authored-by:trailer because I don't have a verified commit email for them — happy toadd one if you'd like to attribute it that way.
Summary by CodeRabbit
Bug Fixes
Tests