Remove short circuit preventing 'Failed to find any GraphQL type definitions' error from appearing
Description
If you have a pointer that doesn't match any files containing graphql, loadFile should result in an error reporting that no graphql type definitions were identified. However, right now, if there is exactly one error produced by the loader, the meaningful error, the fact that no type definitions were identified, will be hidden. This can be very confusing if there error produced by the loader happens to be unrelated.
An easy reproduction, using graphql-codegen:
/src
Test.vue
<script setup lang="ts">
import {Props} from 'props.ts';
defineProps<Props>();
</script>
gqlType.ts
import { graphql } from '@generated/graphql';
const MY_FRAGMENT = graphql(`
fragment MyFragment on SomeType {
id
}
`);
/codegen
/index.ts
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: './codegen/schema.config.ts',
documents: ['src/**/*.vue', 'src/**/*.ts'],
generates: {
'./generated/graphql/': {
preset: 'client',
config: {
useTypeImports: true,
},
},
},
};
export default config;
package.json
{
"name": "test",
"version": "1.0.0",
"scripts": {
"build:graphql-codegen": "graphql-codegen -c codegen/index.ts",
},
"dependencies": {
"vue": "3.5.18",
"graphql": "16.6.0",
},
"devDependencies": {
"@graphql-codegen/cli": "3.3.0",
"@graphql-codegen/client-preset": "3.0.1",
}
}
If you run npm run build:graphql-codegen, the reason codegen fails is because there are no graphql type definitions for any file matched by the .vue file matcher. However, the only error it will report is this:
[@vue/compiler-sfc] No fs option provided to `compileScript` in non-Node environment. File system access is required for resolving imported types.
This error is preventing the file Test.vue from being parsed, but it's not why graphql codegen in general is failing. If you were to add another vue file with a graphql type definition in it, that file would parse correctly and graphql-codegen would succeed. If you want graphql-codegen to work on the current project setup, you can remove the .vue file matcher from codegen/index.ts.
This change results in the following output instead:
✖ Failed to find any GraphQL type definitions in: src/**/*.vue;
- [@vue/compiler-sfc] No fs option provided to `compileScript` in non-Node environment. File system access is required for resolving imported types.
I think this is much clearer.
Related # (issue) https://github.com/ardatan/graphql-tools/issues/7406
Type of change
Please delete options that are not relevant.
- [X] 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?
Before, running graphql-codegen on a project with a matcher that results in no graphql type definitions and one parsing error:
✔ Parse Configuration
⚠ Generate outputs
❯ Generate to ./generated/graphql/
✔ Load GraphQL schemas
✖ [@vue/compiler-sfc] No fs option provided to `compileScript` in non-Node environment. File system access is required for resolving imported types.
anonymous.vue
22 | import type { SpacePublicationFragment } from '@generated/graphql/graphql';
23 |
24 | const props = defineProps<Props>();
| ^^^^^
25 | const instance = getCurrentInstance();
26 |
◼ Generate
After, running graphql-codegenon a project with a matcher that results in no graphql type definitions and one parsing error:
✔ Parse Configuration
⚠ Generate outputs
❯ Generate to ./generated/graphql/
✔ Load GraphQL schemas
✖ Failed to find any GraphQL type definitions in: src/**/*.vue;
- [@vue/compiler-sfc] No fs option provided to `compileScript` in non-Node environment. File system access is required for resolving imported types.
anonymous.vue
22 | import type { SpacePublicationFragment } from '@generated/graphql/graphql';
23 |
24 | const props = defineProps<Props>();
| ^^^^^
25 | const instance = getCurrentInstance();
26 |
◼ Generate
Test Environment:
- OS: MacOS 14.5
-
@graphql-tools/load: 8.0.0 - NodeJS: v17.9.1
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
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [ ] 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
- [ ] Any dependent changes have been merged and published in downstream modules
⚠️ No Changeset found
Latest commit: c42fe0d216f08c2dda7488989c9fc0ba8123c196
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
📝 Walkthrough
Summary by CodeRabbit
-
Bug Fixes
- Standardized file loading error handling to always throw a consolidated AggregateError when no results are found but errors exist, providing clearer and more consistent error messages across async and sync flows.
-
Tests
- Updated integration tests to validate the AggregateError structure and contained errors, aligning expectations with the new standardized error reporting.
Walkthrough
loadFile and loadFileSync now always throw an AggregateError when no results are produced but errors were collected; previously a single error could be rethrown. No API signature changes.
Changes
| Cohort / File(s) | Summary |
|---|---|
Loader error handlingpackages/load/src/load-typedefs/load-file.ts |
Removed special-case that rethrew a single error; now throws an AggregateError containing all collected errors when results.length === 0 and errors.length > 0. Message constructed from individual error messages. |
Tests updatedpackages/load/tests/loaders/schema/integration.spec.ts |
Updated assertions to expect an AggregateError, to check e.errors.length, and to inspect e.errors[0].toString() for SyntaxError instead of asserting on the raw error string. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant Caller
participant loadFile
participant Readers
Caller->>loadFile: loadFile(...)
rect rgba(230,240,255,0.6)
loadFile->>Readers: read/resolve sources
Readers-->>loadFile: results[] and errors[]
end
alt results.length > 0
loadFile-->>Caller: return results[]
else results.length == 0 and errors.length > 0
note over loadFile: behavior changed — aggregate errors
loadFile-->>Caller: throw AggregateError(errors)
else no results and no errors
loadFile-->>Caller: return []
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related issues
- ardatan/graphql-tools#7406 — Addresses the same loadFile/loadFileSync behavior: ensure AggregateError is thrown when no results but errors exist, avoiding rethrowing a single error.
Suggested reviewers
- ardatan
Poem
I hop through logs with careful paws,
Gathered errors into single laws.
No lonely thorn escapes my sight,
I bundle all to make it right.
A rabbit's patchwork, tidy, tight. 🐇✨
[!TIP]
🔌 Remote MCP (Model Context Protocol) integration is now available!
Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between a8b59a324d39e520cf96e0054c44bcd1d9346e80 and c42fe0d216f08c2dda7488989c9fc0ba8123c196.
📒 Files selected for processing (2)
-
packages/load/src/load-typedefs/load-file.ts(0 hunks) -
packages/load/tests/loaders/schema/integration.spec.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/load/src/load-typedefs/load-file.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Unit Test on Node 18 (windows-latest) and GraphQL v16
- GitHub Check: Unit Test on Node 24 (ubuntu-latest) and GraphQL v16
- GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v15
- GitHub Check: Full Check on GraphQL v16
- GitHub Check: Unit Test on Bun
- GitHub Check: Unit Test on Node 22 (ubuntu-latest) and GraphQL v16
- GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v16
✨ 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.
🪧 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. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- 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.
Not sure I understand the motivation behind this change. If it is an issue on codegen, then it needs to be fixed there not here.