In graphql-codegen Is There Any Way to Make Generated Types Derive From a Common Type?

49 Views Asked by At

I am generating Typescript types from a GraphQL API using the graphql-codegen package. It works great ... except that it makes types like these:

export type PolicyTypeConnection = {
  __typename?: 'PolicyTypeConnection';
  count?: Maybe<Scalars['Int']['output']>;
  edges: Array<Maybe<PolicyTypeEdge>>;
};

export type PolicyRuleTypeConnection = {
  __typename?: 'PolicyRuleTypeConnection';
  count?: Maybe<Scalars['Int']['output']>;
  edges: Array<Maybe<PolicyRuleTypeEdge>>;
};

... imagine a ton more that follow the same pattern

It would be handy if I could refer to all those types as a group. In other words, I'd like to have a type:

export type TypeConnection = {
  count?: Maybe<Scalars['Int']['output']>;
  edges: Array<Maybe<any>>;
};

and then have PolicyTypeConnection and every other *TypeConnection type extend that type.

Is there any way to get graphql-codegen to do something like this (perhaps using the scalar config option somehow?), or is the only solution to modify the generated types?

0

There are 0 best solutions below