Skip to content

Commit 4942054

Browse files
authored
Refine generated schema (#1773)
* fix(package/cli): refine generated schema types * chore(package/cli): apply copilot suggestions * chore: changeset
1 parent 13fa932 commit 4942054

File tree

17 files changed

+21089
-631
lines changed

17 files changed

+21089
-631
lines changed

.changeset/every-snails-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gqty/cli': major
3+
---
4+
5+
Split ScalarsEnums and increased default Cache expiry in the generated client

.changeset/pretty-bats-shave.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'gqty': minor
33
---
44

5-
feat(package/gqty): Allow subscription to all cache changes
5+
Allow subscription to all cache changes

examples/gnt/app/1588-infinite-fetch/gqty/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ const queryFetcher: QueryFetcher = async function (
5050
const cache = new Cache(
5151
undefined,
5252
/**
53-
* Default option is immediate cache expiry but keep it for 5 minutes,
53+
* Cache is valid for 30 minutes, but starts revalidating after 5 seconds,
5454
* allowing soft refetches in background.
5555
*/
5656
{
57-
maxAge: 0,
58-
staleWhileRevalidate: 5 * 60 * 1000,
57+
maxAge: 5000,
58+
staleWhileRevalidate: 30 * 60 * 1000,
5959
normalization: true,
6060
}
6161
);

examples/gnt/gqty/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ const queryFetcher: QueryFetcher = async function (
4040
const cache = new Cache(
4141
undefined,
4242
/**
43-
* Default option is immediate cache expiry but keep it for 5 minutes,
43+
* Cache is valid for 30 minutes, but starts revalidating after 5 seconds,
4444
* allowing soft refetches in background.
4545
*/
4646
{
47-
maxAge: 0,
48-
staleWhileRevalidate: 5 * 60 * 1000,
47+
maxAge: 5000,
48+
staleWhileRevalidate: 30 * 60 * 1000,
4949
normalization: true,
5050
}
5151
);

examples/gnt/gqty/schema.generated.ts

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* GQty AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
33
*/
44

5+
import { type ScalarsEnumsHash } from 'gqty';
6+
57
export type Maybe<T> = T | null;
68
export type InputMaybe<T> = Maybe<T>;
79
export type Exact<T extends { [key: string]: unknown }> = {
@@ -13,15 +15,24 @@ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
1315
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
1416
[SubKey in K]: Maybe<T[SubKey]>;
1517
};
18+
export type MakeEmpty<
19+
T extends { [key: string]: unknown },
20+
K extends keyof T
21+
> = { [_ in K]?: never };
22+
export type Incremental<T> =
23+
| T
24+
| {
25+
[P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never;
26+
};
1627
/** All built-in and custom scalars, mapped to their actual values */
1728
export interface Scalars {
18-
ID: string;
19-
String: string;
20-
Boolean: boolean;
21-
Int: number;
22-
Float: number;
29+
ID: { input: string; output: string };
30+
String: { input: string; output: string };
31+
Boolean: { input: boolean; output: boolean };
32+
Int: { input: number; output: number };
33+
Float: { input: number; output: number };
2334
/** The `Upload` scalar type represents a file upload. */
24-
Upload: any;
35+
Upload: { input: any; output: any };
2536
}
2637

2738
export enum CacheControlScope {
@@ -30,25 +41,25 @@ export enum CacheControlScope {
3041
}
3142

3243
export interface FilterCharacter {
33-
gender?: InputMaybe<Scalars['String']>;
34-
name?: InputMaybe<Scalars['String']>;
35-
species?: InputMaybe<Scalars['String']>;
36-
status?: InputMaybe<Scalars['String']>;
37-
type?: InputMaybe<Scalars['String']>;
44+
gender?: InputMaybe<Scalars['String']['input']>;
45+
name?: InputMaybe<Scalars['String']['input']>;
46+
species?: InputMaybe<Scalars['String']['input']>;
47+
status?: InputMaybe<Scalars['String']['input']>;
48+
type?: InputMaybe<Scalars['String']['input']>;
3849
}
3950

4051
export interface FilterEpisode {
41-
episode?: InputMaybe<Scalars['String']>;
42-
name?: InputMaybe<Scalars['String']>;
52+
episode?: InputMaybe<Scalars['String']['input']>;
53+
name?: InputMaybe<Scalars['String']['input']>;
4354
}
4455

4556
export interface FilterLocation {
46-
dimension?: InputMaybe<Scalars['String']>;
47-
name?: InputMaybe<Scalars['String']>;
48-
type?: InputMaybe<Scalars['String']>;
57+
dimension?: InputMaybe<Scalars['String']['input']>;
58+
name?: InputMaybe<Scalars['String']['input']>;
59+
type?: InputMaybe<Scalars['String']['input']>;
4960
}
5061

51-
export const scalarsEnumsHash: import('gqty').ScalarsEnumsHash = {
62+
export const scalarsEnumsHash: ScalarsEnumsHash = {
5263
Boolean: true,
5364
CacheControlScope: true,
5465
ID: true,
@@ -154,48 +165,48 @@ export interface Character {
154165
/**
155166
* Time at which the character was created in the database.
156167
*/
157-
created?: Maybe<ScalarsEnums['String']>;
168+
created?: Maybe<Scalars['String']['output']>;
158169
/**
159170
* Episodes in which this character appeared.
160171
*/
161172
episode: Array<Maybe<Episode>>;
162173
/**
163174
* The gender of the character ('Female', 'Male', 'Genderless' or 'unknown').
164175
*/
165-
gender?: Maybe<ScalarsEnums['String']>;
176+
gender?: Maybe<Scalars['String']['output']>;
166177
/**
167178
* The id of the character.
168179
*/
169-
id?: Maybe<ScalarsEnums['ID']>;
180+
id?: Maybe<Scalars['ID']['output']>;
170181
/**
171182
* Link to the character's image.
172183
* All images are 300x300px and most are medium shots or portraits since they are intended to be used as avatars.
173184
*/
174-
image?: Maybe<ScalarsEnums['String']>;
185+
image?: Maybe<Scalars['String']['output']>;
175186
/**
176187
* The character's last known location
177188
*/
178189
location?: Maybe<Location>;
179190
/**
180191
* The name of the character.
181192
*/
182-
name?: Maybe<ScalarsEnums['String']>;
193+
name?: Maybe<Scalars['String']['output']>;
183194
/**
184195
* The character's origin location
185196
*/
186197
origin?: Maybe<Location>;
187198
/**
188199
* The species of the character.
189200
*/
190-
species?: Maybe<ScalarsEnums['String']>;
201+
species?: Maybe<Scalars['String']['output']>;
191202
/**
192203
* The status of the character ('Alive', 'Dead' or 'unknown').
193204
*/
194-
status?: Maybe<ScalarsEnums['String']>;
205+
status?: Maybe<Scalars['String']['output']>;
195206
/**
196207
* The type or subspecies of the character.
197208
*/
198-
type?: Maybe<ScalarsEnums['String']>;
209+
type?: Maybe<Scalars['String']['output']>;
199210
}
200211

201212
export interface Characters {
@@ -209,27 +220,27 @@ export interface Episode {
209220
/**
210221
* The air date of the episode.
211222
*/
212-
air_date?: Maybe<ScalarsEnums['String']>;
223+
air_date?: Maybe<Scalars['String']['output']>;
213224
/**
214225
* List of characters who have been seen in the episode.
215226
*/
216227
characters: Array<Maybe<Character>>;
217228
/**
218229
* Time at which the episode was created in the database.
219230
*/
220-
created?: Maybe<ScalarsEnums['String']>;
231+
created?: Maybe<Scalars['String']['output']>;
221232
/**
222233
* The code of the episode.
223234
*/
224-
episode?: Maybe<ScalarsEnums['String']>;
235+
episode?: Maybe<Scalars['String']['output']>;
225236
/**
226237
* The id of the episode.
227238
*/
228-
id?: Maybe<ScalarsEnums['ID']>;
239+
id?: Maybe<Scalars['ID']['output']>;
229240
/**
230241
* The name of the episode.
231242
*/
232-
name?: Maybe<ScalarsEnums['String']>;
243+
name?: Maybe<Scalars['String']['output']>;
233244
}
234245

235246
export interface Episodes {
@@ -243,47 +254,47 @@ export interface Info {
243254
/**
244255
* The length of the response.
245256
*/
246-
count?: Maybe<ScalarsEnums['Int']>;
257+
count?: Maybe<Scalars['Int']['output']>;
247258
/**
248259
* Number of the next page (if it exists)
249260
*/
250-
next?: Maybe<ScalarsEnums['Int']>;
261+
next?: Maybe<Scalars['Int']['output']>;
251262
/**
252263
* The amount of pages.
253264
*/
254-
pages?: Maybe<ScalarsEnums['Int']>;
265+
pages?: Maybe<Scalars['Int']['output']>;
255266
/**
256267
* Number of the previous page (if it exists)
257268
*/
258-
prev?: Maybe<ScalarsEnums['Int']>;
269+
prev?: Maybe<Scalars['Int']['output']>;
259270
}
260271

261272
export interface Location {
262273
__typename?: 'Location';
263274
/**
264275
* Time at which the location was created in the database.
265276
*/
266-
created?: Maybe<ScalarsEnums['String']>;
277+
created?: Maybe<Scalars['String']['output']>;
267278
/**
268279
* The dimension in which the location is located.
269280
*/
270-
dimension?: Maybe<ScalarsEnums['String']>;
281+
dimension?: Maybe<Scalars['String']['output']>;
271282
/**
272283
* The id of the location.
273284
*/
274-
id?: Maybe<ScalarsEnums['ID']>;
285+
id?: Maybe<Scalars['ID']['output']>;
275286
/**
276287
* The name of the location.
277288
*/
278-
name?: Maybe<ScalarsEnums['String']>;
289+
name?: Maybe<Scalars['String']['output']>;
279290
/**
280291
* List of characters who have been last seen in the location.
281292
*/
282293
residents: Array<Maybe<Character>>;
283294
/**
284295
* The type of the location.
285296
*/
286-
type?: Maybe<ScalarsEnums['String']>;
297+
type?: Maybe<Scalars['String']['output']>;
287298
}
288299

289300
export interface Locations {
@@ -301,53 +312,53 @@ export interface Query {
301312
/**
302313
* Get a specific character by ID
303314
*/
304-
character: (args: { id: Scalars['ID'] }) => Maybe<Character>;
315+
character: (args: { id: Scalars['ID']['input'] }) => Maybe<Character>;
305316
/**
306317
* Get the list of all characters
307318
*/
308319
characters: (args?: {
309320
filter?: Maybe<FilterCharacter>;
310-
page?: Maybe<Scalars['Int']>;
321+
page?: Maybe<Scalars['Int']['input']>;
311322
}) => Maybe<Characters>;
312323
/**
313324
* Get a list of characters selected by ids
314325
*/
315326
charactersByIds: (args: {
316-
ids: Array<Scalars['ID']>;
327+
ids: Array<Scalars['ID']['input']>;
317328
}) => Maybe<Array<Maybe<Character>>>;
318329
/**
319330
* Get a specific episode by ID
320331
*/
321-
episode: (args: { id: Scalars['ID'] }) => Maybe<Episode>;
332+
episode: (args: { id: Scalars['ID']['input'] }) => Maybe<Episode>;
322333
/**
323334
* Get the list of all episodes
324335
*/
325336
episodes: (args?: {
326337
filter?: Maybe<FilterEpisode>;
327-
page?: Maybe<Scalars['Int']>;
338+
page?: Maybe<Scalars['Int']['input']>;
328339
}) => Maybe<Episodes>;
329340
/**
330341
* Get a list of episodes selected by ids
331342
*/
332343
episodesByIds: (args: {
333-
ids: Array<Scalars['ID']>;
344+
ids: Array<Scalars['ID']['input']>;
334345
}) => Maybe<Array<Maybe<Episode>>>;
335346
/**
336347
* Get a specific locations by ID
337348
*/
338-
location: (args: { id: Scalars['ID'] }) => Maybe<Location>;
349+
location: (args: { id: Scalars['ID']['input'] }) => Maybe<Location>;
339350
/**
340351
* Get the list of all locations
341352
*/
342353
locations: (args?: {
343354
filter?: Maybe<FilterLocation>;
344-
page?: Maybe<Scalars['Int']>;
355+
page?: Maybe<Scalars['Int']['input']>;
345356
}) => Maybe<Locations>;
346357
/**
347358
* Get a list of locations selected by ids
348359
*/
349360
locationsByIds: (args: {
350-
ids: Array<Scalars['ID']>;
361+
ids: Array<Scalars['ID']['input']>;
351362
}) => Maybe<Array<Maybe<Location>>>;
352363
}
353364

@@ -361,10 +372,16 @@ export interface GeneratedSchema {
361372
subscription: Subscription;
362373
}
363374

364-
export type MakeNullable<T> = {
365-
[K in keyof T]: T[K] | undefined;
366-
};
375+
type Enums = {};
367376

368-
export interface ScalarsEnums extends MakeNullable<Scalars> {
369-
CacheControlScope: CacheControlScope | undefined;
370-
}
377+
export type InputFields = {
378+
[Key in keyof Scalars]: Scalars[Key] extends { input: unknown }
379+
? Scalars[Key]['input']
380+
: never;
381+
} & Enums;
382+
383+
export type OutputFields = {
384+
[Key in keyof Scalars]: Scalars[Key] extends { output: unknown }
385+
? Scalars[Key]['output']
386+
: never;
387+
} & Enums;

0 commit comments

Comments
 (0)