In the process of migrating a setup that mirrors all the types exactly as on the server to one based solely on the document nodes we've written.
Currently, the configuration is in .graphqlrc.js
/** @type {import('graphql-config').IGraphQLConfig} */
const graphqlConfig = {
schema: process.env.NEXT_PUBLIC_API_URL,
documents: './src/graphql/**/*.ts',
extensions: {
codegen: {
hooks: {
afterAllFileWrite: ['prettier --write'],
},
generates: {
'./src/__generated__/graphql.ts': {
plugins: [
'typescript',
'typescript-operations',
{
add: {
content: '/* eslint-disable */',
},
},
],
config: {
disableDescriptions: true,
},
},
'./src/__generated__/introspection-result.ts': {
plugins: ['fragment-matcher'],
config: {
useExplicitTyping: true,
},
},
},
},
},
}
This setup currently produces output like below:
export type QueryName = {
__typename?: 'Query'
resource?:
| { __typename?: 'A' }
| { __typename?: 'B' }
| {
__typename?: 'C'
id: string
prop1: any
prop2: any
}
}
However, I was expecting something more specific like:
export type QueryName = {
__typename?: 'Query'
resource?: {
__typename?: 'C'
id: string
prop1: any
prop2: any
}
}
Since I am only querying for type C
, the current generated types will impact a lot of code. If we could generate what I expect, it would simplify the changes needed.
I've experimented with the configuration mentioned here but haven't found a solution yet. Please advise if this is possible or suggest any resources to help solve this issue.
Thank you in advance!