Skip to content

Commit 3c5bc4a

Browse files
authored
feat(package/cli): upgrade graphql-codegen (#1634)
1 parent a81e7cb commit 3c5bc4a

19 files changed

+1544
-1179
lines changed

.changeset/fluffy-colts-confess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gqty/cli': major
3+
---
4+
5+
feat(package/cli): upgrade @graphql-codegen/typescript to v4

.github/workflows/release.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- '.husky/**'
1010
branches:
1111
- main
12+
1213
jobs:
1314
release:
1415
name: Release

examples/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"framer-motion": "^6.5.1",
3333
"gqty": "workspace:^",
3434
"graphql": "^16.6.0",
35-
"graphql-ez": "^0.16.0",
35+
"graphql-ez": "^0.16.1",
3636
"graphql-upload": "^13.0.0",
3737
"ms": "^2.1.3",
3838
"next": "^12.3.4",

internal/test-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"cross-env": "^7.0.3",
4141
"fastify": "^4.26.2",
4242
"graphql": "^16.6.0",
43-
"graphql-ez": "^0.16.0",
43+
"graphql-ez": "^0.16.1",
4444
"jest": "^29.5.0",
4545
"jest-watch-typeahead": "^2.2.2",
4646
"randomstring": "^1.2.3",

packages/cli/package.json

+12-16
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,39 @@
4242
"postpublish": "gh-release",
4343
"test": "jest",
4444
"test:watch": "jest --watch",
45-
"test:watch-coverage": "rimraf coverage && mkdirp coverage/lcov-report && concurrently --raw \"jest --watchAll\" \"serve -l 8787 coverage/lcov-report\" \"wait-on tcp:8787 coverage/lcov-report/index.html && open-cli http://localhost:8787\""
45+
"test:watch-coverage": "rimraf coverage && mkdir -p coverage/lcov-report && concurrently --raw \"jest --watchAll\" \"serve -l 8787 coverage/lcov-report\" \"wait-on tcp:8787 coverage/lcov-report/index.html && open-cli http://localhost:8787\""
4646
},
4747
"dependencies": {
48-
"@graphql-codegen/core": "^3.1.0",
49-
"@graphql-codegen/typescript": "^3.0.4",
50-
"@graphql-tools/delegate": "^9.0.35",
51-
"@graphql-tools/utils": "^9.2.1",
52-
"@graphql-tools/wrap": "^9.4.2",
48+
"@graphql-codegen/core": "^4.0.2",
49+
"@graphql-codegen/typescript": "^4.0.6",
50+
"@graphql-tools/delegate": "^10.0.4",
51+
"@graphql-tools/utils": "^10.1.3",
52+
"@graphql-tools/wrap": "^10.0.5",
53+
"@inquirer/prompts": "^5.0.1",
5354
"chalk": "^5.2.0",
5455
"commander": "^11.0.0",
55-
"cosmiconfig": "^8.1.3",
56-
"cross-fetch": "^3.1.5",
56+
"cosmiconfig": "^9.0.0",
57+
"cross-fetch": "^4.0.0",
5758
"fast-glob": "^3.2.12",
5859
"gqty": "workspace:^",
5960
"graphql": "^16.0.0",
60-
"inquirer": "^8.2.5",
6161
"lodash-es": "^4.17.21",
6262
"micromatch": "^4.0.5",
63-
"mkdirp": "^2.1.5",
6463
"prettier": "^2.8.6",
65-
"trading-signals": "^3.7.0"
64+
"trading-signals": "^5.0.1"
6665
},
6766
"devDependencies": {
68-
"@size-limit/preset-small-lib": "^8.2.6",
69-
"@types/inquirer": "^8.2.6",
67+
"@size-limit/preset-small-lib": "^11.1.2",
7068
"@types/lodash-es": "^4.17.12",
7169
"@types/micromatch": "^4.0.7",
72-
"@types/mkdirp": "^1.0.2",
73-
"@types/ms": "^0.7.31",
7470
"@types/node": "^18.15.5",
7571
"bob-tsm": "^1.1.2",
7672
"esbuild": "^0.17.12",
7773
"open-cli": "^7.2.0",
7874
"p-lazy": "^3.1.0",
7975
"rimraf": "^4.4.0",
8076
"serve": "^14.2.0",
81-
"size-limit": "^8.2.4",
77+
"size-limit": "^11.1.2",
8278
"test-utils": "workspace:^",
8379
"tmp-promise": "^3.0.3",
8480
"wait-on": "^7.0.1"

packages/cli/src/commands/default.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export const addCommand = (command: Command) => {
181181
// Watch mode
182182
if (options.watch) {
183183
const { printSchema } = await import('graphql');
184-
const { FasterSMA: SMA } = await import('trading-signals');
184+
const { FasterSMA: SMA } = await import('trading-signals/dist/SMA/SMA');
185185
const { default: throttle } = await import('lodash-es/throttle.js');
186186
const {
187187
default: { isMatch },
@@ -292,9 +292,7 @@ export const addCommand = (command: Command) => {
292292
};
293293

294294
const promptEndpoints = async (defaultEndpoint?: string) => {
295-
const { endpoints } = await inquirer.prompt<{ endpoints: string }>({
296-
name: 'endpoints',
297-
type: 'input',
295+
const endpoints = await inquirer.input({
298296
message: 'Where is your GraphQL endpoint or schema files?',
299297
default: defaultEndpoint,
300298
});
@@ -306,9 +304,7 @@ const promptEndpoints = async (defaultEndpoint?: string) => {
306304
};
307305

308306
const promptTarget = async (defaultTarget: string) => {
309-
const { target } = await inquirer.prompt<{ target: string }>({
310-
name: 'target',
311-
type: 'input',
307+
const target = await inquirer.input({
312308
message: 'Where should the client be generated?',
313309
default: defaultTarget,
314310
});
@@ -317,9 +313,7 @@ const promptTarget = async (defaultTarget: string) => {
317313
};
318314

319315
const promptReact = async (defaultValue: boolean) => {
320-
const { react } = await inquirer.prompt<{ react: boolean }>({
321-
name: 'react',
322-
type: 'confirm',
316+
const react = await inquirer.confirm({
323317
message: 'Are you using React with GQty?',
324318
default: defaultValue,
325319
});
@@ -328,9 +322,7 @@ const promptReact = async (defaultValue: boolean) => {
328322
};
329323

330324
const promptSubscriptions = async (defaultValue?: string) => {
331-
const { subscriptions } = await inquirer.prompt<{ subscriptions: string }>({
332-
name: 'subscriptions',
333-
type: 'input',
325+
const subscriptions = await inquirer.input({
334326
message: 'Do you need a subscription client? (Enter "-" to skip)',
335327
default: defaultValue?.trim() || undefined,
336328
});
@@ -339,9 +331,7 @@ const promptSubscriptions = async (defaultValue?: string) => {
339331
};
340332

341333
const promptTypescript = async (defaultValue: boolean) => {
342-
const { typescript } = await inquirer.prompt<{ typescript: boolean }>({
343-
name: 'typescript',
344-
type: 'confirm',
334+
const typescript = await inquirer.confirm({
345335
message: 'Do you want a TypeScript client over vanilla.js?',
346336
default: defaultValue,
347337
});

packages/cli/src/commands/default/fetchSchema.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ const fetchSchema = async (
174174
const promptHeaders = async () => {
175175
if (!process.stdin.isTTY) return;
176176

177-
const { headers } = await deps.inquirer.prompt<{ headers: string }>({
178-
name: 'headers',
179-
type: 'input',
177+
const headers = await deps.inquirer.input({
180178
message: `Any request headers? (Authorization: Bearer <token>, X-Foo: <bar>)`,
181179
});
182180

packages/cli/src/commands/default/generateClient.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ export const generateClient = async (
4949
};
5050

5151
const promptRegenerate = async (message: string): Promise<boolean> => {
52-
const { regenerate } = await inquirer.prompt<{ regenerate: boolean }>({
53-
type: 'confirm',
54-
name: 'regenerate',
52+
const regenerate = await inquirer.confirm({
5553
message,
5654
default: false,
5755
});

packages/cli/src/commands/default/promptInstall.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ export const promptInstall = async (configuration: GQtyConfig) => {
1111
const command = getUserPackageManager() ?? 'npm';
1212
const args = getInstallCommand(command).concat(packages);
1313

14-
const { install } = await inquirer.prompt<{ install: boolean }>({
15-
type: 'confirm',
16-
name: 'install',
14+
const install = await inquirer.confirm({
1715
message: `Do you want us to run "${command} ${args[0]}" for you?`,
1816
default: true,
1917
});

packages/cli/src/deps.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ export { codegen } from '@graphql-codegen/core';
22
export * as typescriptPlugin from '@graphql-codegen/typescript';
33
export { printSchemaWithDirectives } from '@graphql-tools/utils';
44
export { schemaFromExecutor, wrapSchema } from '@graphql-tools/wrap';
5+
export * as inquirer from '@inquirer/prompts';
56
export { program } from 'commander';
67
export { cosmiconfig, type Loader } from 'cosmiconfig';
78
export { fetch } from 'cross-fetch';
89
export { default as fg } from 'fast-glob';
910
export { buildSchema, printSchema } from 'graphql';
10-
export { default as inquirer } from 'inquirer';
1111
export { default as sortBy } from 'lodash-es/sortBy.js';
12-
export { default as mkdirp } from 'mkdirp';
1312
export { default as prettier, type Options as PrettierOptions } from 'prettier';

packages/cli/src/generate.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export interface GenerateOptions {
5353
* }
5454
* ```
5555
*/
56-
scalarTypes?: Record<string, string>;
56+
scalarTypes?: Exclude<
57+
deps.typescriptPlugin.TypeScriptPluginConfig['scalars'],
58+
string
59+
>;
5760
/**
5861
* Prepend code to the schema file, useful with the `scalarTypes` option.
5962
*/
@@ -177,7 +180,7 @@ export async function generate(
177180

178181
const codegenResultPromise = deps.codegen({
179182
schema: parse(deps.printSchemaWithDirectives(schema)),
180-
config: {} as deps.typescriptPlugin.TypeScriptPluginConfig,
183+
config: {} satisfies deps.typescriptPlugin.TypeScriptPluginConfig,
181184
documents: [],
182185
filename: 'gqty.generated.ts',
183186
pluginMap: {
@@ -186,14 +189,15 @@ export async function generate(
186189
plugins: [
187190
{
188191
typescript: {
192+
constEnums: true,
189193
onlyOperationTypes: true,
190194
declarationKind: 'interface',
191195
addUnderscoreToArgsType: true,
192196
scalars: scalarTypes,
193197
namingConvention: 'keep',
194198
enumsAsTypes: enumsAsStrings,
195199
enumsAsConst: enumsAsConst,
196-
} as deps.typescriptPlugin.TypeScriptPluginConfig,
200+
} satisfies deps.typescriptPlugin.TypeScriptPluginConfig,
197201
},
198202
],
199203
});
@@ -578,7 +582,7 @@ export async function generate(
578582
scalarsEnumsHash[pureType]
579583
? enumsNames.includes(pureType)
580584
? pureType
581-
: `Scalars["${pureType}"]`
585+
: `ScalarsEnums["${pureType}"]`
582586
: pureType,
583587
];
584588

@@ -754,13 +758,13 @@ export async function generate(
754758
subscription: Subscription
755759
}
756760
757-
export type MakeNullable<T> = {
758-
[K in keyof T]: T[K] | undefined;
759-
};
760-
761-
export interface ScalarsEnums extends MakeNullable<Scalars> {
761+
export type ScalarsEnums = {
762+
[Key in keyof Scalars]: Scalars[Key] extends { output: unknown }
763+
? Scalars[Key]['output']
764+
: never;
765+
} & {
762766
${deps.sortBy(enumsNames).reduce((acum, enumName) => {
763-
acum += `${enumName}: ${enumName} | undefined;`;
767+
acum += `${enumName}: ${enumName};`;
764768
return acum;
765769
}, '')}
766770
}

packages/cli/src/writeGenerate.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { existsSync, promises } from 'fs';
22
import { type GraphQLSchema } from 'graphql';
33
import { dirname, resolve } from 'path';
44
import { defaultConfig, type GQtyConfig } from './config';
5-
import * as deps from './deps.js';
65
import { generate, type TransformSchemaOptions } from './generate';
76

87
export type OnExistingFileConflict =
@@ -128,7 +127,7 @@ export async function writeGenerate(
128127

129128
const [{ clientCode, schemaCode, javascriptSchemaCode }] = await Promise.all([
130129
generate(schema, configuration, transformsGenerate),
131-
deps.mkdirp(dirname(destinationPath)),
130+
promises.mkdir(dirname(destinationPath), { recursive: true }),
132131
]);
133132

134133
await Promise.all([

0 commit comments

Comments
 (0)