dotansimha / dotansimha/graphql-code-generator

config.schema codefile path does not work

Open
#10,592 2 comments 0 reactions 1 assignee Claimed by @eddeee888 View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/cli

### Describe the bug

According to the [Config.schema documentation](https://the-guild.dev/graphql/codegen/docs/config-reference/codegen-config#configuration-options):

> a JavaScript file that exports the schema to generate code from. This can also be an array that specifies multiple schemas to generate code from. You can read more about the supported formats [here](https://the-guild.dev/graphql/codegen/docs/config-reference/schema-field#available-formats)

> You can also specify a code file that exports your `GraphQLSchema` object as export `schema` or as default export.

However, that produces the following error:

```
✔ Parse Configuration
⚠ Generate outputs
❯ Generate to ./src/@types/schema.d.ts
✖ Failed to load schema from
./src/gql/Mutation.ts,./src/gql/Query.ts:

Unable to find any GraphQL type definitions for the following pointers:
- ./src/gql/Mutation.ts
- ./src/gql/Query.ts

NoTypeDefinitionsFound:
Unable to find any GraphQL type definitions for the following pointers:
- ./src/gql/Mutation.ts
- ./src/gql/Query.ts
```

Supplying a single file path to `Schema.ts` produces the same errors (citing `./src/gql/Schema.ts` instead).

codegen.config.ts

```ts
import { type CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
generates: {
'./src/@types/schema.d.ts': {
plugins: ['typescript'],
},
},
overwrite: true,
schema: [
'./src/gql/Mutation.ts',
'./src/gql/Query.ts',
],
};

export default config;
```

Mutation.ts

```ts
const Mutation = new GraphQLObjectType({
fields: () => ({…}),
name: 'Mutation',
});

export default Mutation;
```

Query.ts

```ts
const Query = new GraphQLObjectType({
fields: () => ({…}),
name: 'Query',
});

export default Query;
```

Schema.ts

```ts
import { GraphQLSchema } from 'graphql';

import mutation from './Mutation.ts';
import query from './Query.ts';

const schema = new GraphQLSchema({
mutation,
query,
});

export default schema;
```

### Your Example Website or App

none

### Steps to Reproduce the Bug or Issue

```sh
npx graphql-code-generator --config ./codegen.config.ts
```

### Expected behavior

It should work.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 24.13.0
- `graphql` version: 16.8.1
- `@graphql-codegen/cli` version: 6.1.1
- `@graphql-codegen/typescript` version:5.0.7

### Codegen Config File

_No response_

### Additional context

I'm trying to set up an npm command to generate typescript definitions from the GQL schema. I want this to run against the files themselves (there is no server running).

The outputted error seems to indicate it cannot find the thing this tool is itself supposed to be doing O.o

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.