8000 Add warning before loadFileSync returns empty array · Issue #7247 · ardatan/graphql-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Add warning before loadFileSync returns empty array #7247
Open
@hotpineapple

Description

@hotpineapple

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 injec 5973 t 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0