Skip to content

Commit

Permalink
fix(generator): align exports with docs (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Oct 25, 2024
1 parent 11033e9 commit a54e411
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/entrypoints/_Generator.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { generate } from '../generator/_.js'
export { create } from '../generator/configFile/builder.js'
export { configure } from '../generator/configFile/builder.js'
10 changes: 5 additions & 5 deletions src/extensions/SchemaErrors/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This extension requires generation and also itself extends the generator. You mu
// graffle.config.ts

import { SchemaErrors } from 'graffle/extensions'
import { Graffle } from 'graffle/generator'
import { Generator } from 'graffle/generator'

export default Graffle
export default Generator
.create()
.use(SchemaErrors())
```
Expand All @@ -38,10 +38,10 @@ By default all objects whose name begin with `Error` will be considered to be "e
```ts
// graffle.config.ts
import { SchemaErrors } from 'graffle/extensions/schema-errors/generator'
import { Graffle } from 'graffle/generator'
import { Generator } from 'graffle/generator'

export default Graffle
.create()
export default Generator
.configure()
.use(SchemaErrors({
isErrorType: (type) => type.name.match(/^Foo/),
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Generator } from '../../../../entrypoints/generator.js'
import { SchemaErrors } from '../../generator.js'

export default Generator
.create({
.configure({
name: `GraffleSchemaErrors`,
schema,
lint: {
Expand Down
4 changes: 2 additions & 2 deletions src/generator/configFile/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Builder {
use: (extension: Extension) => Builder
}

export const create = (input: BuilderInput): Builder => {
export const configure = (input: BuilderInput): Builder => {
return {
_: {
input,
Expand All @@ -24,7 +24,7 @@ export const create = (input: BuilderInput): Builder => {
* todo
*/
use: (extension) => {
return create({
return configure({
...input,
extensions: [...(input.extensions ?? []), extension],
})
Expand Down
22 changes: 21 additions & 1 deletion website/content/guides/50_appendix/15_about-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,30 @@ The CLI has built in help that you can use to learn about all its inputs.
pnpm graffle --help
```

## Configuration File

The CLI will by default look for a `graffle.config.{js,ts,mts,mjs}` file in your project. If found, it will use the default export as configuration. Any arguments you provide on the command line will take precedence over the configuration file.

```ts
// graffle.config.ts
import { SchemaErrors } from 'graffle/extensions/schema-errors/generator'
import { Generator } from 'graffle/generator'

export default Generator.configure({
lint: {
missingCustomScalarCodec: false,
},
})
```

## API

If you need to script graffle client generation then you can drop to the underlying Graffle generator API. It is largely one-to-one with the CLI. Use its JSDoc to learn about all its inputs.

```ts
import { generate } from 'graffle/generator'
import { Generator } from 'graffle/generator'

await Generator.generate({
// ...
})
```

0 comments on commit a54e411

Please sign in to comment.