Skip to content

Generate types client query. #8533

Oct 26, 2022 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

Hi @jangot,

First, you will need to fix your configuration by removing the plugins (which should not be used with preset: "client"), as follows:

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), QUERY will be properly typed.
Finally, remove the Promise<any> return type of your getUser() function to let TypeScript infer the return type from URQL query() call.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jangot
Comment options

@charlypoly
Comment options

Answer selected by charlypoly
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants