Skip to content

fix(schema): support absolute schema paths#721

Merged
sid88in merged 1 commit into
masterfrom
fix/382-schema-absolute-paths
Jun 2, 2026
Merged

fix(schema): support absolute schema paths#721
sid88in merged 1 commit into
masterfrom
fix/382-schema-absolute-paths

Conversation

@sid88in

@sid88in sid88in commented Jun 2, 2026

Copy link
Copy Markdown
Owner

fix(schema): support absolute schema paths

Closes #382

Problem

schema file paths were resolved with path.join(servicePath, schema). path.join
treats every argument as a segment, so an absolute schema path gets incorrectly
prefixed with the service directory:

path.join('/svc/path', '/abs/schema.graphql')
// => '/svc/path/abs/schema.graphql'   (file not found)

The result is that an absolute schema path silently resolves to nothing: globbing
returns 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 v2
line in src/resources/Schema.ts.

Fix

Use path.resolve instead of path.join:

path.resolve('/svc/path', 'schema.graphql')      // => '/svc/path/schema.graphql'  (unchanged for relative)
path.resolve('/svc/path', '/abs/schema.graphql') // => '/abs/schema.graphql'        (absolute honored)

path.resolve keeps the existing behaviour for relative paths (resolved against the
service 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 all
unaffected.

Note: #382 also asked about glob support (schema: schemas/*.graphql). That is
already implemented on the v2 line (globby + @graphql-tools/merge), so this PR
only addresses the remaining absolute-path gap.

Tests

Added two cases to src/__tests__/schema.test.ts:

  • should support absolute schema paths regardless of servicePath — sets
    servicePath to a directory that does not contain the schema and passes an
    absolute path to a fixture; asserts the schema is still read. (Fails on master:
    generateSchema() returns "".)
  • should resolve relative schema paths against servicePath — regression guard
    confirming relative paths still resolve against the service directory.

The existing relative-path / glob / stitching snapshots are unchanged.

Verification

  • npm run build — OK
  • npm run lint — 0 errors
  • npm test — 21 suites / 347 tests pass; 216 snapshots unchanged
  • npm run test:e2e — 31 suites / 90 tests pass

Verified the patch applies cleanly to a fresh origin/master (978c4cb) and that the
schema suite (10 tests) passes there after npm ci && npm run build.

Credit

The fix approach (joinresolve) was proposed by @ankon in #382. I have not added a
Co-authored-by: trailer because I don't have a verified commit email for them — happy to
add one if you'd like to attribute it that way.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed schema file path resolution to correctly handle both absolute and relative schema paths relative to the service directory.
  • Tests

    • Added test coverage validating schema path resolution for absolute and relative paths.

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
@sid88in sid88in self-assigned this Jun 2, 2026
@sid88in sid88in requested a review from AlexHladin June 2, 2026 00:04
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65d07617-004b-425c-b64b-23cbd60d716b

📥 Commits

Reviewing files that changed from the base of the PR and between 978c4cb and 458f371.

📒 Files selected for processing (2)
  • src/__tests__/schema.test.ts
  • src/resources/Schema.ts

📝 Walkthrough

Walkthrough

The PR fixes schema file path resolution in the serverless-appsync-plugin by switching from path.join() to path.resolve() in Schema.generateSchema(). This change preserves absolute schema paths while still rooting relative paths at the configured Serverless service directory. Two test cases verify the corrected behavior for both absolute and relative path scenarios.

Changes

Schema path resolution

Layer / File(s) Summary
Schema path resolution implementation
src/resources/Schema.ts
Schema file path resolution now uses path.resolve(servicePath, schema) instead of path.join() to correctly handle absolute paths while keeping relative paths rooted at servicePath.
Path import and resolution test cases
src/__tests__/schema.test.ts
Test file imports path module and adds two new test cases verifying schema path resolution: one ensures absolute schema paths load correctly independent of servicePath, and another verifies relative schema paths resolve against servicePath.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • #382: Addresses the same code-level issue of switching schema path resolution from path.join() to path.resolve() to properly support absolute schema paths.

Suggested reviewers

  • AlexHladin

Poem

🐰 A rabbit hops through paths both far and near,
No more the join that muddles what's unclear,
Resolve now keeps the absolute so bright,
While relatives find home in servicePath light,
Schema paths aligned—all working right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(schema): support absolute schema paths' directly and accurately describes the main change: fixing support for absolute schema file paths in the Schema module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/382-schema-absolute-paths

Comment @coderabbitai help to get the list of available commands and usage tips.

@sid88in sid88in merged commit 840d109 into master Jun 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schema should support absolute paths

2 participants