-
|
I've been trying to get codegen working in a new project that also uses apollo client and pothos. I've followed every instruction I can find, read the docs, etc. No matter what I do, the codegen appears to create the typescript files correctly, but there's never a query actually present. Apollo Client and pothos seem unrelated this, the same happens when I make a When I try Here's the page where it's used: https://github.com/viveleroi/graphql-issue/blob/main/app/(application)/dashboard/page.tsx Here's the actual codegen.ts file: https://github.com/viveleroi/graphql-issue/blob/main/codegen.ts This repo is a minimal reproduction so you can look through it. I assume I'm doing something wrong but I can't figure out what. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Good thing you reached out, and thanks for the repo! Let's fix it. The first thing to mention here is that const config: CodegenConfig = {
schema: printSchema(schema),
+ documents: ['app/**/*.tsx'],
generates: {
'./gql/': {
preset: 'client',
plugins: []
}
}
}Then, GraphQL documents should be defined within backticks: const query = graphql(/* GraphQL */ `
query {
greetings
}
`);Finally, anonymous queries and mutations are ignored, we need to provide a name for that query: const query = graphql(/* GraphQL */ `
+ query Greetings {
greetings
}
`); |
Beta Was this translation helpful? Give feedback.
Good thing you reached out, and thanks for the repo! Let's fix it.
The first thing to mention here is that
documentsfield is missing from codegen's config:const config: CodegenConfig = { schema: printSchema(schema), + documents: ['app/**/*.tsx'], generates: { './gql/': { preset: 'client', plugins: [] } } }Then, GraphQL documents should be defined within backticks:
Finally, anonymous queries and mutations are ignored, we need to provide a name for that query:
const query = graphql(/* GraphQL */ ` + query Greetings { greetings } `);