-
Notifications
You must be signed in to change notification settings - Fork 1.4k
config.schema codefile path does not work #10592
Description
Which packages are impacted by your issue?
@graphql-codegen/cli
Describe the bug
According to the Config.schema documentation:
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
You can also specify a code file that exports your
GraphQLSchemaobject as exportschemaor 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
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
const Mutation = new GraphQLObjectType({
fields: () => ({…}),
name: 'Mutation',
});
export default Mutation;Query.ts
const Query = new GraphQLObjectType({
fields: () => ({…}),
name: 'Query',
});
export default Query;Schema.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
npx graphql-code-generator --config ./codegen.config.tsExpected behavior
It should work.
Screenshots or Videos
No response
Platform
- OS: macOS
- NodeJS: 24.13.0
graphqlversion: 16.8.1@graphql-codegen/cliversion: 6.1.1@graphql-codegen/typescriptversion: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