Why generated query types has lots of ANY #9957
-
Hi ! My problemThe generated query types in graphql.ts has so many any types. DescriptionThe backend generate a schema.graphqls file tant contains everything. I put this file on the root in the project. I use it in a React project with Apollo client. For example :
My Queryimport { gql } from '@/types/graphql/_generated_';
export const FindProgRByIdQuery = gql(`
query FindProgRByIdQuery($progRId: String) {
mapsProgr(where: {id: {_eq: $progRId}}) {
id
name
status
priority
meshmaxlength
validityperiods {
start
end
}
...
}
}
`);
export type ProgRById = FindProgRByIdQueryQuery['mapsProgr'][0]; Codegen configimport type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
overwrite: true,
schema: 'http://localhost:5173/schema.graphqls',
documents: ['src/**/*.{ts,tsx}'],
generates: {
'./src/types/graphql/_generated_/': {
preset: 'client',
plugins: [],
presetConfig: {
gqlTagName: 'gql',
// Rename useFragment to getFragmentData for ESLint error
fragmentMasking: { unmaskFunctionName: 'getFragmentData' },
},
},
},
ignoreNoDocuments: true,
};
export default config; The generated queryexport type FindProgRByIdQueryQuery = { __typename?: 'query_root', mapsProgr: Array<{ __typename?: 'MapsProgr', id: string, name: string, status: MapsProgrstatusEnum, submissiondate: any, priority: string, meshmaxlength: any, skybrightnessthreshold?: any | null, solaranglethreshold?: any | null, userorderId: number, areaofinterest?: any | null, validityperiods: Array<{ __typename?: 'MapsValidityperiod', start: any, end: any }>, satellites: Array<{ __typename?: 'MapsProgrsatellites', satellite: any }>, visibilityconstraints: Array<{ __typename?: 'MapsVisibilityconstraints', maxazimuth?: any | null, maxelevation?: any | null, minazimuth?: any | null, minelevation?: any | null, psixmax?: any | null, psixmin?: any | null, psixymax?: any | null, psiymax?: any | null, psiymin?: any | null, type: MapsVisibilityconstraintstypesEnum }>, meshaimings: Array<{ __typename?: 'MapsMeshaiming', ascending?: boolean | null, azimuth?: any | null, type: MapsMeshaimingtypesEnum }>, userorder: { __typename?: 'MapsUserorder', id: string, name?: string | null } }> }; Dependencies
Why there is so many ANY in the FindProgRByIdQueryQuery ? The problem is probably from me but I really don't know where ! I need your help :D Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You have to define the types of scalars by yourself. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much ! |
Beta Was this translation helpful? Give feedback.
You have to define the types of scalars by yourself.
https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-operations#scalars