[Feature] Generate and export acumulated types of schema fields
PabloSzx opened this issue · 3 comments
PabloSzx commented
Right now @gqless/cli
only generates the types of every argument by itself and inlines them, but it should also generate a separated and exported type of every argument together.
export interface Query {
__typename: 'Query' | undefined;
account_sample: (args?: {
distinct_on?: Maybe<Array<account_sample_select_column>>;
limit?: Maybe<Scalars['Int']>;
offset?: Maybe<Scalars['Int']>;
order_by?: Maybe<Array<account_sample_order_by>>;
where?: Maybe<account_sample_bool_exp>;
}) => Array<account_sample>;
...
}
The current workaround is to use TypeScript's Paramaters
:
type SuperArgs = Parameters<typeof Query.account_sample>[0]
Thanks to slumtrimpet for the heads up via Discord and the Stack Overflow question
vicary commented
We tried convention naming which looks like export type QueryAccountSampleInput
and I think it is awkward.
How about a simple utility such as Input<typeof Query.account_sample>
?
PabloSzx commented
New utility type available in gqty@2.0.2, Variables / Args
import { query, Query } from '../gqty';
import type { Variables, Args } from 'gqty';
function getUserName(args: Variables<Query['user']>) {
return query.user(args).name;
}
function getUserEmail(args: Args<typeof query['user']>) {
return query.user(args).email;
}