ardatan / ardatan/graphql-tools
Add warning before loadFileSync returns empty array
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
**Is your feature request related to a problem? Please describe.**
When using `loadFilesSync()` to load GraphQL SDL files (e.g., `**/*.graphql`), if no matching files are found (e.g., due to a wrong glob pattern or missing files), the function silently returns an empty array `[]` without any warning or error.
This becomes problematic when used with buildSchema() or similar utilities.
Functions such as addElementsToSchema will inject default federation directives (e.g., version 1) when none are explicitly defined.
This can lead to federation version conflicts when the resulting schema is later merged with another schema that includes a different version of federation directives, and it is not easy to debug to find root cause.
**Describe the solution you'd like**
Add warning log when result is empty array.
```typescript
// load-files/src/index.ts
export function loadFilesSync(
pattern: string | string[],
options: LoadFilesOptions = LoadFilesDefaultOptions,
): T[] {
// ...
const result = relevantPaths
.map(path => {
...
})
.filter(v => v);
if(result.length === 0) {
console.warn(
'[loadFilesSync] No GraphQL schema files were loaded. Please check your glob pattern or file extensions.'
);
}
return result;
}
```
**Describe alternatives you've considered**
**Additional context**
Contributor guide
Research direction
Read load-files/src/index.ts and the loadFilesSync entry point. Trace how relevantPaths becomes the result, then verify behavior when no GraphQL files match; done means an empty result emits the requested warning while non-empty results remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 43/100