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

fix(graphql): handle parentheses in fragment import file paths. #1746

Merged

Conversation

grxy
Copy link
Contributor

@grxy grxy commented Jul 3, 2024

Rollup Plugin Name: graphql

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

N/A

Description

This PR fixes an issue in the GraphQL plugin where parentheses in file paths are not properly replaced with a fragment's variable, leading to a parsing error.

The fix works by updating the require statement replacement regex from /require\(([^)]+)\)/gi to /require\(["']([^"']+)["']\)/gi. The original regex considered a closing parenthesis as the terminator of a require statement, when in fact, we should be looking at a quote character before a parentheses as the terminator. In addition, by excluding the leading and trailing quote from the regex capture group, we can remove the additional replacePath variable.

@grxy grxy marked this pull request as ready for review July 3, 2024 18:34
@grxy grxy requested a review from shellscape as a code owner July 3, 2024 18:34

query Query {
...ParenthesesFragment
...BracketsFragment
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brackets in filenames weren't actually breaking fragment imports, but I added this for extra confidence. Let me know if you'd like this to be removed.

Copy link
Collaborator

@shellscape shellscape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@shellscape shellscape changed the title fix(graphql): handle parentheses in fragment import file paths fix(graphql): handle parentheses in fragment import file paths. Sep 22, 2024
@shellscape shellscape merged commit 1a734fc into rollup:master Sep 22, 2024
5 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.

2 participants