|
1 | | -import { createTypeSpecLibrary } from "@typespec/compiler"; |
| 1 | +import { createTypeSpecLibrary, type JSONSchemaType } from "@typespec/compiler"; |
2 | 2 |
|
3 | | -export const $lib = createTypeSpecLibrary({ |
| 3 | +export interface GraphQLEmitterOptions { |
| 4 | + /** |
| 5 | + * Name of the output file. |
| 6 | + * Output file will interpolate the following values: |
| 7 | + * - schema-name: Name of the schema if multiple |
| 8 | + * |
| 9 | + * @default `{schema-name}.graphql` |
| 10 | + * |
| 11 | + * @example Single schema |
| 12 | + * - `schema.graphql` |
| 13 | + * |
| 14 | + * @example Multiple schemas |
| 15 | + * - `Org1.Schema1.graphql` |
| 16 | + * - `Org1.Schema2.graphql` |
| 17 | + */ |
| 18 | + "output-file"?: string; |
| 19 | + |
| 20 | + /** |
| 21 | + * Set the newline character for emitting files. |
| 22 | + * @default lf |
| 23 | + */ |
| 24 | + "new-line"?: "crlf" | "lf"; |
| 25 | + |
| 26 | + /** |
| 27 | + * Omit unreachable types. |
| 28 | + * By default all types declared under the schema namespace will be included. With this flag on only types references in an operation will be emitted. |
| 29 | + * @default false |
| 30 | + */ |
| 31 | + "omit-unreachable-types"?: boolean; |
| 32 | + |
| 33 | + /** |
| 34 | + * Only emit types if a correct GraphQL translation type is found. Don't emit Any types and operations that don't have the GraphQL decorators. |
| 35 | + * By default a best effort is made to emit all types. |
| 36 | + * @default false |
| 37 | + */ |
| 38 | + strict?: boolean; |
| 39 | +} |
| 40 | + |
| 41 | +const EmitterOptionsSchema: JSONSchemaType<GraphQLEmitterOptions> = { |
| 42 | + type: "object", |
| 43 | + additionalProperties: false, |
| 44 | + properties: { |
| 45 | + "output-file": { |
| 46 | + type: "string", |
| 47 | + nullable: true, |
| 48 | + description: [ |
| 49 | + "Name of the output file.", |
| 50 | + " Output file will interpolate the following values:", |
| 51 | + " - schema-name: Name of the schema if multiple", |
| 52 | + "", |
| 53 | + " Default: `{schema-name}.graphql`", |
| 54 | + "", |
| 55 | + " Example Single schema", |
| 56 | + " - `schema.graphql`", |
| 57 | + "", |
| 58 | + " Example Multiple schemas", |
| 59 | + " - `Org1.Schema1.graphql`", |
| 60 | + " - `Org1.Schema2.graphql`", |
| 61 | + ].join("\n"), |
| 62 | + }, |
| 63 | + "new-line": { |
| 64 | + type: "string", |
| 65 | + enum: ["crlf", "lf"], |
| 66 | + default: "lf", |
| 67 | + nullable: true, |
| 68 | + description: "Set the newLine character for emitting files.", |
| 69 | + }, |
| 70 | + "omit-unreachable-types": { |
| 71 | + type: "boolean", |
| 72 | + nullable: true, |
| 73 | + description: [ |
| 74 | + "Omit unreachable types.", |
| 75 | + "By default all types declared under the schema namespace will be included.", |
| 76 | + "With this flag on only types references in an operation will be emitted.", |
| 77 | + ].join("\n"), |
| 78 | + }, |
| 79 | + strict: { |
| 80 | + type: "boolean", |
| 81 | + nullable: true, |
| 82 | + description: [ |
| 83 | + "Only emit types if a correct GraphQL translation type is found.", |
| 84 | + "Don't emit Any types and operations that don't have the GraphQL decorators.", |
| 85 | + "By default a best effort is made to emit all types.", |
| 86 | + ].join("\n"), |
| 87 | + }, |
| 88 | + }, |
| 89 | + required: [], |
| 90 | +}; |
| 91 | + |
| 92 | +export const libDef = { |
4 | 93 | name: "@typespec/graphql", |
5 | 94 | diagnostics: {}, |
6 | | -}); |
| 95 | + emitter: { |
| 96 | + options: EmitterOptionsSchema as JSONSchemaType<GraphQLEmitterOptions>, |
| 97 | + }, |
| 98 | +} as const; |
| 99 | + |
| 100 | +export const $lib = createTypeSpecLibrary(libDef); |
7 | 101 |
|
8 | 102 | export const { reportDiagnostic, createDiagnostic } = $lib; |
0 commit comments