graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Add warning before loadFileSync returns empty array

Open hotpineapple opened this issue 5 months ago • 0 comments

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.

// load-files/src/index.ts
export function loadFilesSync<T = any>(
  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

hotpineapple avatar Jun 10 '25 21:06 hotpineapple