Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for module import paths #4723

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tlivings
Copy link
Contributor

@tlivings tlivings commented Sep 20, 2022

🚨 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: #4721

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 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:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • 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-bot
Copy link

changeset-bot bot commented Sep 20, 2022

🦋 Changeset detected

Latest commit: be558ca

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

@vercel
Copy link

vercel bot commented Sep 20, 2022

@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
Copy link

vercel bot commented Sep 22, 2022

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)

@tlivings
Copy link
Contributor Author

Any thoughts on this?

@tlivings
Copy link
Contributor Author

@ardatan Was there any feedback or questions?

@ardatan
Copy link
Owner

ardatan commented Sep 28, 2022

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

@Urigo Urigo requested a review from ardatan September 29, 2022 15:00
@tlivings
Copy link
Contributor Author

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

@ardatan
Copy link
Owner

ardatan commented Oct 20, 2022

@tlivings
Copy link
Contributor Author

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!

@Urigo
Copy link
Collaborator

Urigo commented Oct 20, 2022

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

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.

3 participants