@constructive-io/graphql-codegen 2.32.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +429 -1691
- package/cli/index.d.ts +5 -2
- package/cli/index.js +98 -581
- package/cli/shared.d.ts +35 -0
- package/cli/shared.js +106 -0
- package/{esm/cli → core}/codegen/barrel.d.ts +1 -1
- package/{cli → core}/codegen/barrel.js +1 -4
- package/{esm/cli → core}/codegen/index.d.ts +15 -5
- package/{cli → core}/codegen/index.js +44 -24
- package/{cli → core}/codegen/invalidation.d.ts +2 -2
- package/{esm/cli → core}/codegen/mutation-keys.d.ts +2 -2
- package/{cli → core}/codegen/orm/client-generator.js +2 -3
- package/{esm/cli → core}/codegen/orm/index.d.ts +9 -2
- package/{cli → core}/codegen/orm/index.js +3 -2
- package/{cli → core}/codegen/query-keys.d.ts +2 -2
- package/core/codegen/shared/index.d.ts +39 -0
- package/core/codegen/shared/index.js +118 -0
- package/core/config/index.d.ts +5 -0
- package/core/config/index.js +13 -0
- package/core/config/loader.d.ts +18 -0
- package/{cli/commands/init.js → core/config/loader.js} +7 -94
- package/core/config/resolver.d.ts +46 -0
- package/core/config/resolver.js +104 -0
- package/core/database/index.d.ts +43 -0
- package/core/database/index.js +85 -0
- package/core/generate.d.ts +22 -0
- package/core/generate.js +192 -0
- package/core/index.d.ts +13 -1
- package/core/index.js +22 -2
- package/{cli → core}/introspect/fetch-schema.js +58 -9
- package/core/introspect/source/api-schemas.d.ts +44 -0
- package/core/introspect/source/api-schemas.js +122 -0
- package/core/introspect/source/database.d.ts +32 -0
- package/core/introspect/source/database.js +91 -0
- package/core/introspect/source/index.d.ts +112 -0
- package/core/introspect/source/index.js +173 -0
- package/core/introspect/source/pgpm-module.d.ts +83 -0
- package/core/introspect/source/pgpm-module.js +200 -0
- package/core/output/index.d.ts +4 -0
- package/core/output/index.js +9 -0
- package/core/output/writer.d.ts +38 -0
- package/core/output/writer.js +156 -0
- package/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
- package/{cli/commands/shared.js → core/pipeline/index.js} +4 -0
- package/{cli → core}/watch/orchestrator.d.ts +25 -3
- package/{cli → core}/watch/orchestrator.js +35 -27
- package/{cli → core}/watch/types.d.ts +1 -1
- package/esm/cli/index.d.ts +5 -2
- package/esm/cli/index.js +97 -547
- package/esm/cli/shared.d.ts +35 -0
- package/esm/cli/shared.js +101 -0
- package/{cli → esm/core}/codegen/barrel.d.ts +1 -1
- package/esm/{cli → core}/codegen/barrel.js +1 -4
- package/{cli → esm/core}/codegen/index.d.ts +15 -5
- package/esm/{cli → core}/codegen/index.js +44 -24
- package/esm/{cli → core}/codegen/invalidation.d.ts +2 -2
- package/{cli → esm/core}/codegen/mutation-keys.d.ts +2 -2
- package/esm/{cli → core}/codegen/orm/client-generator.js +2 -3
- package/{cli → esm/core}/codegen/orm/index.d.ts +9 -2
- package/esm/{cli → core}/codegen/orm/index.js +3 -2
- package/esm/{cli → core}/codegen/query-keys.d.ts +2 -2
- package/esm/core/codegen/shared/index.d.ts +39 -0
- package/esm/core/codegen/shared/index.js +79 -0
- package/esm/core/config/index.d.ts +5 -0
- package/esm/core/config/index.js +5 -0
- package/esm/core/config/loader.d.ts +18 -0
- package/esm/core/config/loader.js +71 -0
- package/esm/core/config/resolver.d.ts +46 -0
- package/esm/core/config/resolver.js +100 -0
- package/esm/core/database/index.d.ts +43 -0
- package/esm/core/database/index.js +48 -0
- package/esm/core/generate.d.ts +22 -0
- package/esm/core/generate.js +186 -0
- package/esm/core/index.d.ts +13 -1
- package/esm/core/index.js +20 -1
- package/esm/{cli → core}/introspect/fetch-schema.js +55 -9
- package/esm/core/introspect/source/api-schemas.d.ts +44 -0
- package/esm/core/introspect/source/api-schemas.js +117 -0
- package/esm/core/introspect/source/database.d.ts +32 -0
- package/esm/core/introspect/source/database.js +87 -0
- package/esm/core/introspect/source/index.d.ts +112 -0
- package/esm/core/introspect/source/index.js +154 -0
- package/esm/core/introspect/source/pgpm-module.d.ts +83 -0
- package/esm/core/introspect/source/pgpm-module.js +194 -0
- package/esm/core/output/index.d.ts +4 -0
- package/esm/core/output/index.js +4 -0
- package/esm/core/output/writer.d.ts +38 -0
- package/esm/core/output/writer.js +119 -0
- package/esm/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
- package/esm/{cli/commands/shared.js → core/pipeline/index.js} +1 -0
- package/esm/{cli → core}/watch/orchestrator.d.ts +25 -3
- package/esm/{cli → core}/watch/orchestrator.js +35 -27
- package/esm/{cli → core}/watch/types.d.ts +1 -1
- package/esm/index.d.ts +8 -3
- package/esm/index.js +9 -3
- package/esm/types/config.d.ts +101 -138
- package/esm/types/config.js +8 -35
- package/esm/types/index.d.ts +2 -2
- package/esm/types/index.js +1 -1
- package/index.d.ts +8 -3
- package/index.js +18 -8
- package/package.json +18 -11
- package/types/config.d.ts +101 -138
- package/types/config.js +9 -38
- package/types/index.d.ts +2 -2
- package/types/index.js +3 -3
- package/cli/commands/generate-orm.d.ts +0 -53
- package/cli/commands/generate-orm.js +0 -292
- package/cli/commands/generate.d.ts +0 -66
- package/cli/commands/generate.js +0 -431
- package/cli/commands/index.d.ts +0 -9
- package/cli/commands/index.js +0 -14
- package/cli/commands/init.d.ts +0 -35
- package/cli/introspect/source/index.d.ts +0 -48
- package/cli/introspect/source/index.js +0 -72
- package/esm/cli/commands/generate-orm.d.ts +0 -53
- package/esm/cli/commands/generate-orm.js +0 -289
- package/esm/cli/commands/generate.d.ts +0 -66
- package/esm/cli/commands/generate.js +0 -393
- package/esm/cli/commands/index.d.ts +0 -9
- package/esm/cli/commands/index.js +0 -6
- package/esm/cli/commands/init.d.ts +0 -35
- package/esm/cli/commands/init.js +0 -158
- package/esm/cli/introspect/source/index.d.ts +0 -48
- package/esm/cli/introspect/source/index.js +0 -54
- /package/{cli → core}/codegen/babel-ast.d.ts +0 -0
- /package/{cli → core}/codegen/babel-ast.js +0 -0
- /package/{cli → core}/codegen/client.d.ts +0 -0
- /package/{cli → core}/codegen/client.js +0 -0
- /package/{cli → core}/codegen/custom-mutations.d.ts +0 -0
- /package/{cli → core}/codegen/custom-mutations.js +0 -0
- /package/{cli → core}/codegen/custom-queries.d.ts +0 -0
- /package/{cli → core}/codegen/custom-queries.js +0 -0
- /package/{cli → core}/codegen/gql-ast.d.ts +0 -0
- /package/{cli → core}/codegen/gql-ast.js +0 -0
- /package/{cli → core}/codegen/invalidation.js +0 -0
- /package/{cli → core}/codegen/mutation-keys.js +0 -0
- /package/{cli → core}/codegen/mutations.d.ts +0 -0
- /package/{cli → core}/codegen/mutations.js +0 -0
- /package/{cli → core}/codegen/orm/barrel.d.ts +0 -0
- /package/{cli → core}/codegen/orm/barrel.js +0 -0
- /package/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/client.d.ts +0 -0
- /package/{cli → core}/codegen/orm/client.js +0 -0
- /package/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
- /package/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/input-types-generator.js +0 -0
- /package/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/model-generator.js +0 -0
- /package/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
- /package/{cli → core}/codegen/orm/query-builder.js +0 -0
- /package/{cli → core}/codegen/orm/query-builder.ts +0 -0
- /package/{cli → core}/codegen/orm/select-types.d.ts +0 -0
- /package/{cli → core}/codegen/orm/select-types.js +0 -0
- /package/{cli → core}/codegen/queries.d.ts +0 -0
- /package/{cli → core}/codegen/queries.js +0 -0
- /package/{cli → core}/codegen/query-keys.js +0 -0
- /package/{cli → core}/codegen/scalars.d.ts +0 -0
- /package/{cli → core}/codegen/scalars.js +0 -0
- /package/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
- /package/{cli → core}/codegen/schema-gql-ast.js +0 -0
- /package/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
- /package/{cli → core}/codegen/schema-types-generator.js +0 -0
- /package/{cli → core}/codegen/type-resolver.d.ts +0 -0
- /package/{cli → core}/codegen/type-resolver.js +0 -0
- /package/{cli → core}/codegen/types.d.ts +0 -0
- /package/{cli → core}/codegen/types.js +0 -0
- /package/{cli → core}/codegen/utils.d.ts +0 -0
- /package/{cli → core}/codegen/utils.js +0 -0
- /package/{cli → core}/introspect/fetch-schema.d.ts +0 -0
- /package/{cli → core}/introspect/index.d.ts +0 -0
- /package/{cli → core}/introspect/index.js +0 -0
- /package/{cli → core}/introspect/infer-tables.d.ts +0 -0
- /package/{cli → core}/introspect/infer-tables.js +0 -0
- /package/{cli → core}/introspect/schema-query.d.ts +0 -0
- /package/{cli → core}/introspect/schema-query.js +0 -0
- /package/{cli → core}/introspect/source/endpoint.d.ts +0 -0
- /package/{cli → core}/introspect/source/endpoint.js +0 -0
- /package/{cli → core}/introspect/source/file.d.ts +0 -0
- /package/{cli → core}/introspect/source/file.js +0 -0
- /package/{cli → core}/introspect/source/types.d.ts +0 -0
- /package/{cli → core}/introspect/source/types.js +0 -0
- /package/{cli → core}/introspect/transform-schema.d.ts +0 -0
- /package/{cli → core}/introspect/transform-schema.js +0 -0
- /package/{cli → core}/introspect/transform.d.ts +0 -0
- /package/{cli → core}/introspect/transform.js +0 -0
- /package/{cli → core}/watch/cache.d.ts +0 -0
- /package/{cli → core}/watch/cache.js +0 -0
- /package/{cli → core}/watch/debounce.d.ts +0 -0
- /package/{cli → core}/watch/debounce.js +0 -0
- /package/{cli → core}/watch/hash.d.ts +0 -0
- /package/{cli → core}/watch/hash.js +0 -0
- /package/{cli → core}/watch/index.d.ts +0 -0
- /package/{cli → core}/watch/index.js +0 -0
- /package/{cli → core}/watch/poller.d.ts +0 -0
- /package/{cli → core}/watch/poller.js +0 -0
- /package/{cli → core}/watch/types.js +0 -0
- /package/esm/{cli → core}/codegen/babel-ast.d.ts +0 -0
- /package/esm/{cli → core}/codegen/babel-ast.js +0 -0
- /package/esm/{cli → core}/codegen/client.d.ts +0 -0
- /package/esm/{cli → core}/codegen/client.js +0 -0
- /package/esm/{cli → core}/codegen/custom-mutations.d.ts +0 -0
- /package/esm/{cli → core}/codegen/custom-mutations.js +0 -0
- /package/esm/{cli → core}/codegen/custom-queries.d.ts +0 -0
- /package/esm/{cli → core}/codegen/custom-queries.js +0 -0
- /package/esm/{cli → core}/codegen/gql-ast.d.ts +0 -0
- /package/esm/{cli → core}/codegen/gql-ast.js +0 -0
- /package/esm/{cli → core}/codegen/invalidation.js +0 -0
- /package/esm/{cli → core}/codegen/mutation-keys.js +0 -0
- /package/esm/{cli → core}/codegen/mutations.d.ts +0 -0
- /package/esm/{cli → core}/codegen/mutations.js +0 -0
- /package/esm/{cli → core}/codegen/orm/barrel.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/barrel.js +0 -0
- /package/esm/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/client.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/client.js +0 -0
- /package/esm/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
- /package/esm/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/input-types-generator.js +0 -0
- /package/esm/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/model-generator.js +0 -0
- /package/esm/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/query-builder.js +0 -0
- /package/esm/{cli → core}/codegen/orm/select-types.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/select-types.js +0 -0
- /package/esm/{cli → core}/codegen/queries.d.ts +0 -0
- /package/esm/{cli → core}/codegen/queries.js +0 -0
- /package/esm/{cli → core}/codegen/query-keys.js +0 -0
- /package/esm/{cli → core}/codegen/scalars.d.ts +0 -0
- /package/esm/{cli → core}/codegen/scalars.js +0 -0
- /package/esm/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
- /package/esm/{cli → core}/codegen/schema-gql-ast.js +0 -0
- /package/esm/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/schema-types-generator.js +0 -0
- /package/esm/{cli → core}/codegen/type-resolver.d.ts +0 -0
- /package/esm/{cli → core}/codegen/type-resolver.js +0 -0
- /package/esm/{cli → core}/codegen/types.d.ts +0 -0
- /package/esm/{cli → core}/codegen/types.js +0 -0
- /package/esm/{cli → core}/codegen/utils.d.ts +0 -0
- /package/esm/{cli → core}/codegen/utils.js +0 -0
- /package/esm/{cli → core}/introspect/fetch-schema.d.ts +0 -0
- /package/esm/{cli → core}/introspect/index.d.ts +0 -0
- /package/esm/{cli → core}/introspect/index.js +0 -0
- /package/esm/{cli → core}/introspect/infer-tables.d.ts +0 -0
- /package/esm/{cli → core}/introspect/infer-tables.js +0 -0
- /package/esm/{cli → core}/introspect/schema-query.d.ts +0 -0
- /package/esm/{cli → core}/introspect/schema-query.js +0 -0
- /package/esm/{cli → core}/introspect/source/endpoint.d.ts +0 -0
- /package/esm/{cli → core}/introspect/source/endpoint.js +0 -0
- /package/esm/{cli → core}/introspect/source/file.d.ts +0 -0
- /package/esm/{cli → core}/introspect/source/file.js +0 -0
- /package/esm/{cli → core}/introspect/source/types.d.ts +0 -0
- /package/esm/{cli → core}/introspect/source/types.js +0 -0
- /package/esm/{cli → core}/introspect/transform-schema.d.ts +0 -0
- /package/esm/{cli → core}/introspect/transform-schema.js +0 -0
- /package/esm/{cli → core}/introspect/transform.d.ts +0 -0
- /package/esm/{cli → core}/introspect/transform.js +0 -0
- /package/esm/{cli → core}/watch/cache.d.ts +0 -0
- /package/esm/{cli → core}/watch/cache.js +0 -0
- /package/esm/{cli → core}/watch/debounce.d.ts +0 -0
- /package/esm/{cli → core}/watch/debounce.js +0 -0
- /package/esm/{cli → core}/watch/hash.d.ts +0 -0
- /package/esm/{cli → core}/watch/hash.js +0 -0
- /package/esm/{cli → core}/watch/index.d.ts +0 -0
- /package/esm/{cli → core}/watch/index.js +0 -0
- /package/esm/{cli → core}/watch/poller.d.ts +0 -0
- /package/esm/{cli → core}/watch/poller.js +0 -0
- /package/esm/{cli → core}/watch/types.js +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { SchemaSource, SchemaSourceResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Options for PGPM module schema source using direct module path
|
|
4
|
+
*/
|
|
5
|
+
export interface PgpmModulePathOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Path to the PGPM module directory
|
|
8
|
+
* The directory should contain a pgpm.plan file and .control file
|
|
9
|
+
*/
|
|
10
|
+
pgpmModulePath: string;
|
|
11
|
+
/**
|
|
12
|
+
* PostgreSQL schemas to include in introspection
|
|
13
|
+
* Mutually exclusive with apiNames
|
|
14
|
+
*/
|
|
15
|
+
schemas?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* API names to resolve schemas from
|
|
18
|
+
* Queries services_public.api_schemas to get schema names
|
|
19
|
+
* Mutually exclusive with schemas
|
|
20
|
+
*/
|
|
21
|
+
apiNames?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* If true, keeps the ephemeral database after introspection (useful for debugging)
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
keepDb?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for PGPM module schema source using workspace + module name
|
|
30
|
+
*/
|
|
31
|
+
export interface PgpmWorkspaceOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Path to the PGPM workspace directory
|
|
34
|
+
* The directory should contain a pgpm.config.yaml or similar workspace config
|
|
35
|
+
*/
|
|
36
|
+
pgpmWorkspacePath: string;
|
|
37
|
+
/**
|
|
38
|
+
* Name of the module within the workspace
|
|
39
|
+
*/
|
|
40
|
+
pgpmModuleName: string;
|
|
41
|
+
/**
|
|
42
|
+
* PostgreSQL schemas to include in introspection
|
|
43
|
+
* Mutually exclusive with apiNames
|
|
44
|
+
*/
|
|
45
|
+
schemas?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* API names to resolve schemas from
|
|
48
|
+
* Queries services_public.api_schemas to get schema names
|
|
49
|
+
* Mutually exclusive with schemas
|
|
50
|
+
*/
|
|
51
|
+
apiNames?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* If true, keeps the ephemeral database after introspection (useful for debugging)
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
keepDb?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export type PgpmModuleSchemaSourceOptions = PgpmModulePathOptions | PgpmWorkspaceOptions;
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if options use direct module path
|
|
61
|
+
*/
|
|
62
|
+
export declare function isPgpmModulePathOptions(options: PgpmModuleSchemaSourceOptions): options is PgpmModulePathOptions;
|
|
63
|
+
/**
|
|
64
|
+
* Type guard to check if options use workspace + module name
|
|
65
|
+
*/
|
|
66
|
+
export declare function isPgpmWorkspaceOptions(options: PgpmModuleSchemaSourceOptions): options is PgpmWorkspaceOptions;
|
|
67
|
+
/**
|
|
68
|
+
* Schema source that loads from a PGPM module
|
|
69
|
+
*
|
|
70
|
+
* Creates an ephemeral database, deploys the module, introspects the schema,
|
|
71
|
+
* and cleans up. Supports both direct module path and workspace + module name modes.
|
|
72
|
+
*/
|
|
73
|
+
export declare class PgpmModuleSchemaSource implements SchemaSource {
|
|
74
|
+
private readonly options;
|
|
75
|
+
private ephemeralDb;
|
|
76
|
+
constructor(options: PgpmModuleSchemaSourceOptions);
|
|
77
|
+
fetch(): Promise<SchemaSourceResult>;
|
|
78
|
+
describe(): string;
|
|
79
|
+
private resolveModulePath;
|
|
80
|
+
private getSchemas;
|
|
81
|
+
private getApiNames;
|
|
82
|
+
private getKeepDb;
|
|
83
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PgpmModuleSchemaSource = void 0;
|
|
4
|
+
exports.isPgpmModulePathOptions = isPgpmModulePathOptions;
|
|
5
|
+
exports.isPgpmWorkspaceOptions = isPgpmWorkspaceOptions;
|
|
6
|
+
/**
|
|
7
|
+
* PGPM Module Schema Source
|
|
8
|
+
*
|
|
9
|
+
* Loads GraphQL schema from a PGPM module by:
|
|
10
|
+
* 1. Creating an ephemeral database
|
|
11
|
+
* 2. Deploying the module to the database
|
|
12
|
+
* 3. Introspecting the database with PostGraphile
|
|
13
|
+
* 4. Cleaning up the ephemeral database (unless keepDb is true)
|
|
14
|
+
*/
|
|
15
|
+
const graphql_1 = require("graphql");
|
|
16
|
+
const core_1 = require("@pgpmjs/core");
|
|
17
|
+
const pgsql_client_1 = require("pgsql-client");
|
|
18
|
+
const pgsql_seed_1 = require("pgsql-seed");
|
|
19
|
+
const pg_cache_1 = require("pg-cache");
|
|
20
|
+
const types_1 = require("./types");
|
|
21
|
+
const database_1 = require("../../database");
|
|
22
|
+
const api_schemas_1 = require("./api-schemas");
|
|
23
|
+
/**
|
|
24
|
+
* Type guard to check if options use direct module path
|
|
25
|
+
*/
|
|
26
|
+
function isPgpmModulePathOptions(options) {
|
|
27
|
+
return 'pgpmModulePath' in options;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if options use workspace + module name
|
|
31
|
+
*/
|
|
32
|
+
function isPgpmWorkspaceOptions(options) {
|
|
33
|
+
return 'pgpmWorkspacePath' in options && 'pgpmModuleName' in options;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Schema source that loads from a PGPM module
|
|
37
|
+
*
|
|
38
|
+
* Creates an ephemeral database, deploys the module, introspects the schema,
|
|
39
|
+
* and cleans up. Supports both direct module path and workspace + module name modes.
|
|
40
|
+
*/
|
|
41
|
+
class PgpmModuleSchemaSource {
|
|
42
|
+
options;
|
|
43
|
+
ephemeralDb = null;
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.options = options;
|
|
46
|
+
}
|
|
47
|
+
async fetch() {
|
|
48
|
+
const keepDb = this.getKeepDb();
|
|
49
|
+
const apiNames = this.getApiNames();
|
|
50
|
+
// Resolve the module path
|
|
51
|
+
let modulePath;
|
|
52
|
+
try {
|
|
53
|
+
modulePath = this.resolveModulePath();
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
throw new types_1.SchemaSourceError(`Failed to resolve module path: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
57
|
+
}
|
|
58
|
+
// Validate the module exists
|
|
59
|
+
const pkg = new core_1.PgpmPackage(modulePath);
|
|
60
|
+
if (!pkg.isInModule()) {
|
|
61
|
+
throw new types_1.SchemaSourceError(`Not a valid PGPM module: ${modulePath}. Directory must contain pgpm.plan and .control files.`, this.describe());
|
|
62
|
+
}
|
|
63
|
+
// Create ephemeral database
|
|
64
|
+
try {
|
|
65
|
+
this.ephemeralDb = (0, pgsql_client_1.createEphemeralDb)({
|
|
66
|
+
prefix: 'codegen_pgpm_',
|
|
67
|
+
verbose: false,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
throw new types_1.SchemaSourceError(`Failed to create ephemeral database: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
72
|
+
}
|
|
73
|
+
const { config: dbConfig, teardown } = this.ephemeralDb;
|
|
74
|
+
try {
|
|
75
|
+
// Deploy the module to the ephemeral database
|
|
76
|
+
try {
|
|
77
|
+
await (0, pgsql_seed_1.deployPgpm)(dbConfig, modulePath, false);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
throw new types_1.SchemaSourceError(`Failed to deploy PGPM module: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
81
|
+
}
|
|
82
|
+
// Resolve schemas - either from explicit schemas option or from apiNames (after deployment)
|
|
83
|
+
let schemas;
|
|
84
|
+
if (apiNames && apiNames.length > 0) {
|
|
85
|
+
// For PGPM mode, validate services schemas AFTER migration
|
|
86
|
+
const pool = (0, pg_cache_1.getPgPool)(dbConfig);
|
|
87
|
+
try {
|
|
88
|
+
const validation = await (0, api_schemas_1.validateServicesSchemas)(pool);
|
|
89
|
+
if (!validation.valid) {
|
|
90
|
+
throw new types_1.SchemaSourceError(validation.error, this.describe());
|
|
91
|
+
}
|
|
92
|
+
schemas = await (0, api_schemas_1.resolveApiSchemas)(pool, apiNames);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (err instanceof types_1.SchemaSourceError)
|
|
96
|
+
throw err;
|
|
97
|
+
throw new types_1.SchemaSourceError(`Failed to resolve API schemas: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
schemas = this.getSchemas();
|
|
102
|
+
}
|
|
103
|
+
// Build SDL from the deployed database
|
|
104
|
+
let sdl;
|
|
105
|
+
try {
|
|
106
|
+
sdl = await (0, database_1.buildSchemaSDLFromDatabase)({
|
|
107
|
+
database: dbConfig.database,
|
|
108
|
+
schemas,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
throw new types_1.SchemaSourceError(`Failed to introspect database: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
113
|
+
}
|
|
114
|
+
// Validate non-empty
|
|
115
|
+
if (!sdl.trim()) {
|
|
116
|
+
throw new types_1.SchemaSourceError('Database introspection returned empty schema', this.describe());
|
|
117
|
+
}
|
|
118
|
+
// Parse SDL to GraphQL schema
|
|
119
|
+
let schema;
|
|
120
|
+
try {
|
|
121
|
+
schema = (0, graphql_1.buildSchema)(sdl);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw new types_1.SchemaSourceError(`Invalid GraphQL SDL from database: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
125
|
+
}
|
|
126
|
+
// Convert to introspection format
|
|
127
|
+
let introspectionResult;
|
|
128
|
+
try {
|
|
129
|
+
introspectionResult = (0, graphql_1.introspectionFromSchema)(schema);
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
throw new types_1.SchemaSourceError(`Failed to generate introspection: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
133
|
+
}
|
|
134
|
+
// Convert graphql-js introspection result to our mutable type
|
|
135
|
+
const introspection = JSON.parse(JSON.stringify(introspectionResult));
|
|
136
|
+
return { introspection };
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
// Clean up the ephemeral database
|
|
140
|
+
teardown({ keepDb });
|
|
141
|
+
if (keepDb) {
|
|
142
|
+
console.log(`[pgpm-module] Kept ephemeral database: ${dbConfig.database}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
describe() {
|
|
147
|
+
const apiNames = this.getApiNames();
|
|
148
|
+
if (isPgpmModulePathOptions(this.options)) {
|
|
149
|
+
if (apiNames && apiNames.length > 0) {
|
|
150
|
+
return `pgpm module: ${this.options.pgpmModulePath} (apiNames: ${apiNames.join(', ')})`;
|
|
151
|
+
}
|
|
152
|
+
const schemas = this.options.schemas ?? ['public'];
|
|
153
|
+
return `pgpm module: ${this.options.pgpmModulePath} (schemas: ${schemas.join(', ')})`;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
if (apiNames && apiNames.length > 0) {
|
|
157
|
+
return `pgpm workspace: ${this.options.pgpmWorkspacePath}, module: ${this.options.pgpmModuleName} (apiNames: ${apiNames.join(', ')})`;
|
|
158
|
+
}
|
|
159
|
+
const schemas = this.options.schemas ?? ['public'];
|
|
160
|
+
return `pgpm workspace: ${this.options.pgpmWorkspacePath}, module: ${this.options.pgpmModuleName} (schemas: ${schemas.join(', ')})`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
resolveModulePath() {
|
|
164
|
+
if (isPgpmModulePathOptions(this.options)) {
|
|
165
|
+
return this.options.pgpmModulePath;
|
|
166
|
+
}
|
|
167
|
+
// Workspace + module name mode
|
|
168
|
+
const { pgpmWorkspacePath, pgpmModuleName } = this.options;
|
|
169
|
+
const workspace = new core_1.PgpmPackage(pgpmWorkspacePath);
|
|
170
|
+
if (!workspace.workspacePath) {
|
|
171
|
+
throw new Error(`Not a valid PGPM workspace: ${pgpmWorkspacePath}`);
|
|
172
|
+
}
|
|
173
|
+
// Get the module from the workspace
|
|
174
|
+
const moduleProject = workspace.getModuleProject(pgpmModuleName);
|
|
175
|
+
const modulePath = moduleProject.getModulePath();
|
|
176
|
+
if (!modulePath) {
|
|
177
|
+
throw new Error(`Module "${pgpmModuleName}" not found in workspace`);
|
|
178
|
+
}
|
|
179
|
+
return modulePath;
|
|
180
|
+
}
|
|
181
|
+
getSchemas() {
|
|
182
|
+
if (isPgpmModulePathOptions(this.options)) {
|
|
183
|
+
return this.options.schemas ?? ['public'];
|
|
184
|
+
}
|
|
185
|
+
return this.options.schemas ?? ['public'];
|
|
186
|
+
}
|
|
187
|
+
getApiNames() {
|
|
188
|
+
if (isPgpmModulePathOptions(this.options)) {
|
|
189
|
+
return this.options.apiNames;
|
|
190
|
+
}
|
|
191
|
+
return this.options.apiNames;
|
|
192
|
+
}
|
|
193
|
+
getKeepDb() {
|
|
194
|
+
if (isPgpmModulePathOptions(this.options)) {
|
|
195
|
+
return this.options.keepDb ?? false;
|
|
196
|
+
}
|
|
197
|
+
return this.options.keepDb ?? false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.PgpmModuleSchemaSource = PgpmModuleSchemaSource;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Output module exports
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatOutput = exports.writeGeneratedFiles = void 0;
|
|
7
|
+
var writer_1 = require("./writer");
|
|
8
|
+
Object.defineProperty(exports, "writeGeneratedFiles", { enumerable: true, get: function () { return writer_1.writeGeneratedFiles; } });
|
|
9
|
+
Object.defineProperty(exports, "formatOutput", { enumerable: true, get: function () { return writer_1.formatOutput; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GeneratedFile } from '../codegen';
|
|
2
|
+
export type { GeneratedFile };
|
|
3
|
+
/**
|
|
4
|
+
* Result of writing files
|
|
5
|
+
*/
|
|
6
|
+
export interface WriteResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
filesWritten?: string[];
|
|
9
|
+
errors?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Options for writing files
|
|
13
|
+
*/
|
|
14
|
+
export interface WriteOptions {
|
|
15
|
+
/** Show progress output (default: true) */
|
|
16
|
+
showProgress?: boolean;
|
|
17
|
+
/** Format files with oxfmt after writing (default: true) */
|
|
18
|
+
formatFiles?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Write generated files to disk
|
|
22
|
+
*
|
|
23
|
+
* @param files - Array of files to write
|
|
24
|
+
* @param outputDir - Base output directory
|
|
25
|
+
* @param subdirs - Subdirectories to create
|
|
26
|
+
* @param options - Write options
|
|
27
|
+
*/
|
|
28
|
+
export declare function writeGeneratedFiles(files: GeneratedFile[], outputDir: string, subdirs: string[], options?: WriteOptions): Promise<WriteResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Format generated files using oxfmt
|
|
31
|
+
*
|
|
32
|
+
* Runs oxfmt on the output directory after all files are written.
|
|
33
|
+
* Uses the same formatting options as prettier: single quotes, trailing commas, 2-space tabs, semicolons.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatOutput(outputDir: string): {
|
|
36
|
+
success: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.writeGeneratedFiles = writeGeneratedFiles;
|
|
37
|
+
exports.formatOutput = formatOutput;
|
|
38
|
+
/**
|
|
39
|
+
* File writing utilities
|
|
40
|
+
*
|
|
41
|
+
* Pure functions for writing generated files to disk and formatting them.
|
|
42
|
+
* These are core utilities that can be used programmatically or by the CLI.
|
|
43
|
+
*/
|
|
44
|
+
const fs = __importStar(require("node:fs"));
|
|
45
|
+
const path = __importStar(require("node:path"));
|
|
46
|
+
const node_child_process_1 = require("node:child_process");
|
|
47
|
+
/**
|
|
48
|
+
* Write generated files to disk
|
|
49
|
+
*
|
|
50
|
+
* @param files - Array of files to write
|
|
51
|
+
* @param outputDir - Base output directory
|
|
52
|
+
* @param subdirs - Subdirectories to create
|
|
53
|
+
* @param options - Write options
|
|
54
|
+
*/
|
|
55
|
+
async function writeGeneratedFiles(files, outputDir, subdirs, options = {}) {
|
|
56
|
+
const { showProgress = true, formatFiles = true } = options;
|
|
57
|
+
const errors = [];
|
|
58
|
+
const written = [];
|
|
59
|
+
const total = files.length;
|
|
60
|
+
const isTTY = process.stdout.isTTY;
|
|
61
|
+
// Ensure output directory exists
|
|
62
|
+
try {
|
|
63
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
errors: [`Failed to create output directory: ${message}`],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Create subdirectories
|
|
73
|
+
for (const subdir of subdirs) {
|
|
74
|
+
const subdirPath = path.join(outputDir, subdir);
|
|
75
|
+
try {
|
|
76
|
+
fs.mkdirSync(subdirPath, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
80
|
+
errors.push(`Failed to create directory ${subdirPath}: ${message}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (errors.length > 0) {
|
|
84
|
+
return { success: false, errors };
|
|
85
|
+
}
|
|
86
|
+
for (let i = 0; i < files.length; i++) {
|
|
87
|
+
const file = files[i];
|
|
88
|
+
const filePath = path.join(outputDir, file.path);
|
|
89
|
+
// Show progress
|
|
90
|
+
if (showProgress) {
|
|
91
|
+
const progress = Math.round(((i + 1) / total) * 100);
|
|
92
|
+
if (isTTY) {
|
|
93
|
+
process.stdout.write(`\rWriting files: ${i + 1}/${total} (${progress}%)`);
|
|
94
|
+
}
|
|
95
|
+
else if (i % 100 === 0 || i === total - 1) {
|
|
96
|
+
// Non-TTY: periodic updates for CI/CD
|
|
97
|
+
console.log(`Writing files: ${i + 1}/${total}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Ensure parent directory exists
|
|
101
|
+
const parentDir = path.dirname(filePath);
|
|
102
|
+
try {
|
|
103
|
+
fs.mkdirSync(parentDir, { recursive: true });
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Ignore if already exists
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
fs.writeFileSync(filePath, file.content, 'utf-8');
|
|
110
|
+
written.push(filePath);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
114
|
+
errors.push(`Failed to write ${filePath}: ${message}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Clear progress line
|
|
118
|
+
if (showProgress && isTTY) {
|
|
119
|
+
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
120
|
+
}
|
|
121
|
+
// Format all generated files with oxfmt
|
|
122
|
+
if (formatFiles && errors.length === 0) {
|
|
123
|
+
if (showProgress) {
|
|
124
|
+
console.log('Formatting generated files...');
|
|
125
|
+
}
|
|
126
|
+
const formatResult = formatOutput(outputDir);
|
|
127
|
+
if (!formatResult.success && showProgress) {
|
|
128
|
+
console.warn('Warning: Failed to format generated files:', formatResult.error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
success: errors.length === 0,
|
|
133
|
+
filesWritten: written,
|
|
134
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Format generated files using oxfmt
|
|
139
|
+
*
|
|
140
|
+
* Runs oxfmt on the output directory after all files are written.
|
|
141
|
+
* Uses the same formatting options as prettier: single quotes, trailing commas, 2-space tabs, semicolons.
|
|
142
|
+
*/
|
|
143
|
+
function formatOutput(outputDir) {
|
|
144
|
+
const absoluteOutputDir = path.resolve(outputDir);
|
|
145
|
+
try {
|
|
146
|
+
(0, node_child_process_1.execSync)(`npx oxfmt --write "${absoluteOutputDir}"`, {
|
|
147
|
+
stdio: 'pipe',
|
|
148
|
+
encoding: 'utf-8',
|
|
149
|
+
});
|
|
150
|
+
return { success: true };
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
154
|
+
return { success: false, error: message };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -8,18 +8,20 @@
|
|
|
8
8
|
* - Operation transformation
|
|
9
9
|
* - Filtering
|
|
10
10
|
*/
|
|
11
|
-
import type {
|
|
11
|
+
import type { GraphQLSDKConfigTarget } from '../../types/config';
|
|
12
12
|
import type { CleanTable, CleanOperation, TypeRegistry } from '../../types/schema';
|
|
13
13
|
import type { SchemaSource } from '../introspect/source';
|
|
14
|
+
export type { SchemaSource } from '../introspect/source';
|
|
15
|
+
export { createSchemaSource, validateSourceOptions } from '../introspect/source';
|
|
14
16
|
export interface CodegenPipelineOptions {
|
|
15
17
|
/**
|
|
16
18
|
* Schema source (endpoint or file)
|
|
17
19
|
*/
|
|
18
20
|
source: SchemaSource;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Configuration
|
|
21
23
|
*/
|
|
22
|
-
config:
|
|
24
|
+
config: GraphQLSDKConfigTarget;
|
|
23
25
|
/**
|
|
24
26
|
* Enable verbose logging
|
|
25
27
|
*/
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSourceOptions = exports.createSchemaSource = void 0;
|
|
3
4
|
exports.runCodegenPipeline = runCodegenPipeline;
|
|
4
5
|
exports.validateTablesFound = validateTablesFound;
|
|
5
6
|
const infer_tables_1 = require("../introspect/infer-tables");
|
|
6
7
|
const transform_1 = require("../introspect/transform");
|
|
7
8
|
const transform_schema_1 = require("../introspect/transform-schema");
|
|
9
|
+
var source_1 = require("../introspect/source");
|
|
10
|
+
Object.defineProperty(exports, "createSchemaSource", { enumerable: true, get: function () { return source_1.createSchemaSource; } });
|
|
11
|
+
Object.defineProperty(exports, "validateSourceOptions", { enumerable: true, get: function () { return source_1.validateSourceOptions; } });
|
|
8
12
|
// ============================================================================
|
|
9
13
|
// Main Pipeline
|
|
10
14
|
// ============================================================================
|
|
@@ -3,10 +3,28 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Coordinates schema polling, change detection, and code regeneration
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { GraphQLSDKConfigTarget } from '../../types/config';
|
|
7
7
|
import type { GeneratorType } from './types';
|
|
8
|
+
export interface GenerateFunction {
|
|
9
|
+
(options: {
|
|
10
|
+
config?: string;
|
|
11
|
+
target?: string;
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
output?: string;
|
|
14
|
+
authorization?: string;
|
|
15
|
+
verbose?: boolean;
|
|
16
|
+
skipCustomOperations?: boolean;
|
|
17
|
+
}): Promise<GenerateResult>;
|
|
18
|
+
}
|
|
19
|
+
export interface GenerateResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
message: string;
|
|
22
|
+
tables?: string[];
|
|
23
|
+
filesWritten?: string[];
|
|
24
|
+
errors?: string[];
|
|
25
|
+
}
|
|
8
26
|
export interface WatchOrchestratorOptions {
|
|
9
|
-
config:
|
|
27
|
+
config: GraphQLSDKConfigTarget;
|
|
10
28
|
generatorType: GeneratorType;
|
|
11
29
|
verbose: boolean;
|
|
12
30
|
authorization?: string;
|
|
@@ -14,10 +32,14 @@ export interface WatchOrchestratorOptions {
|
|
|
14
32
|
configPath?: string;
|
|
15
33
|
/** Target name for multi-target configs */
|
|
16
34
|
target?: string;
|
|
17
|
-
/** Override output directory
|
|
35
|
+
/** Override output directory */
|
|
18
36
|
outputDir?: string;
|
|
19
37
|
/** Skip custom operations flag */
|
|
20
38
|
skipCustomOperations?: boolean;
|
|
39
|
+
/** Generator function for React Query SDK */
|
|
40
|
+
generateReactQuery: GenerateFunction;
|
|
41
|
+
/** Generator function for ORM client */
|
|
42
|
+
generateOrm: GenerateFunction;
|
|
21
43
|
}
|
|
22
44
|
export interface WatchStatus {
|
|
23
45
|
isRunning: boolean;
|
|
@@ -9,8 +9,6 @@ exports.WatchOrchestrator = void 0;
|
|
|
9
9
|
exports.startWatch = startWatch;
|
|
10
10
|
const poller_1 = require("./poller");
|
|
11
11
|
const debounce_1 = require("./debounce");
|
|
12
|
-
const generate_1 = require("../commands/generate");
|
|
13
|
-
const generate_orm_1 = require("../commands/generate-orm");
|
|
14
12
|
/**
|
|
15
13
|
* Main watch orchestrator class
|
|
16
14
|
*/
|
|
@@ -135,29 +133,31 @@ class WatchOrchestrator {
|
|
|
135
133
|
}
|
|
136
134
|
this.log('Regenerating...');
|
|
137
135
|
try {
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
target: this.options.target,
|
|
154
|
-
endpoint: this.options.config.endpoint,
|
|
155
|
-
output: this.options.outputDir ?? this.options.config.orm.output,
|
|
156
|
-
authorization: this.options.authorization,
|
|
157
|
-
verbose: this.watchOptions.verbose,
|
|
158
|
-
skipCustomOperations: this.options.skipCustomOperations,
|
|
159
|
-
});
|
|
136
|
+
let generateFn;
|
|
137
|
+
let outputDir;
|
|
138
|
+
switch (this.options.generatorType) {
|
|
139
|
+
case 'react-query':
|
|
140
|
+
generateFn = this.options.generateReactQuery;
|
|
141
|
+
// React Query hooks go to {output}/hooks
|
|
142
|
+
outputDir = this.options.outputDir ?? `${this.options.config.output}/hooks`;
|
|
143
|
+
break;
|
|
144
|
+
case 'orm':
|
|
145
|
+
generateFn = this.options.generateOrm;
|
|
146
|
+
// ORM client goes to {output}/orm
|
|
147
|
+
outputDir = this.options.outputDir ?? `${this.options.config.output}/orm`;
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
throw new Error(`Unknown generator type: ${this.options.generatorType}`);
|
|
160
151
|
}
|
|
152
|
+
const result = await generateFn({
|
|
153
|
+
config: this.options.configPath,
|
|
154
|
+
target: this.options.target,
|
|
155
|
+
endpoint: this.options.config.endpoint,
|
|
156
|
+
output: outputDir,
|
|
157
|
+
authorization: this.options.authorization,
|
|
158
|
+
verbose: this.watchOptions.verbose,
|
|
159
|
+
skipCustomOperations: this.options.skipCustomOperations,
|
|
160
|
+
});
|
|
161
161
|
const duration = Date.now() - startTime;
|
|
162
162
|
if (result.success) {
|
|
163
163
|
this.status.regenerateCount++;
|
|
@@ -197,9 +197,17 @@ class WatchOrchestrator {
|
|
|
197
197
|
process.stdout.write('\x1B[2J\x1B[0f');
|
|
198
198
|
}
|
|
199
199
|
logHeader() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
let generatorName;
|
|
201
|
+
switch (this.options.generatorType) {
|
|
202
|
+
case 'react-query':
|
|
203
|
+
generatorName = 'React Query hooks';
|
|
204
|
+
break;
|
|
205
|
+
case 'orm':
|
|
206
|
+
generatorName = 'ORM client';
|
|
207
|
+
break;
|
|
208
|
+
default:
|
|
209
|
+
throw new Error(`Unknown generator type: ${this.options.generatorType}`);
|
|
210
|
+
}
|
|
203
211
|
console.log(`\n${'─'.repeat(50)}`);
|
|
204
212
|
console.log(`graphql-codegen watch mode (${generatorName})`);
|
|
205
213
|
console.log(`Endpoint: ${this.options.config.endpoint}`);
|