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

If there are no GraphQL type definitions matching a pointer in load-file having a single error hides the relevant error message

Open person1123 opened this issue 4 months ago • 0 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [ ] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

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.

To Reproduce Steps to reproduce the behavior:

/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.

Expected behavior

Output:

 ✖ 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.

This both communicates the individual error that was found, as well as explaining why the whole build errored

Environment:

  • OS: MacOS
  • @graphql-tools/load: 8.0.0
  • NodeJS: v17.9.1

person1123 avatar Aug 20 '25 19:08 person1123