Skip to content

Conversation

HunterLarco
Copy link
Contributor

@HunterLarco HunterLarco commented Jul 5, 2025

Description

TL;DR: this package has a dependency on @vue/compiler-sfc which updated two years ago in a non-backwards compatible way. Minor changes are required so that this package conforms to the changes in vuejs/core#8083

Fixes #6945 (cc @felixxxxxs)

Details

vue's composition API (most common syntax as of Vue 3) heavily leverages compiler macros. As part of the implementation of this feature, vue's SFC compiler requires two things:

  1. The module typescript to be registered with @vue/compiler-sfc (code pointer)
  2. Parsed files to include a file path for the purpose or resolving local imports (code pointer)

Currently this project satisfies neither of these requirements, meaning that any vue single-file-component using compiler macros (most of Vue 3 code) will crash the parser with an error like:

[@vue/compiler-sfc] No fs option provided to 'compileScript' in non-Node environment. File system access is required for resolving imported types.

Though cryptic, this error can be traced back to typescript not being registered correctly (see @vue/compiler-sf#resolveFS). We have a few options to fix this.

  1. Rely on callers to register typescript with the vue compiler themselves. This can be easily achieved by adding import 'vue/compiler-sfc'; to their codegen.ts file.
  2. Whenever vue files need to be parsed, ensure first that registerTS has been called.

Of these two options I'd recommend the latter. typescript registration is a low-level concept which is handled for clients by most of the vue ecosystem. It's easy for clients of graphql-codegen to miss or be confused on why import 'vue/compiler-sfc'; is required especially given the cryptic error when it's missing.

For this PR I've taken option (2) and ensured that this project correctly calls registerTS.

For our second requirement, "file paths must be included for parsed files to resolve local imports" we can easily remedy this by plumbing file path information down to @vue/compiler-sfc which this PR also does.

And one last note. I've moved @vue/compiler-sfc to optional dependencies as this package does actually include it at runtime and not just as a dev dependency. I've also reframed it's version constraint to ^3.3.1 which is the first version which included the non-backwards compatible change this PR addresses.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots/Sandbox (if appropriate/relevant):

N/A

How Has This Been Tested?

  1. This has been tested locally in a vue repo in which graphql-codegen was failing due to the above root cause analysis. By applying these changes graphql-codegen now passes.
  2. I also added a test which fails on main but passes in this PR to replicate my graphql-codegen project

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

Copy link
Contributor

coderabbitai bot commented Jul 5, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Improved support for Vue Single File Components using TypeScript, including better handling of <script setup lang="ts"> syntax.
    • Enhanced error handling when the TypeScript package is missing.
  • Tests

    • Added new tests to verify GraphQL plucking from Vue 3 components with TypeScript and compiler macros.
    • Improved test isolation and cleanup for more reliable test runs.

Summary by CodeRabbit

  • New Features
    • Improved support for extracting GraphQL queries from Vue 3 Single File Components using <script setup lang="ts"> syntax, including those with TypeScript and compiler macros.
  • Tests
    • Added new tests to verify GraphQL extraction from Vue SFCs with TypeScript setup and imports.
    • Enhanced test isolation and cleanup for more reliable test execution.

Walkthrough

The changes update the Vue Single File Component (SFC) parsing logic in the graphql-tag-pluck package to require and utilize the filePath parameter, ensuring correct filename context and TypeScript support during parsing. Tests are added to verify GraphQL plucking from Vue SFCs using imported types with compiler macros.

Changes

File(s) Change Summary
packages/graphql-tag-pluck/src/index.ts Updated Vue parsing functions to require and forward filePath; registered TypeScript loader; passed filename to compiler; introduced error for missing TypeScript package; changed Vue compiler loading to async.
packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts Added new test for Vue SFCs with imported types and compiler macros; setup/teardown for temp files.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant FileSystem
    participant PluckFunction
    participant VueCompiler

    TestRunner->>FileSystem: Write TypeScript and Vue SFC files
    TestRunner->>PluckFunction: Call pluck with fileData, filePath
    PluckFunction->>VueCompiler: parseWithVue(fileData, filePath)
    VueCompiler->>VueCompiler: Register TypeScript loader
    VueCompiler->>VueCompiler: Parse SFC with filename context
    VueCompiler-->>PluckFunction: Return parsed script content
    PluckFunction-->>TestRunner: Return extracted GraphQL query
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure graphql-tag-pluck works for Vue SFCs using imported types with compiler macros (#6945)
Call Vue SFC compiler with correct filePath and register TypeScript loader for imported types (#6945)
Add failing test for Vue SFCs with imported types and macros, and verify extraction of GraphQL queries (#6945)

Poem

In burrows deep, a bunny found
Vue files with types that went around.
With file paths clear and TypeScript near,
The plucking magic did appear!
Now queries hop with cheerful cheer—
The code is fixed, the coast is clear!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/graphql-tag-pluck/src/index.ts

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da157f5 and 8ee9dd1.

📒 Files selected for processing (1)
  • packages/graphql-tag-pluck/src/index.ts (7 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@HunterLarco HunterLarco changed the title fix vue files support parsing vue single-file-components using composition API Jul 6, 2025
Copy link

changeset-bot bot commented Jul 6, 2025

⚠️ No Changeset found

Latest commit: 8ee9dd1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@HunterLarco HunterLarco marked this pull request as ready for review July 6, 2025 15:59
@ardatan ardatan merged commit 48ec563 into ardatan:master Jul 17, 2025
13 of 14 checks passed
@HunterLarco HunterLarco deleted the hunter/fix-vue-imports branch July 17, 2025 19:04
ardatan added a commit that referenced this pull request Sep 22, 2025
* fix vue files

* register-ts

* test

* self review

* resolve github runner permissions issue

* satisfy lint

* revert package.json as per comments

* adopt peerDependenciesMeta

* revert package.json

* resolve lint

* Better module loading

* Align

---------

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
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.

graphql-tag-pluck fails for Vue SFCs when using imported types with compiler macros
2 participants