Skip to content

Custom TS schema loaders are not working #8981

@taletski

Description

@taletski

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

I am following the guide for creating a custom loader using TS.
It appears that the codegen fails to load the .ts loader file yet works ok with a .js one.

Your Example Website or App

https://codesandbox.io/p/sandbox/graphql-codegen-custom-schema-loader-issue-hkve7f

Steps to Reproduce the Bug or Issue

  • Run yarn generate
    The command fails with an error

  • Change loader.ts to loader.js in codegen.ts

  • Run yarn generate
    This time the command will work

Expected behavior

As a user, I expected that the custom schema loader written in TS will work if I follow the guide

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Linux]
  • NodeJS: 16.17.0
  • graphql version: 16.2.0
  • @graphql-codegen/* version(s): 2.6.2

Codegen Config File

import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: {
    "schema.graphql": {
      // loader: "./loader.js", // JS - ✅ working
      loader: "./loader.ts", // TS - ❌ not working
    },
  },
  documents: "document.graphql",
  generates: {
    "types.ts": { plugins: ["typescript", "typescript-operations"] },
  },
};

export default config;

Additional context

Please, note that I am registering the ts-node for the codegen command.

graphql-codegen -r ts-node/register --config ./codegen.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions