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

fix(generator): align exports with docs #1218

Merged
merged 1 commit into from
Oct 25, 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/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({
// ...
})
```