Generate types client query. #8533
-
Hello. I have config:
I have a code:
It generates strange results with many types for a scheme. And I totally don't understand where I can take types for results. I have found dozens of examples of how to generate scheme types but no one creates queries or maybe I don't understand something. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @jangot, First, you will need to fix your configuration by removing the import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: 'http://localhost:5555/graphql',
documents: ['src/**/*.ts'],
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
};
export default config; Then, you after running graphql-codegen (preferably in watch mode), |
Beta Was this translation helpful? Give feedback.
-
Aga, it is much better. |
Beta Was this translation helpful? Give feedback.
Hi @jangot,
First, you will need to fix your configuration by removing the
plugins
(which should not be used withpreset: "client"
), as follows:Then, you after running graphql-codegen (preferably in watch mode),
QUERY
will be properly typed.Finally, remove the
Promise<any>
return type of yourgetUser()
function to let TypeScript infer the return type from URQLquery()
call.