graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Adding support for module import paths

Open tlivings opened this issue 3 years ago • 10 comments

🚨 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.

tlivings avatar Sep 20 '22 20:09 tlivings

🦋 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

changeset-bot[bot] avatar Sep 20 '22 20:09 changeset-bot[bot]

@tlivings is attempting to deploy a commit to the The Guild Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 20 '22 20:09 vercel[bot]

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)

vercel[bot] avatar Sep 22 '22 05:09 vercel[bot]

Any thoughts on this?

tlivings avatar Sep 23 '22 12:09 tlivings

@ardatan Was there any feedback or questions?

tlivings avatar Sep 28 '22 21:09 tlivings

@tlivings I was busy with some important tasks. I will take a look by the end of this week.

ardatan avatar Sep 28 '22 22:09 ardatan

@Urigo and @ardatan : how are we feeling about this?

tlivings avatar Oct 17 '22 13:10 tlivings

I think we already support this case; https://github.com/ardatan/graphql-tools/blob/master/packages/import/tests/schema/import-schema.spec.ts#L128

ardatan avatar Oct 20 '22 15:10 ardatan

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!

tlivings avatar Oct 20 '22 19:10 tlivings

sorry for that @tlivings :/ Would you be ok with adding this to our docs?

Urigo avatar Oct 20 '22 19:10 Urigo