Recently, I received an auto-generated GraphQL schema mapping that looks like this:
export const generatedSchema = {
query: {
__typename: { __type: 'String!' },
account_sample: {
__type: '[account_sample!]!',
__args: {
distinct_on: '[account_sample_select_column!]',
limit: 'Int',
offset: 'Int',
order_by: '[account_sample_order_by!]',
where: 'account_sample_bool_exp',
},
},
...
}
}
Now, I am eager to create a properly typed object to manipulate inside my implementation, specifically corresponding to the __args object depicted above.
Would it be feasible in TypeScript? In my main logic, I attempted the following:
import { generatedSchema } from '../generated/graphql';
let parms: typeof generatedSchema.query.account_sample.__args;
parms.limit = 400;
Although Vetur seems to comprehend the type we are using, it presents an error when I try to assign values:
(property) limit: "Int"
Cannot assign to 'limit' because it is a read-only property. Vetur(2540)
I am hopeful that there is a basic aspect of TypeScript that I might be overlooking.
UPDATE:
Upon examining the auto-generated GraphQL schema more closely, I have identified a more suitable candidate for the actual datatype I intend to utilize externally:
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>;
...
}
Do you have any insights on how to import THAT 'args' object as a usable type in a calling program? The objective is to import something that would provide a usable object in my calling program similar to the manually declared:
interface SuperArgs {
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>;
}