Skip to content

Commit 9839538

Browse files
authored
feat(cli): default output to ./graffle (#1051)
1 parent ccd85ed commit 9839538

File tree

8 files changed

+12
-13
lines changed

8 files changed

+12
-13
lines changed

src/cli/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const args = Command.create().description(`Generate a type safe GraphQL client.`
2323
)
2424
.parameter(
2525
`output`,
26-
z.string().min(1).describe(
26+
z.string().min(1).default(`./graffle`).describe(
2727
`Directory path for where to output the generated TypeScript files.`,
2828
),
2929
)

src/layers/2_generator/files.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { generateCode, type Input as GenerateInput } from './generateCode.js'
99
import { fileExists } from './prelude.js'
1010

1111
export interface Input {
12-
outputDirPath: string
12+
outputDirPath?: string
1313
name?: string
1414
code?: Omit<GenerateInput, 'schemaSource' | 'sourceDirPath' | 'options'>
1515
defaultSchemaUrl?: URL
@@ -62,12 +62,12 @@ const resolveSourceSchema = async (input: Input) => {
6262
export const generateFiles = async (input: Input) => {
6363
const sourceDirPath = input.sourceDirPath ?? process.cwd()
6464
const schemaSource = await resolveSourceSchema(input)
65-
65+
const outputDirPath = input.outputDirPath ?? Path.join(process.cwd(), `./graffle`)
6666
// todo support other extensions: .tsx,.js,.mjs,.cjs
6767
const customScalarCodecsFilePath = input.sourceCustomScalarCodecsFilePath
6868
?? Path.join(sourceDirPath, `customScalarCodecs.ts`)
6969
const customScalarCodecsImportPath = Path.relative(
70-
input.outputDirPath,
70+
outputDirPath,
7171
customScalarCodecsFilePath.replace(/\.ts$/, `.js`),
7272
)
7373
const customScalarCodecsPathExists = await fileExists(customScalarCodecsFilePath)
@@ -91,10 +91,10 @@ export const generateFiles = async (input: Input) => {
9191
},
9292
})
9393

94-
await fs.mkdir(input.outputDirPath, { recursive: true })
94+
await fs.mkdir(outputDirPath, { recursive: true })
9595
await Promise.all(
9696
codes.map((code) => {
97-
return fs.writeFile(`${input.outputDirPath}/${code.moduleName}.ts`, code.code, { encoding: `utf8` })
97+
return fs.writeFile(`${outputDirPath}/${code.moduleName}.ts`, code.code, { encoding: `utf8` })
9898
}),
9999
)
100100
}

website/content/guides/overview/getting-started-generated.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ pnpm add graffle graphql
1010

1111
## Generate Client Lib
1212

13-
<!-- TODO Default the output and name to "graffle" -->
14-
1513
Now you have access to the `graffle` command line interface in your project. Use it to generate a client. We will use a simple publicly available GraphQL API for our schema source.
1614

1715
```sh

website/graffle/Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { createPrefilled } from 'graphql-request/graffle/client'
22

33
import { $defaultSchemaUrl, $Index } from './SchemaRuntime.js'
44

5-
export const create = createPrefilled(`graffle`, $Index, $defaultSchemaUrl)
5+
export const create = createPrefilled(`default`, $Index, $defaultSchemaUrl)

website/graffle/Global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Index } from './Index.js'
33
declare global {
44
export namespace GraphQLRequestTypes {
55
export interface Schemas {
6-
graffle: {
6+
default: {
77
index: Index
88
customScalars: {}
99
featureOptions: {

website/graffle/Index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type * as Schema from './SchemaBuildtime.js'
44

55
export interface Index {
6-
name: 'graffle'
6+
name: 'default'
77
Root: {
88
Query: Schema.Root.Query
99
Mutation: null

website/graffle/SchemaRuntime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const Query = $.Object$(`Query`, {
9999
})
100100

101101
export const $Index = {
102-
name: 'graffle' as const,
102+
name: 'default' as const,
103103
Root: {
104104
Query,
105105
Mutation: null,

website/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"scripts": {
44
"dev": "vitepress dev",
55
"build": "vitepress build",
6-
"preview": "vitepress preview"
6+
"preview": "vitepress preview",
7+
"gen:graffle:default": "graffle --schema https://countries.trevorblades.com/graphql"
78
},
89
"devDependencies": {
910
"vitepress": "^1.3.3"

0 commit comments

Comments
 (0)