-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DocumentTypeDecoration Not Imported inside graphql.ts when there is no document #10176
Comments
I wrote a hook to fix this issue for me. Here's my code: import type { CodegenConfig } from '@graphql-codegen/cli';
function fixImportsAndLint(path: string, content: string) {
let newContent = content;
if (!newContent.startsWith(`/* eslint-disable */`)) {
newContent = `/* eslint-disable */\n${newContent}`;
}
if (path.endsWith('graphql.ts')) {
newContent = newContent.replace(
'/* eslint-disable */',
`/* eslint-disable */\nimport { DocumentTypeDecoration } from '@graphql-typed-document-node/core';\n`
);
}
return newContent;
}
const config: CodegenConfig = {
schema: 'path/to/schema.graphql',
documents: ['src/**/*.tsx'],
ignoreNoDocuments: true,
generates: {
'./src/graphql/generated/': {
preset: 'client',
config: {
documentMode: 'string',
},
hooks: {
beforeOneFileWrite: (path, content) => {
return fixImportsAndLint(path, content);
},
},
},
'./schema.graphql': {
plugins: ['schema-ast'],
config: {
includeDirectives: true,
},
},
},
};
export default config; |
It then added the import statement automatically once it started generating fragment and query documents, so now I have 2 and need to remove my hook. |
Hi @JamesParkDev , One thing that jumps out straightaway is you don't need to explicitly bring in |
Hi @eddeee888 - I just made replication of this bug here: https://github.com/JamesParkDev/bug-10176 - I think this bug only happens if there are no documents. Run command: If you create query findMainUser {
user(id: "1") {
id
username
email
}
} Then you run the
As it might confuse someone just trying to configure. I switched to SDK style mostly after this. |
Can you check comment above? I'm not sure if we can replicate this if you add documents? I think after you add the documents that can be removed. A lot of time passed after I had this issue, but I ended up switching to SDK since client-preset was giving me so much issues. Maybe there are ways to trigger this missing even if there are documents, but I'm not sure if there is at this moment. |
Hi @JamesParkDev , having no documents seem to cause that issue like you mentioned. I've updated the issue title to reflect it. Another question out of curiousity is what is the SDK approach you mention? 🙂 |
@eddeee888 this.sdk.findProductById() Generated from document But also there is for vanilla as well I think it would be https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-generic-sdk |
Which packages are impacted by your issue?
@graphql-codegen/cli, @graphql-codegen/client-preset
Describe the bug
Package json
when we run codegen everything gets generated but graphql has one type issue
Your Example Website or App
n/a
Steps to Reproduce the Bug or Issue
when we run codegen everything gets generated but graphql has one type issue
Expected behavior
It think generation should import/generate it.
Looking at local
/examples
we can see typescript example here https://github.com/dotansimha/graphql-code-generator/blob/master/examples/typescript-esm/src/gql/graphql.ts which imports it at the top, and I'm unsure why it is not includedScreenshots or Videos
No response
Platform
graphql
version: 16.9.0@graphql-codegen/*
5.0.3Codegen Config File
Additional context
No response
The text was updated successfully, but these errors were encountered: