The best way to control Claude Code, Codex and more from any computer or phone

main
ts 84 lines 2.92 KB
Raw
1 /**
2 * Configuration for `graphql.config.ts`, exported with {@link defineConfig}.
3 * The `schema` and `documents` keys are compatible with graphql-config, so
4 * GraphQL editor extensions can share the file.
5 *
6 * ```ts
7 * import { defineConfig } from "@effect/graphql-generator/Config"
8 *
9 * export default defineConfig({
10 * schema: "./schema/github.graphql",
11 * documents: ["src/**\/*.graphql"],
12 * scalars: {
13 * GitObjectID: "effect/Schema#String"
14 * }
15 * })
16 * ```
17 *
18 * @since 4.0.0
19 */
20 import * as Schema from "effect/Schema"
21
22 /**
23 * A `"<module>#<export>"` reference to a `Schema` codec for a custom scalar.
24 * Relative modules resolve against the config file; bare modules are imported
25 * as written.
26 *
27 * @stability experimental
28 * @category schemas
29 * @since 4.0.0
30 */
31 export const ScalarSpecifier = Schema.TemplateLiteral([Schema.String, "#", Schema.String])
32
33 /**
34 * The configuration `Schema`, used to decode a config file's default export.
35 *
36 * - `schema`: the SDL (`.graphql`) or introspection JSON (`.json`) file,
37 * relative to the config file.
38 * - `documents`: glob patterns (`*`, `**`, `?`, `{a,b}`) for the executable
39 * `.graphql` or `.gql` documents, relative to the config file. Absolute
40 * patterns are a `ConfigError`, and a `{` without a closing `}` is a literal
41 * character. `node_modules` and dot-directories are skipped, and the schema
42 * file is never treated as a document.
43 * - `scalars`: a `Schema` codec per custom scalar, also able to override the
44 * built-in `Int`, `Float` and `ID`. Custom scalars named `DateTime` and `URI`
45 * default to `Schema.DateTimeUtcFromString` and `Schema.String`; `scalars`
46 * can override them too. Other unmapped custom scalars decode as `Schema.Json`.
47 * - `shared`: where the shared module goes. Defaults to the schema's name and
48 * directory, e.g. `github.graphql` or `github.json` gives
49 * `github.graphql.ts`. It can't be the schema, a document or a document's
50 * output.
51 * - `importExtension`: the extension used in imports between generated files
52 * and to relative scalar modules. Accepts `.ts` (default) or `.js`. A
53 * relative scalar module's `.ts`, `.js` or missing extension is replaced;
54 * any other extension, such as `.mjs`, is kept.
55 *
56 * @stability experimental
57 * @category schemas
58 * @since 4.0.0
59 */
60 export const Config = Schema.Struct({
61 schema: Schema.String,
62 documents: Schema.Array(Schema.String),
63 scalars: Schema.optional(Schema.Record(Schema.String, ScalarSpecifier)),
64 shared: Schema.optional(Schema.String),
65 importExtension: Schema.optional(Schema.Literals([".ts", ".js"]))
66 })
67
68 /**
69 * A decoded generator configuration.
70 *
71 * @stability experimental
72 * @category models
73 * @since 4.0.0
74 */
75 export type Config = typeof Config.Type
76
77 /**
78 * Types a config file's default export. It returns its argument unchanged.
79 *
80 * @stability experimental
81 * @category constructors
82 * @since 4.0.0
83 */
84 export const defineConfig = (config: Config): Config => config