-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce a CLI for generating the client (#730)
- Loading branch information
1 parent
db7c8c5
commit 48e4d64
Showing
3 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
import { generateFile } from '../generator/generator.js' | ||
#!/usr/bin/env node | ||
|
||
await generateFile({ | ||
schemaPath: `./examples/schema.graphql`, | ||
typeScriptPath: `./src/demo.ts`, | ||
}) | ||
import { Command } from '@molt/command' | ||
import * as fs from 'node:fs/promises' | ||
import { z } from 'zod' | ||
import { generateCode } from '../generator/generator.js' | ||
|
||
const args = Command.create().description(`Generate a type safe GraphQL client.`) | ||
.parameter(`schemaPath`, z.string().min(1).describe(`File path to where your GraphQL schema is.`)) | ||
.parameter( | ||
`output`, | ||
z.string().min(1).optional().describe( | ||
`File path for where to output the generated TypeScript types. If not given, outputs to stdout.`, | ||
), | ||
) | ||
.parse() | ||
|
||
const schemaSource = await fs.readFile(args.schemaPath, `utf8`) | ||
const code = generateCode({ schemaSource }) | ||
|
||
if (args.output) { | ||
await fs.writeFile(args.output, code, { encoding: `utf8` }) | ||
} else { | ||
console.log(code) | ||
} |