Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): default output to ./graffle #1051

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const args = Command.create().description(`Generate a type safe GraphQL client.`
)
.parameter(
`output`,
z.string().min(1).describe(
z.string().min(1).default(`./graffle`).describe(
`Directory path for where to output the generated TypeScript files.`,
),
)
Expand Down
10 changes: 5 additions & 5 deletions src/layers/2_generator/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { generateCode, type Input as GenerateInput } from './generateCode.js'
import { fileExists } from './prelude.js'

export interface Input {
outputDirPath: string
outputDirPath?: string
name?: string
code?: Omit<GenerateInput, 'schemaSource' | 'sourceDirPath' | 'options'>
defaultSchemaUrl?: URL
Expand Down Expand Up @@ -62,12 +62,12 @@ const resolveSourceSchema = async (input: Input) => {
export const generateFiles = async (input: Input) => {
const sourceDirPath = input.sourceDirPath ?? process.cwd()
const schemaSource = await resolveSourceSchema(input)

const outputDirPath = input.outputDirPath ?? Path.join(process.cwd(), `./graffle`)
// todo support other extensions: .tsx,.js,.mjs,.cjs
const customScalarCodecsFilePath = input.sourceCustomScalarCodecsFilePath
?? Path.join(sourceDirPath, `customScalarCodecs.ts`)
const customScalarCodecsImportPath = Path.relative(
input.outputDirPath,
outputDirPath,
customScalarCodecsFilePath.replace(/\.ts$/, `.js`),
)
const customScalarCodecsPathExists = await fileExists(customScalarCodecsFilePath)
Expand All @@ -91,10 +91,10 @@ export const generateFiles = async (input: Input) => {
},
})

await fs.mkdir(input.outputDirPath, { recursive: true })
await fs.mkdir(outputDirPath, { recursive: true })
await Promise.all(
codes.map((code) => {
return fs.writeFile(`${input.outputDirPath}/${code.moduleName}.ts`, code.code, { encoding: `utf8` })
return fs.writeFile(`${outputDirPath}/${code.moduleName}.ts`, code.code, { encoding: `utf8` })
}),
)
}
2 changes: 0 additions & 2 deletions website/content/guides/overview/getting-started-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pnpm add graffle graphql

## Generate Client Lib

<!-- TODO Default the output and name to "graffle" -->

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.

```sh
Expand Down
2 changes: 1 addition & 1 deletion website/graffle/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { createPrefilled } from 'graphql-request/graffle/client'

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

export const create = createPrefilled(`graffle`, $Index, $defaultSchemaUrl)
export const create = createPrefilled(`default`, $Index, $defaultSchemaUrl)
2 changes: 1 addition & 1 deletion website/graffle/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Index } from './Index.js'
declare global {
export namespace GraphQLRequestTypes {
export interface Schemas {
graffle: {
default: {
index: Index
customScalars: {}
featureOptions: {
Expand Down
2 changes: 1 addition & 1 deletion website/graffle/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type * as Schema from './SchemaBuildtime.js'

export interface Index {
name: 'graffle'
name: 'default'
Root: {
Query: Schema.Root.Query
Mutation: null
Expand Down
2 changes: 1 addition & 1 deletion website/graffle/SchemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const Query = $.Object$(`Query`, {
})

export const $Index = {
name: 'graffle' as const,
name: 'default' as const,
Root: {
Query,
Mutation: null,
Expand Down
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scripts": {
"dev": "vitepress dev",
"build": "vitepress build",
"preview": "vitepress preview"
"preview": "vitepress preview",
"gen:graffle:default": "graffle --schema https://countries.trevorblades.com/graphql"
},
"devDependencies": {
"vitepress": "^1.3.3"
Expand Down