Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit48e4d64

Browse files
authored
feat: introduce a CLI for generating the client (#730)
1 parentdb7c8c5 commit48e4d64

File tree

3 files changed

+122
-8
lines changed

3 files changed

+122
-8
lines changed

‎package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name":"graphql-request",
33
"version":"0.0.0-dripip",
44
"type":"module",
5+
"bin": {
6+
"graphql-request":"./build/cli/generate.js",
7+
"gr":"./build/cli/generate.js"
8+
},
59
"exports": {
610
".": {
711
"import": {
@@ -52,7 +56,7 @@
5256
"check:lint":"eslint . --ext .ts,.tsx --max-warnings 0",
5357
"prepublishOnly":"pnpm build",
5458
"build:docs":"doctoc README.md --notitle && dprint fmt README.md",
55-
"build":"pnpm clean && pnpm tsc --project tsconfig.build.json",
59+
"build":"pnpm clean && pnpm tsc --project tsconfig.build.json && chmod +x ./build/cli/generate.js",
5660
"clean":"tsc --build --clean && rm -rf build",
5761
"test":"vitest",
5862
"test:types":"vitest --typecheck",
@@ -64,7 +68,9 @@
6468
"dependencies": {
6569
"@dprint/formatter":"^0.2.1",
6670
"@graphql-typed-document-node/core":"^3.2.0",
67-
"dprint":"^0.45.0"
71+
"@molt/command":"^0.9.0",
72+
"dprint":"^0.45.0",
73+
"zod":"^3.22.4"
6874
},
6975
"peerDependencies": {
7076
"graphql":"14 - 16"

‎pnpm-lock.yaml

Lines changed: 90 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/cli/generate.ts

100644100755
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
import{generateFile}from'../generator/generator.js'
1+
#!/usr/bin/env node
22

3-
awaitgenerateFile({
4-
schemaPath:`./examples/schema.graphql`,
5-
typeScriptPath:`./src/demo.ts`,
6-
})
3+
import{Command}from'@molt/command'
4+
import*asfsfrom'node:fs/promises'
5+
import{z}from'zod'
6+
import{generateCode}from'../generator/generator.js'
7+
8+
constargs=Command.create().description(`Generate a type safe GraphQL client.`)
9+
.parameter(`schemaPath`,z.string().min(1).describe(`File path to where your GraphQL schema is.`))
10+
.parameter(
11+
`output`,
12+
z.string().min(1).optional().describe(
13+
`File path for where to output the generated TypeScript types. If not given, outputs to stdout.`,
14+
),
15+
)
16+
.parse()
17+
18+
constschemaSource=awaitfs.readFile(args.schemaPath,`utf8`)
19+
constcode=generateCode({ schemaSource})
20+
21+
if(args.output){
22+
awaitfs.writeFile(args.output,code,{encoding:`utf8`})
23+
}else{
24+
console.log(code)
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp