Skip to content

Commit

Permalink
docs(cli): update type
Browse files Browse the repository at this point in the history
  • Loading branch information
Teages committed Jun 10, 2024
1 parent 9f53e34 commit 8c52c6e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 14 deletions.
71 changes: 59 additions & 12 deletions docs/cli/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,64 @@
## Type Definition

```ts
interface Config {
clients: (
| string // the url of endpoint
| {
url: string // the url of endpoint
method?: 'GET' | 'POST' // method to request the schema
headers?: Record<string, string> // custom headers
schemaOverride?: string | undefined // path to schema file, will use local file if provided
}
)[]
output: string // output directory
silent: boolean // disable console output
export interface Config {
/**
* The list of clients to generate types for.
*/
clients: ClientConfig[]
/**
* Output directory for generated code.
*/
output: string
/**
* Disable console output.
*/
silent: boolean
}
export type ClientConfig =
/**
* The URL of the GraphQL endpoint.
*/
| string
| {
/**
* The URL of the GraphQL endpoint.
*/
url: string
/**
* Override the way to get the schema.
* By default, the schema is fetched from the endpoint.
*/
schema?: SchemaConfig
}
export type SchemaConfig =
| {
type: 'path'
/**
* The path to the schema file.
*/
value: string
}
| {
type: 'sdl' | 'json'
/**
* The content of the GraphQL schema (json) or SDL.
*/
value: string
}
| {
type: 'url'
/**
* The method to fetch the schema from the URL.
*/
method?: 'GET' | 'POST'
/**
* The headers to send with the request.
*/
headers?: Record<string, string>
/**
* Override the url to fetch the schema.
*/
override?: string
}
```
43 changes: 41 additions & 2 deletions src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,32 @@ const schemaConfig = z.discriminatedUnion('type', [

export type SchemaConfig =
| {
type: 'path' | 'sdl' | 'json'
type: 'path'
/**
* The path to the schema file.
*/
value: string
} | {
}
| {
type: 'sdl' | 'json'
/**
* The content of the GraphQL schema (json) or SDL.
*/
value: string
}
| {
type: 'url'
/**
* The method to fetch the schema from the URL.
*/
method?: 'GET' | 'POST'
/**
* The headers to send with the request.
*/
headers?: Record<string, string>
/**
* Override the url to fetch the schema.
*/
override?: string
}

Expand All @@ -54,9 +74,19 @@ const clientConfig = z.union([
}),
])
export type ClientConfig =
/**
* The URL of the GraphQL endpoint.
*/
| string
| {
/**
* The URL of the GraphQL endpoint.
*/
url: string
/**
* Override the way to get the schema.
* By default, the schema is fetched from the endpoint.
*/
schema?: SchemaConfig
}

Expand All @@ -71,8 +101,17 @@ const configSchema = z.object({
.default(false),
})
export interface Config {
/**
* The list of clients to generate types for.
*/
clients: ClientConfig[]
/**
* Output directory for generated code.
*/
output: string
/**
* Disable console output.
*/
silent: boolean
}

Expand Down

0 comments on commit 8c52c6e

Please sign in to comment.