@inversable/codegen-subtypes
v1.0.1
Published
Plugin for GraphQL Code Generator that creates subtypes for each operation, similar to the output of Apollo codegen.
Downloads
550
Maintainers
Readme
Codegen Subtypes
Codegen Subtypes is a plugin for GraphQL Code Generator. The plugin generates subtypes for your GraphQL operations. The subtypes are very similar to the subtypes Apollo tooling generates.
Example
Example query:
query getContexts($userId: uuid!) {
auth_contexts {
id
name
AccountRoles(where: {account: {user_id: {_eq: $userId}}}) {
id
role
}
}
}
Default GraphQL Code Generator output (typescript-operations plugin)
export type get_contexts_query = {
auth_contexts: Array<{
__typename: 'auth_contexts',
id: any,
name: string | null,
AccountRoles: Array<{
__typename: 'auth_account_roles',
id: any, role: string
}>
}>
};
Additional types generated with Codegen Subtypes:
export type getContexts = get_contexts_query;
export type getContexts_auth_contexts = NonNullable<(NonNullable<get_contexts_query['auth_contexts']>)[number]>;
export type getContexts_auth_contexts_AccountRoles = NonNullable<(NonNullable<NonNullable<(NonNullable<get_contexts_query['auth_contexts']>)[number]>['AccountRoles']>)[number]>;
How to enable
Add package:
npm install -D @inversable/codegen-subtypes
Add @inversable/codegen-subtypes
as a plugin to your codegen.ts
.