@constructive-io/graphql-codegen 2.22.1 → 2.23.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/cli/codegen/barrel.d.ts +5 -1
- package/cli/codegen/barrel.js +13 -11
- package/cli/codegen/index.d.ts +3 -3
- package/cli/codegen/index.js +15 -9
- package/cli/codegen/orm/client-generator.js +3 -2
- package/cli/codegen/orm/custom-ops-generator.js +17 -4
- package/cli/codegen/orm/input-types-generator.js +129 -18
- package/cli/codegen/orm/model-generator.js +2 -1
- package/cli/codegen/orm/query-builder.d.ts +1 -1
- package/cli/codegen/orm/query-builder.js +2 -2
- package/cli/codegen/schema-types-generator.js +5 -5
- package/cli/codegen/utils.d.ts +6 -1
- package/cli/codegen/utils.js +23 -8
- package/cli/commands/generate-orm.d.ts +5 -3
- package/cli/commands/generate-orm.js +65 -84
- package/cli/commands/generate.d.ts +2 -0
- package/cli/commands/generate.js +66 -87
- package/cli/commands/shared.d.ts +74 -0
- package/cli/commands/shared.js +88 -0
- package/cli/index.js +75 -45
- package/cli/introspect/index.d.ts +8 -5
- package/cli/introspect/index.js +19 -7
- package/cli/introspect/infer-tables.d.ts +51 -0
- package/cli/introspect/infer-tables.js +550 -0
- package/cli/introspect/pluralize.d.ts +30 -0
- package/cli/introspect/pluralize.js +124 -0
- package/cli/introspect/source/endpoint.d.ts +34 -0
- package/cli/introspect/source/endpoint.js +35 -0
- package/cli/introspect/source/file.d.ts +20 -0
- package/cli/introspect/source/file.js +103 -0
- package/cli/introspect/source/index.d.ts +48 -0
- package/cli/introspect/source/index.js +72 -0
- package/cli/introspect/source/types.d.ts +58 -0
- package/cli/introspect/source/types.js +27 -0
- package/cli/introspect/transform.d.ts +5 -6
- package/cli/introspect/transform.js +0 -173
- package/cli/watch/cache.d.ts +3 -4
- package/cli/watch/cache.js +6 -10
- package/cli/watch/poller.d.ts +1 -2
- package/cli/watch/poller.js +27 -45
- package/cli/watch/types.d.ts +0 -3
- package/esm/cli/codegen/barrel.d.ts +5 -1
- package/esm/cli/codegen/barrel.js +13 -11
- package/esm/cli/codegen/index.d.ts +3 -3
- package/esm/cli/codegen/index.js +18 -12
- package/esm/cli/codegen/orm/client-generator.js +3 -2
- package/esm/cli/codegen/orm/custom-ops-generator.js +18 -5
- package/esm/cli/codegen/orm/input-types-generator.js +130 -19
- package/esm/cli/codegen/orm/model-generator.js +3 -2
- package/esm/cli/codegen/orm/query-builder.d.ts +1 -1
- package/esm/cli/codegen/orm/query-builder.js +2 -2
- package/esm/cli/codegen/schema-types-generator.js +6 -6
- package/esm/cli/codegen/utils.d.ts +6 -1
- package/esm/cli/codegen/utils.js +22 -8
- package/esm/cli/commands/generate-orm.d.ts +5 -3
- package/esm/cli/commands/generate-orm.js +65 -84
- package/esm/cli/commands/generate.d.ts +2 -0
- package/esm/cli/commands/generate.js +66 -87
- package/esm/cli/commands/shared.d.ts +74 -0
- package/esm/cli/commands/shared.js +84 -0
- package/esm/cli/index.js +76 -46
- package/esm/cli/introspect/index.d.ts +8 -5
- package/esm/cli/introspect/index.js +10 -3
- package/esm/cli/introspect/infer-tables.d.ts +51 -0
- package/esm/cli/introspect/infer-tables.js +547 -0
- package/esm/cli/introspect/pluralize.d.ts +30 -0
- package/esm/cli/introspect/pluralize.js +83 -0
- package/esm/cli/introspect/source/endpoint.d.ts +34 -0
- package/esm/cli/introspect/source/endpoint.js +31 -0
- package/esm/cli/introspect/source/file.d.ts +20 -0
- package/esm/cli/introspect/source/file.js +66 -0
- package/esm/cli/introspect/source/index.d.ts +48 -0
- package/esm/cli/introspect/source/index.js +54 -0
- package/esm/cli/introspect/source/types.d.ts +58 -0
- package/esm/cli/introspect/source/types.js +23 -0
- package/esm/cli/introspect/transform.d.ts +5 -6
- package/esm/cli/introspect/transform.js +0 -172
- package/esm/cli/watch/cache.d.ts +3 -4
- package/esm/cli/watch/cache.js +7 -11
- package/esm/cli/watch/poller.d.ts +1 -2
- package/esm/cli/watch/poller.js +28 -46
- package/esm/cli/watch/types.d.ts +0 -3
- package/esm/types/config.d.ts +21 -5
- package/esm/types/config.js +2 -1
- package/package.json +4 -2
- package/types/config.d.ts +21 -5
- package/types/config.js +2 -1
- package/cli/introspect/fetch-meta.d.ts +0 -31
- package/cli/introspect/fetch-meta.js +0 -108
- package/cli/introspect/meta-query.d.ts +0 -111
- package/cli/introspect/meta-query.js +0 -191
- package/esm/cli/introspect/fetch-meta.d.ts +0 -31
- package/esm/cli/introspect/fetch-meta.js +0 -104
- package/esm/cli/introspect/meta-query.d.ts +0 -111
- package/esm/cli/introspect/meta-query.js +0 -188
|
@@ -0,0 +1,124 @@
|
|
|
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.singularize = singularize;
|
|
37
|
+
exports.pluralize = pluralize;
|
|
38
|
+
exports.lcFirst = lcFirst;
|
|
39
|
+
exports.ucFirst = ucFirst;
|
|
40
|
+
exports.toFieldName = toFieldName;
|
|
41
|
+
exports.toQueryName = toQueryName;
|
|
42
|
+
/**
|
|
43
|
+
* Pluralization utilities for inferring entity names from PostGraphile patterns
|
|
44
|
+
*
|
|
45
|
+
* Uses the 'inflection' package which is already a dependency of this package.
|
|
46
|
+
*/
|
|
47
|
+
const inflection = __importStar(require("inflection"));
|
|
48
|
+
/**
|
|
49
|
+
* Latin plural suffixes that inflection handles differently than PostGraphile.
|
|
50
|
+
*
|
|
51
|
+
* The inflection library correctly singularizes Latin words (schemata → schematum),
|
|
52
|
+
* but PostGraphile uses English-style naming (schemata → schema).
|
|
53
|
+
*
|
|
54
|
+
* Format: [pluralSuffix, singularSuffix]
|
|
55
|
+
*/
|
|
56
|
+
const LATIN_SUFFIX_OVERRIDES = [
|
|
57
|
+
// Common Latin plural endings
|
|
58
|
+
['schemata', 'schema'],
|
|
59
|
+
['criteria', 'criterion'],
|
|
60
|
+
['phenomena', 'phenomenon'],
|
|
61
|
+
['media', 'medium'],
|
|
62
|
+
['memoranda', 'memorandum'],
|
|
63
|
+
['strata', 'stratum'],
|
|
64
|
+
['curricula', 'curriculum'],
|
|
65
|
+
['data', 'datum'],
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* Convert a word to its singular form
|
|
69
|
+
* @example "Users" → "User", "People" → "Person", "Schemata" → "Schema", "ApiSchemata" → "ApiSchema"
|
|
70
|
+
*/
|
|
71
|
+
function singularize(word) {
|
|
72
|
+
// Check for Latin suffix overrides (handles compound words like "ApiSchemata")
|
|
73
|
+
const lowerWord = word.toLowerCase();
|
|
74
|
+
for (const [pluralSuffix, singularSuffix] of LATIN_SUFFIX_OVERRIDES) {
|
|
75
|
+
if (lowerWord.endsWith(pluralSuffix)) {
|
|
76
|
+
// Find where the suffix starts in the original word (preserving case)
|
|
77
|
+
const suffixStart = word.length - pluralSuffix.length;
|
|
78
|
+
const prefix = word.slice(0, suffixStart);
|
|
79
|
+
const originalSuffix = word.slice(suffixStart);
|
|
80
|
+
// Preserve the casing of the first letter of the suffix
|
|
81
|
+
const isUpperSuffix = originalSuffix[0] === originalSuffix[0].toUpperCase();
|
|
82
|
+
const newSuffix = isUpperSuffix
|
|
83
|
+
? singularSuffix.charAt(0).toUpperCase() + singularSuffix.slice(1)
|
|
84
|
+
: singularSuffix;
|
|
85
|
+
return prefix + newSuffix;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return inflection.singularize(word);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Convert a word to its plural form
|
|
92
|
+
* @example "User" → "Users", "Person" → "People"
|
|
93
|
+
*/
|
|
94
|
+
function pluralize(word) {
|
|
95
|
+
return inflection.pluralize(word);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Convert PascalCase to camelCase
|
|
99
|
+
* @example "UserProfile" → "userProfile"
|
|
100
|
+
*/
|
|
101
|
+
function lcFirst(str) {
|
|
102
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Convert camelCase to PascalCase
|
|
106
|
+
* @example "userProfile" → "UserProfile"
|
|
107
|
+
*/
|
|
108
|
+
function ucFirst(str) {
|
|
109
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Convert a plural PascalCase type name to singular camelCase field name
|
|
113
|
+
* @example "Users" → "user", "OrderItems" → "orderItem"
|
|
114
|
+
*/
|
|
115
|
+
function toFieldName(pluralTypeName) {
|
|
116
|
+
return lcFirst(singularize(pluralTypeName));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Convert a singular PascalCase type name to plural camelCase query name
|
|
120
|
+
* @example "User" → "users", "OrderItem" → "orderItems"
|
|
121
|
+
*/
|
|
122
|
+
function toQueryName(singularTypeName) {
|
|
123
|
+
return lcFirst(pluralize(singularTypeName));
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint Schema Source
|
|
3
|
+
*
|
|
4
|
+
* Fetches GraphQL schema via introspection from a live endpoint.
|
|
5
|
+
* Wraps the existing fetchSchema() function with the SchemaSource interface.
|
|
6
|
+
*/
|
|
7
|
+
import type { SchemaSource, SchemaSourceResult } from './types';
|
|
8
|
+
export interface EndpointSchemaSourceOptions {
|
|
9
|
+
/**
|
|
10
|
+
* GraphQL endpoint URL
|
|
11
|
+
*/
|
|
12
|
+
endpoint: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional authorization header value (e.g., "Bearer token")
|
|
15
|
+
*/
|
|
16
|
+
authorization?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional additional headers
|
|
19
|
+
*/
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Request timeout in milliseconds (default: 30000)
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Schema source that fetches from a live GraphQL endpoint
|
|
28
|
+
*/
|
|
29
|
+
export declare class EndpointSchemaSource implements SchemaSource {
|
|
30
|
+
private readonly options;
|
|
31
|
+
constructor(options: EndpointSchemaSourceOptions);
|
|
32
|
+
fetch(): Promise<SchemaSourceResult>;
|
|
33
|
+
describe(): string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EndpointSchemaSource = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const fetch_schema_1 = require("../fetch-schema");
|
|
6
|
+
/**
|
|
7
|
+
* Schema source that fetches from a live GraphQL endpoint
|
|
8
|
+
*/
|
|
9
|
+
class EndpointSchemaSource {
|
|
10
|
+
options;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
async fetch() {
|
|
15
|
+
const result = await (0, fetch_schema_1.fetchSchema)({
|
|
16
|
+
endpoint: this.options.endpoint,
|
|
17
|
+
authorization: this.options.authorization,
|
|
18
|
+
headers: this.options.headers,
|
|
19
|
+
timeout: this.options.timeout,
|
|
20
|
+
});
|
|
21
|
+
if (!result.success) {
|
|
22
|
+
throw new types_1.SchemaSourceError(result.error ?? 'Unknown error fetching schema', this.describe());
|
|
23
|
+
}
|
|
24
|
+
if (!result.data) {
|
|
25
|
+
throw new types_1.SchemaSourceError('No introspection data returned', this.describe());
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
introspection: result.data,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
describe() {
|
|
32
|
+
return `endpoint: ${this.options.endpoint}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.EndpointSchemaSource = EndpointSchemaSource;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SchemaSource, SchemaSourceResult } from './types';
|
|
2
|
+
export interface FileSchemaSourceOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the GraphQL schema file (.graphql)
|
|
5
|
+
* Can be absolute or relative to current working directory
|
|
6
|
+
*/
|
|
7
|
+
schemaPath: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Schema source that loads from a local GraphQL schema file
|
|
11
|
+
*
|
|
12
|
+
* Supports .graphql files containing SDL (Schema Definition Language).
|
|
13
|
+
* The SDL is parsed using graphql-js and converted to introspection format.
|
|
14
|
+
*/
|
|
15
|
+
export declare class FileSchemaSource implements SchemaSource {
|
|
16
|
+
private readonly options;
|
|
17
|
+
constructor(options: FileSchemaSourceOptions);
|
|
18
|
+
fetch(): Promise<SchemaSourceResult>;
|
|
19
|
+
describe(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.FileSchemaSource = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* File Schema Source
|
|
39
|
+
*
|
|
40
|
+
* Loads GraphQL schema from a local .graphql SDL file and converts it
|
|
41
|
+
* to introspection format using the graphql package.
|
|
42
|
+
*/
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
const graphql_1 = require("graphql");
|
|
46
|
+
const types_1 = require("./types");
|
|
47
|
+
/**
|
|
48
|
+
* Schema source that loads from a local GraphQL schema file
|
|
49
|
+
*
|
|
50
|
+
* Supports .graphql files containing SDL (Schema Definition Language).
|
|
51
|
+
* The SDL is parsed using graphql-js and converted to introspection format.
|
|
52
|
+
*/
|
|
53
|
+
class FileSchemaSource {
|
|
54
|
+
options;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
async fetch() {
|
|
59
|
+
const absolutePath = path.isAbsolute(this.options.schemaPath)
|
|
60
|
+
? this.options.schemaPath
|
|
61
|
+
: path.resolve(process.cwd(), this.options.schemaPath);
|
|
62
|
+
// Check file exists
|
|
63
|
+
if (!fs.existsSync(absolutePath)) {
|
|
64
|
+
throw new types_1.SchemaSourceError(`Schema file not found: ${absolutePath}`, this.describe());
|
|
65
|
+
}
|
|
66
|
+
// Read file content
|
|
67
|
+
let sdl;
|
|
68
|
+
try {
|
|
69
|
+
sdl = await fs.promises.readFile(absolutePath, 'utf-8');
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
throw new types_1.SchemaSourceError(`Failed to read schema file: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
73
|
+
}
|
|
74
|
+
// Validate non-empty
|
|
75
|
+
if (!sdl.trim()) {
|
|
76
|
+
throw new types_1.SchemaSourceError('Schema file is empty', this.describe());
|
|
77
|
+
}
|
|
78
|
+
// Parse SDL to GraphQL schema
|
|
79
|
+
let schema;
|
|
80
|
+
try {
|
|
81
|
+
schema = (0, graphql_1.buildSchema)(sdl);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
throw new types_1.SchemaSourceError(`Invalid GraphQL SDL: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
85
|
+
}
|
|
86
|
+
// Convert to introspection format
|
|
87
|
+
let introspectionResult;
|
|
88
|
+
try {
|
|
89
|
+
introspectionResult = (0, graphql_1.introspectionFromSchema)(schema);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw new types_1.SchemaSourceError(`Failed to generate introspection: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
93
|
+
}
|
|
94
|
+
// Convert graphql-js introspection result to our mutable type
|
|
95
|
+
// The graphql-js types are readonly, but our types are mutable
|
|
96
|
+
const introspection = JSON.parse(JSON.stringify(introspectionResult));
|
|
97
|
+
return { introspection };
|
|
98
|
+
}
|
|
99
|
+
describe() {
|
|
100
|
+
return `file: ${this.options.schemaPath}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.FileSchemaSource = FileSchemaSource;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Source Module
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified interface for loading GraphQL schemas from different sources:
|
|
5
|
+
* - Live GraphQL endpoints (via introspection)
|
|
6
|
+
* - Static .graphql schema files
|
|
7
|
+
*/
|
|
8
|
+
export * from './types';
|
|
9
|
+
export * from './endpoint';
|
|
10
|
+
export * from './file';
|
|
11
|
+
import type { SchemaSource } from './types';
|
|
12
|
+
export interface CreateSchemaSourceOptions {
|
|
13
|
+
/**
|
|
14
|
+
* GraphQL endpoint URL (for live introspection)
|
|
15
|
+
*/
|
|
16
|
+
endpoint?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Path to GraphQL schema file (.graphql)
|
|
19
|
+
*/
|
|
20
|
+
schema?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional authorization header for endpoint requests
|
|
23
|
+
*/
|
|
24
|
+
authorization?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Optional additional headers for endpoint requests
|
|
27
|
+
*/
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Request timeout in milliseconds (for endpoint requests)
|
|
31
|
+
*/
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a schema source based on configuration
|
|
36
|
+
*
|
|
37
|
+
* @param options - Source configuration
|
|
38
|
+
* @returns Appropriate SchemaSource implementation
|
|
39
|
+
* @throws Error if neither endpoint nor schema is provided
|
|
40
|
+
*/
|
|
41
|
+
export declare function createSchemaSource(options: CreateSchemaSourceOptions): SchemaSource;
|
|
42
|
+
/**
|
|
43
|
+
* Validate that source options are valid (at least one source specified)
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateSourceOptions(options: CreateSchemaSourceOptions): {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
error?: string;
|
|
48
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createSchemaSource = createSchemaSource;
|
|
18
|
+
exports.validateSourceOptions = validateSourceOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Schema Source Module
|
|
21
|
+
*
|
|
22
|
+
* Provides a unified interface for loading GraphQL schemas from different sources:
|
|
23
|
+
* - Live GraphQL endpoints (via introspection)
|
|
24
|
+
* - Static .graphql schema files
|
|
25
|
+
*/
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./endpoint"), exports);
|
|
28
|
+
__exportStar(require("./file"), exports);
|
|
29
|
+
const endpoint_1 = require("./endpoint");
|
|
30
|
+
const file_1 = require("./file");
|
|
31
|
+
/**
|
|
32
|
+
* Create a schema source based on configuration
|
|
33
|
+
*
|
|
34
|
+
* @param options - Source configuration
|
|
35
|
+
* @returns Appropriate SchemaSource implementation
|
|
36
|
+
* @throws Error if neither endpoint nor schema is provided
|
|
37
|
+
*/
|
|
38
|
+
function createSchemaSource(options) {
|
|
39
|
+
if (options.schema) {
|
|
40
|
+
return new file_1.FileSchemaSource({
|
|
41
|
+
schemaPath: options.schema,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (options.endpoint) {
|
|
45
|
+
return new endpoint_1.EndpointSchemaSource({
|
|
46
|
+
endpoint: options.endpoint,
|
|
47
|
+
authorization: options.authorization,
|
|
48
|
+
headers: options.headers,
|
|
49
|
+
timeout: options.timeout,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
throw new Error('Either endpoint or schema must be provided. ' +
|
|
53
|
+
'Use --endpoint for live introspection or --schema for a local file.');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate that source options are valid (at least one source specified)
|
|
57
|
+
*/
|
|
58
|
+
function validateSourceOptions(options) {
|
|
59
|
+
if (!options.endpoint && !options.schema) {
|
|
60
|
+
return {
|
|
61
|
+
valid: false,
|
|
62
|
+
error: 'Either endpoint or schema must be provided',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (options.endpoint && options.schema) {
|
|
66
|
+
return {
|
|
67
|
+
valid: false,
|
|
68
|
+
error: 'Cannot use both endpoint and schema. Choose one source.',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return { valid: true };
|
|
72
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Source Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the interface for schema sources, allowing the codegen pipeline
|
|
5
|
+
* to work with both live GraphQL endpoints and static schema files.
|
|
6
|
+
*/
|
|
7
|
+
import type { IntrospectionQueryResponse } from '../../../types/introspection';
|
|
8
|
+
/**
|
|
9
|
+
* Result from fetching a schema source
|
|
10
|
+
*/
|
|
11
|
+
export interface SchemaSourceResult {
|
|
12
|
+
/**
|
|
13
|
+
* The GraphQL introspection data
|
|
14
|
+
*/
|
|
15
|
+
introspection: IntrospectionQueryResponse;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Abstract interface for schema sources
|
|
19
|
+
*
|
|
20
|
+
* Implementations:
|
|
21
|
+
* - EndpointSchemaSource: Fetches from a live GraphQL endpoint
|
|
22
|
+
* - FileSchemaSource: Loads from a local .graphql schema file
|
|
23
|
+
*/
|
|
24
|
+
export interface SchemaSource {
|
|
25
|
+
/**
|
|
26
|
+
* Fetch or load the GraphQL introspection data
|
|
27
|
+
* @throws SchemaSourceError if fetching fails
|
|
28
|
+
*/
|
|
29
|
+
fetch(): Promise<SchemaSourceResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Human-readable description of the source (for logging)
|
|
32
|
+
* @example "endpoint: https://api.example.com/graphql"
|
|
33
|
+
* @example "file: ./schema.graphql"
|
|
34
|
+
*/
|
|
35
|
+
describe(): string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when a schema source fails to fetch
|
|
39
|
+
*/
|
|
40
|
+
export declare class SchemaSourceError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* Description of the source that failed
|
|
43
|
+
*/
|
|
44
|
+
readonly source: string;
|
|
45
|
+
/**
|
|
46
|
+
* Original error that caused the failure
|
|
47
|
+
*/
|
|
48
|
+
readonly cause?: Error;
|
|
49
|
+
constructor(message: string,
|
|
50
|
+
/**
|
|
51
|
+
* Description of the source that failed
|
|
52
|
+
*/
|
|
53
|
+
source: string,
|
|
54
|
+
/**
|
|
55
|
+
* Original error that caused the failure
|
|
56
|
+
*/
|
|
57
|
+
cause?: Error);
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaSourceError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a schema source fails to fetch
|
|
6
|
+
*/
|
|
7
|
+
class SchemaSourceError extends Error {
|
|
8
|
+
source;
|
|
9
|
+
cause;
|
|
10
|
+
constructor(message,
|
|
11
|
+
/**
|
|
12
|
+
* Description of the source that failed
|
|
13
|
+
*/
|
|
14
|
+
source,
|
|
15
|
+
/**
|
|
16
|
+
* Original error that caused the failure
|
|
17
|
+
*/
|
|
18
|
+
cause) {
|
|
19
|
+
super(`${message} (source: ${source})`);
|
|
20
|
+
this.source = source;
|
|
21
|
+
this.cause = cause;
|
|
22
|
+
this.name = 'SchemaSourceError';
|
|
23
|
+
// Maintain proper prototype chain
|
|
24
|
+
Object.setPrototypeOf(this, SchemaSourceError.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SchemaSourceError = SchemaSourceError;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Table utility functions for CleanTable[]
|
|
3
|
+
*
|
|
4
|
+
* Note: The _meta transform functions have been removed.
|
|
5
|
+
* Tables are now inferred from standard GraphQL introspection
|
|
6
|
+
* using inferTablesFromIntrospection() in ./infer-tables.ts
|
|
3
7
|
*/
|
|
4
8
|
import type { CleanTable } from '../../types/schema';
|
|
5
|
-
import type { MetaQueryResponse } from './meta-query';
|
|
6
|
-
/**
|
|
7
|
-
* Transform _meta response to CleanTable array
|
|
8
|
-
*/
|
|
9
|
-
export declare function transformMetaToCleanTables(metaResponse: MetaQueryResponse): CleanTable[];
|
|
10
9
|
/**
|
|
11
10
|
* Get table names from CleanTable array
|
|
12
11
|
*/
|