Adding support for module import paths
🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.
Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.
Description
This change adds support for #import statements to use paths to modules.
Example:
# import A from "require:someModule/schema.graphql"
A simplified form, assuming the module package main points at a schema could be:
# import A from "require:someModule"
This is particularly useful for both published shared types and monorepos that wish to avoid relative paths between packages.
Related: https://github.com/ardatan/graphql-tools/discussions/4721
Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [x] This change requires a documentation update
How Has This Been Tested?
See import-schema.spec.ts test: "require paths"
Test Environment:
- OS:
@graphql-tools/...:- NodeJS:
Checklist:
- [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests and linter rules pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules
Further comments
Because jest intercepts require statements, I added a path override to the module mapper to ensure the test is able to run.
🦋 Changeset detected
Latest commit: be558cad70ee0ade4f159ce52935477effe7786b
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 3 packages
| Name | Type |
|---|---|
| @graphql-tools/import | Minor |
| @graphql-tools/graphql-file-loader | Patch |
| @graphql-tools/node-require | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
@tlivings is attempting to deploy a commit to the The Guild Team on Vercel.
A member of the Team first needs to authorize it.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated |
|---|---|---|---|
| graphql-tools | ✅ Ready (Inspect) | Visit Preview | Sep 22, 2022 at 5:38AM (UTC) |
Any thoughts on this?
@ardatan Was there any feedback or questions?
@tlivings I was busy with some important tasks. I will take a look by the end of this week.
@Urigo and @ardatan : how are we feeling about this?
I think we already support this case; https://github.com/ardatan/graphql-tools/blob/master/packages/import/tests/schema/import-schema.spec.ts#L128
I think we already support this case; https://github.com/ardatan/graphql-tools/blob/master/packages/import/tests/schema/import-schema.spec.ts#L128
I see. Would be nice if this was documented 🤣
Thanks!
sorry for that @tlivings :/ Would you be ok with adding this to our docs?