@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
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* No file I/O during normal polling - only touchFile is optional file write.
|
|
6
6
|
*/
|
|
7
7
|
import { EventEmitter } from 'node:events';
|
|
8
|
-
import type { MetaQueryResponse } from '../introspect/meta-query';
|
|
9
8
|
import type { IntrospectionQueryResponse } from '../../types/introspection';
|
|
10
9
|
import { SchemaCache } from './cache';
|
|
11
10
|
import type { PollResult, WatchOptions } from './types';
|
|
@@ -62,4 +61,4 @@ export declare class SchemaPoller extends EventEmitter {
|
|
|
62
61
|
/**
|
|
63
62
|
* Utility to compute schema hash without full poll
|
|
64
63
|
*/
|
|
65
|
-
export declare function computeSchemaHash(
|
|
64
|
+
export declare function computeSchemaHash(schema: IntrospectionQueryResponse): Promise<string>;
|
package/esm/cli/watch/poller.js
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
* No file I/O during normal polling - only touchFile is optional file write.
|
|
6
6
|
*/
|
|
7
7
|
import { EventEmitter } from 'node:events';
|
|
8
|
-
import { fetchMeta } from '../introspect/fetch-meta';
|
|
9
8
|
import { fetchSchema } from '../introspect/fetch-schema';
|
|
10
9
|
import { SchemaCache, touchFile } from './cache';
|
|
11
|
-
import { hashObject
|
|
10
|
+
import { hashObject } from './hash';
|
|
12
11
|
/**
|
|
13
12
|
* Schema poller that periodically introspects a GraphQL endpoint
|
|
14
13
|
* and emits events when the schema changes.
|
|
@@ -56,39 +55,31 @@ export class SchemaPoller extends EventEmitter {
|
|
|
56
55
|
async poll() {
|
|
57
56
|
// Prevent concurrent polls
|
|
58
57
|
if (this.isPolling) {
|
|
59
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
changed: false,
|
|
61
|
+
error: 'Poll already in progress',
|
|
62
|
+
};
|
|
60
63
|
}
|
|
61
64
|
this.isPolling = true;
|
|
62
65
|
const startTime = Date.now();
|
|
63
66
|
this.emit('poll-start', this.createEvent('poll-start'));
|
|
64
67
|
try {
|
|
65
|
-
// Fetch
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}),
|
|
73
|
-
fetchSchema({
|
|
74
|
-
endpoint: this.options.endpoint,
|
|
75
|
-
authorization: this.options.authorization,
|
|
76
|
-
headers: this.options.headers,
|
|
77
|
-
timeout: 30000,
|
|
78
|
-
}),
|
|
79
|
-
]);
|
|
68
|
+
// Fetch __schema via standard introspection
|
|
69
|
+
const schemaResult = await fetchSchema({
|
|
70
|
+
endpoint: this.options.endpoint,
|
|
71
|
+
authorization: this.options.authorization,
|
|
72
|
+
headers: this.options.headers,
|
|
73
|
+
timeout: 30000,
|
|
74
|
+
});
|
|
80
75
|
const duration = Date.now() - startTime;
|
|
81
76
|
// Check for errors
|
|
82
|
-
if (!metaResult.success) {
|
|
83
|
-
return this.handleError(`_meta fetch failed: ${metaResult.error}`, duration);
|
|
84
|
-
}
|
|
85
77
|
if (!schemaResult.success) {
|
|
86
78
|
return this.handleError(`__schema fetch failed: ${schemaResult.error}`, duration);
|
|
87
79
|
}
|
|
88
|
-
const meta = metaResult.data;
|
|
89
80
|
const schema = schemaResult.data;
|
|
90
81
|
// Check if schema changed
|
|
91
|
-
const { changed, newHash } = await this.cache.hasChanged(
|
|
82
|
+
const { changed, newHash } = await this.cache.hasChanged(schema);
|
|
92
83
|
// Reset error counter on success
|
|
93
84
|
this.consecutiveErrors = 0;
|
|
94
85
|
if (changed) {
|
|
@@ -99,11 +90,11 @@ export class SchemaPoller extends EventEmitter {
|
|
|
99
90
|
touchFile(this.options.touchFile);
|
|
100
91
|
}
|
|
101
92
|
this.emit('schema-changed', this.createEvent('schema-changed', { hash: newHash, duration }));
|
|
102
|
-
return { success: true, changed: true, hash: newHash,
|
|
93
|
+
return { success: true, changed: true, hash: newHash, schema };
|
|
103
94
|
}
|
|
104
95
|
this.emit('schema-unchanged', this.createEvent('schema-unchanged', { duration }));
|
|
105
96
|
this.emit('poll-success', this.createEvent('poll-success', { duration }));
|
|
106
|
-
return { success: true, changed: false, hash: newHash,
|
|
97
|
+
return { success: true, changed: false, hash: newHash, schema };
|
|
107
98
|
}
|
|
108
99
|
catch (err) {
|
|
109
100
|
const duration = Date.now() - startTime;
|
|
@@ -126,22 +117,14 @@ export class SchemaPoller extends EventEmitter {
|
|
|
126
117
|
*/
|
|
127
118
|
async seedCache() {
|
|
128
119
|
try {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
endpoint: this.options.endpoint,
|
|
138
|
-
authorization: this.options.authorization,
|
|
139
|
-
headers: this.options.headers,
|
|
140
|
-
timeout: 30000,
|
|
141
|
-
}),
|
|
142
|
-
]);
|
|
143
|
-
if (metaResult.success && schemaResult.success) {
|
|
144
|
-
const { newHash } = await this.cache.hasChanged(metaResult.data, schemaResult.data);
|
|
120
|
+
const schemaResult = await fetchSchema({
|
|
121
|
+
endpoint: this.options.endpoint,
|
|
122
|
+
authorization: this.options.authorization,
|
|
123
|
+
headers: this.options.headers,
|
|
124
|
+
timeout: 30000,
|
|
125
|
+
});
|
|
126
|
+
if (schemaResult.success) {
|
|
127
|
+
const { newHash } = await this.cache.hasChanged(schemaResult.data);
|
|
145
128
|
this.cache.updateHash(newHash);
|
|
146
129
|
}
|
|
147
130
|
}
|
|
@@ -171,7 +154,8 @@ export class SchemaPoller extends EventEmitter {
|
|
|
171
154
|
this.consecutiveErrors++;
|
|
172
155
|
this.emit('poll-error', this.createEvent('poll-error', { error, duration }));
|
|
173
156
|
// Slow down polling after multiple consecutive errors
|
|
174
|
-
if (this.consecutiveErrors >= this.MAX_CONSECUTIVE_ERRORS &&
|
|
157
|
+
if (this.consecutiveErrors >= this.MAX_CONSECUTIVE_ERRORS &&
|
|
158
|
+
this.pollTimer) {
|
|
175
159
|
this.stop();
|
|
176
160
|
const newInterval = this.options.pollInterval * 2;
|
|
177
161
|
this.pollTimer = setInterval(() => {
|
|
@@ -191,8 +175,6 @@ export class SchemaPoller extends EventEmitter {
|
|
|
191
175
|
/**
|
|
192
176
|
* Utility to compute schema hash without full poll
|
|
193
177
|
*/
|
|
194
|
-
export async function computeSchemaHash(
|
|
195
|
-
|
|
196
|
-
const schemaHash = await hashObject(schema);
|
|
197
|
-
return combineHashes(metaHash, schemaHash);
|
|
178
|
+
export async function computeSchemaHash(schema) {
|
|
179
|
+
return hashObject(schema);
|
|
198
180
|
}
|
package/esm/cli/watch/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Watch mode types
|
|
3
3
|
*/
|
|
4
|
-
import type { MetaQueryResponse } from '../introspect/meta-query';
|
|
5
4
|
import type { IntrospectionQueryResponse } from '../../types/introspection';
|
|
6
5
|
/**
|
|
7
6
|
* Result of a schema poll operation
|
|
@@ -14,8 +13,6 @@ export interface PollResult {
|
|
|
14
13
|
error?: string;
|
|
15
14
|
/** The new hash if successful */
|
|
16
15
|
hash?: string;
|
|
17
|
-
/** Meta response if successful */
|
|
18
|
-
meta?: MetaQueryResponse;
|
|
19
16
|
/** Schema response if successful */
|
|
20
17
|
schema?: IntrospectionQueryResponse;
|
|
21
18
|
}
|
package/esm/types/config.d.ts
CHANGED
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export interface GraphQLSDKConfig {
|
|
8
8
|
/**
|
|
9
|
-
* GraphQL endpoint URL
|
|
9
|
+
* GraphQL endpoint URL for live introspection
|
|
10
|
+
* Either endpoint or schema must be provided
|
|
10
11
|
*/
|
|
11
|
-
endpoint
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Path to GraphQL schema file (.graphql) for file-based generation
|
|
15
|
+
* Either endpoint or schema must be provided
|
|
16
|
+
*/
|
|
17
|
+
schema?: string;
|
|
12
18
|
/**
|
|
13
19
|
* Headers to include in introspection requests
|
|
14
20
|
*/
|
|
@@ -19,7 +25,7 @@ export interface GraphQLSDKConfig {
|
|
|
19
25
|
*/
|
|
20
26
|
output?: string;
|
|
21
27
|
/**
|
|
22
|
-
* Table filtering options (for table-based CRUD operations
|
|
28
|
+
* Table filtering options (for table-based CRUD operations)
|
|
23
29
|
*/
|
|
24
30
|
tables?: {
|
|
25
31
|
/** Tables to include (glob patterns supported) */
|
|
@@ -154,8 +160,17 @@ export interface ResolvedWatchConfig {
|
|
|
154
160
|
/**
|
|
155
161
|
* Resolved configuration with defaults applied
|
|
156
162
|
*/
|
|
157
|
-
export interface ResolvedConfig
|
|
163
|
+
export interface ResolvedConfig {
|
|
164
|
+
/**
|
|
165
|
+
* GraphQL endpoint URL (empty string if using schema file)
|
|
166
|
+
*/
|
|
167
|
+
endpoint: string;
|
|
168
|
+
/**
|
|
169
|
+
* Path to GraphQL schema file (null if using endpoint)
|
|
170
|
+
*/
|
|
171
|
+
schema: string | null;
|
|
158
172
|
headers: Record<string, string>;
|
|
173
|
+
output: string;
|
|
159
174
|
tables: {
|
|
160
175
|
include: string[];
|
|
161
176
|
exclude: string[];
|
|
@@ -168,6 +183,7 @@ export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers
|
|
|
168
183
|
include: string[];
|
|
169
184
|
exclude: string[];
|
|
170
185
|
};
|
|
186
|
+
excludeFields: string[];
|
|
171
187
|
hooks: {
|
|
172
188
|
queries: boolean;
|
|
173
189
|
mutations: boolean;
|
|
@@ -196,7 +212,7 @@ export declare const DEFAULT_WATCH_CONFIG: ResolvedWatchConfig;
|
|
|
196
212
|
/**
|
|
197
213
|
* Default configuration values
|
|
198
214
|
*/
|
|
199
|
-
export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, 'endpoint'>;
|
|
215
|
+
export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, 'endpoint' | 'schema'>;
|
|
200
216
|
/**
|
|
201
217
|
* Default ORM configuration values
|
|
202
218
|
*/
|
package/esm/types/config.js
CHANGED
|
@@ -65,7 +65,8 @@ export function defineConfig(config) {
|
|
|
65
65
|
*/
|
|
66
66
|
export function resolveConfig(config) {
|
|
67
67
|
return {
|
|
68
|
-
endpoint: config.endpoint,
|
|
68
|
+
endpoint: config.endpoint ?? '',
|
|
69
|
+
schema: config.schema ?? null,
|
|
69
70
|
headers: config.headers ?? DEFAULT_CONFIG.headers,
|
|
70
71
|
output: config.output ?? DEFAULT_CONFIG.output,
|
|
71
72
|
tables: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.23.0",
|
|
4
4
|
"description": "CLI-based GraphQL SDK generator for PostGraphile endpoints with React Query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"test:watch": "jest --watch",
|
|
44
44
|
"example:codegen:sdk": "node dist/cli/index.js generate --endpoint http://api.localhost:3000/graphql --output examples/output/generated-sdk",
|
|
45
45
|
"example:codegen:orm": "node dist/cli/index.js generate-orm --endpoint http://api.localhost:3000/graphql --output examples/output/generated-orm",
|
|
46
|
+
"example:codegen:sdk:schema": "node dist/cli/index.js generate --schema examples/example.schema.graphql --output examples/output/generated-sdk-schema",
|
|
47
|
+
"example:codegen:orm:schema": "node dist/cli/index.js generate-orm --schema examples/example.schema.graphql --output examples/output/generated-orm-schema",
|
|
46
48
|
"example:sdk": "tsx examples/react-query-sdk.ts",
|
|
47
49
|
"example:orm": "tsx examples/orm-sdk.ts"
|
|
48
50
|
},
|
|
@@ -79,5 +81,5 @@
|
|
|
79
81
|
"tsx": "^4.21.0",
|
|
80
82
|
"typescript": "^5.9.3"
|
|
81
83
|
},
|
|
82
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "ba5bbacf7ccc1980cba10bf3f45ebb0ca639fb79"
|
|
83
85
|
}
|
package/types/config.d.ts
CHANGED
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export interface GraphQLSDKConfig {
|
|
8
8
|
/**
|
|
9
|
-
* GraphQL endpoint URL
|
|
9
|
+
* GraphQL endpoint URL for live introspection
|
|
10
|
+
* Either endpoint or schema must be provided
|
|
10
11
|
*/
|
|
11
|
-
endpoint
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Path to GraphQL schema file (.graphql) for file-based generation
|
|
15
|
+
* Either endpoint or schema must be provided
|
|
16
|
+
*/
|
|
17
|
+
schema?: string;
|
|
12
18
|
/**
|
|
13
19
|
* Headers to include in introspection requests
|
|
14
20
|
*/
|
|
@@ -19,7 +25,7 @@ export interface GraphQLSDKConfig {
|
|
|
19
25
|
*/
|
|
20
26
|
output?: string;
|
|
21
27
|
/**
|
|
22
|
-
* Table filtering options (for table-based CRUD operations
|
|
28
|
+
* Table filtering options (for table-based CRUD operations)
|
|
23
29
|
*/
|
|
24
30
|
tables?: {
|
|
25
31
|
/** Tables to include (glob patterns supported) */
|
|
@@ -154,8 +160,17 @@ export interface ResolvedWatchConfig {
|
|
|
154
160
|
/**
|
|
155
161
|
* Resolved configuration with defaults applied
|
|
156
162
|
*/
|
|
157
|
-
export interface ResolvedConfig
|
|
163
|
+
export interface ResolvedConfig {
|
|
164
|
+
/**
|
|
165
|
+
* GraphQL endpoint URL (empty string if using schema file)
|
|
166
|
+
*/
|
|
167
|
+
endpoint: string;
|
|
168
|
+
/**
|
|
169
|
+
* Path to GraphQL schema file (null if using endpoint)
|
|
170
|
+
*/
|
|
171
|
+
schema: string | null;
|
|
158
172
|
headers: Record<string, string>;
|
|
173
|
+
output: string;
|
|
159
174
|
tables: {
|
|
160
175
|
include: string[];
|
|
161
176
|
exclude: string[];
|
|
@@ -168,6 +183,7 @@ export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers
|
|
|
168
183
|
include: string[];
|
|
169
184
|
exclude: string[];
|
|
170
185
|
};
|
|
186
|
+
excludeFields: string[];
|
|
171
187
|
hooks: {
|
|
172
188
|
queries: boolean;
|
|
173
189
|
mutations: boolean;
|
|
@@ -196,7 +212,7 @@ export declare const DEFAULT_WATCH_CONFIG: ResolvedWatchConfig;
|
|
|
196
212
|
/**
|
|
197
213
|
* Default configuration values
|
|
198
214
|
*/
|
|
199
|
-
export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, 'endpoint'>;
|
|
215
|
+
export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, 'endpoint' | 'schema'>;
|
|
200
216
|
/**
|
|
201
217
|
* Default ORM configuration values
|
|
202
218
|
*/
|
package/types/config.js
CHANGED
|
@@ -70,7 +70,8 @@ function defineConfig(config) {
|
|
|
70
70
|
*/
|
|
71
71
|
function resolveConfig(config) {
|
|
72
72
|
return {
|
|
73
|
-
endpoint: config.endpoint,
|
|
73
|
+
endpoint: config.endpoint ?? '',
|
|
74
|
+
schema: config.schema ?? null,
|
|
74
75
|
headers: config.headers ?? exports.DEFAULT_CONFIG.headers,
|
|
75
76
|
output: config.output ?? exports.DEFAULT_CONFIG.output,
|
|
76
77
|
tables: {
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fetch _meta query from a PostGraphile endpoint
|
|
3
|
-
*/
|
|
4
|
-
import { type MetaQueryResponse } from './meta-query';
|
|
5
|
-
export interface FetchMetaOptions {
|
|
6
|
-
/** GraphQL endpoint URL */
|
|
7
|
-
endpoint: string;
|
|
8
|
-
/** Optional authorization header value (e.g., "Bearer token") */
|
|
9
|
-
authorization?: string;
|
|
10
|
-
/** Optional additional headers */
|
|
11
|
-
headers?: Record<string, string>;
|
|
12
|
-
/** Request timeout in milliseconds (default: 30000) */
|
|
13
|
-
timeout?: number;
|
|
14
|
-
}
|
|
15
|
-
export interface FetchMetaResult {
|
|
16
|
-
success: boolean;
|
|
17
|
-
data?: MetaQueryResponse;
|
|
18
|
-
error?: string;
|
|
19
|
-
statusCode?: number;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Fetch the _meta query from a PostGraphile endpoint
|
|
23
|
-
*/
|
|
24
|
-
export declare function fetchMeta(options: FetchMetaOptions): Promise<FetchMetaResult>;
|
|
25
|
-
/**
|
|
26
|
-
* Validate that an endpoint URL is valid
|
|
27
|
-
*/
|
|
28
|
-
export declare function validateEndpoint(endpoint: string): {
|
|
29
|
-
valid: boolean;
|
|
30
|
-
error?: string;
|
|
31
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchMeta = fetchMeta;
|
|
4
|
-
exports.validateEndpoint = validateEndpoint;
|
|
5
|
-
/**
|
|
6
|
-
* Fetch _meta query from a PostGraphile endpoint
|
|
7
|
-
*/
|
|
8
|
-
const meta_query_1 = require("./meta-query");
|
|
9
|
-
/**
|
|
10
|
-
* Fetch the _meta query from a PostGraphile endpoint
|
|
11
|
-
*/
|
|
12
|
-
async function fetchMeta(options) {
|
|
13
|
-
const { endpoint, authorization, headers = {}, timeout = 30000 } = options;
|
|
14
|
-
// Build headers
|
|
15
|
-
const requestHeaders = {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
Accept: 'application/json',
|
|
18
|
-
...headers,
|
|
19
|
-
};
|
|
20
|
-
if (authorization) {
|
|
21
|
-
requestHeaders['Authorization'] = authorization;
|
|
22
|
-
}
|
|
23
|
-
// Create abort controller for timeout
|
|
24
|
-
const controller = new AbortController();
|
|
25
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
26
|
-
try {
|
|
27
|
-
const response = await fetch(endpoint, {
|
|
28
|
-
method: 'POST',
|
|
29
|
-
headers: requestHeaders,
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
query: meta_query_1.META_QUERY,
|
|
32
|
-
variables: {},
|
|
33
|
-
}),
|
|
34
|
-
signal: controller.signal,
|
|
35
|
-
});
|
|
36
|
-
clearTimeout(timeoutId);
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
return {
|
|
39
|
-
success: false,
|
|
40
|
-
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
41
|
-
statusCode: response.status,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const json = (await response.json());
|
|
45
|
-
// Check for GraphQL errors
|
|
46
|
-
if (json.errors && json.errors.length > 0) {
|
|
47
|
-
const errorMessages = json.errors.map((e) => e.message).join('; ');
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
error: `GraphQL errors: ${errorMessages}`,
|
|
51
|
-
statusCode: response.status,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
// Check if _meta is present
|
|
55
|
-
if (!json.data?._meta) {
|
|
56
|
-
return {
|
|
57
|
-
success: false,
|
|
58
|
-
error: 'No _meta field in response. Make sure the endpoint has the PostGraphile meta plugin installed.',
|
|
59
|
-
statusCode: response.status,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
success: true,
|
|
64
|
-
data: json.data,
|
|
65
|
-
statusCode: response.status,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
clearTimeout(timeoutId);
|
|
70
|
-
if (err instanceof Error) {
|
|
71
|
-
if (err.name === 'AbortError') {
|
|
72
|
-
return {
|
|
73
|
-
success: false,
|
|
74
|
-
error: `Request timeout after ${timeout}ms`,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
success: false,
|
|
79
|
-
error: err.message,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
success: false,
|
|
84
|
-
error: 'Unknown error occurred',
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Validate that an endpoint URL is valid
|
|
90
|
-
*/
|
|
91
|
-
function validateEndpoint(endpoint) {
|
|
92
|
-
try {
|
|
93
|
-
const url = new URL(endpoint);
|
|
94
|
-
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
95
|
-
return {
|
|
96
|
-
valid: false,
|
|
97
|
-
error: 'Endpoint must use http or https protocol',
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return { valid: true };
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return {
|
|
104
|
-
valid: false,
|
|
105
|
-
error: 'Invalid URL format',
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The _meta GraphQL query for introspecting PostGraphile schema
|
|
3
|
-
* This query fetches all table metadata including fields, constraints, and relations
|
|
4
|
-
*/
|
|
5
|
-
export declare const META_QUERY = "\nquery Meta {\n _meta {\n tables {\n name\n query {\n all\n create\n delete\n one\n update\n }\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n inflection {\n allRows\n allRowsSimple\n conditionType\n connection\n createField\n createInputType\n createPayloadType\n deleteByPrimaryKey\n deletePayloadType\n edge\n edgeField\n enumType\n filterType\n inputType\n orderByType\n patchField\n patchType\n tableFieldName\n tableType\n typeName\n updateByPrimaryKey\n updatePayloadType\n }\n primaryKeyConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n }\n uniqueConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n }\n foreignKeyConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n refFields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n refTable {\n name\n }\n }\n relations {\n belongsTo {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n references {\n name\n }\n type\n }\n hasOne {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n referencedBy {\n name\n }\n type\n }\n hasMany {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n referencedBy {\n name\n }\n type\n }\n manyToMany {\n fieldName\n junctionTable {\n name\n }\n rightTable {\n name\n }\n type\n }\n }\n }\n }\n}\n";
|
|
6
|
-
/**
|
|
7
|
-
* Types for the _meta query response
|
|
8
|
-
*/
|
|
9
|
-
export interface MetaFieldType {
|
|
10
|
-
gqlType: string;
|
|
11
|
-
isArray: boolean;
|
|
12
|
-
modifier: string | number | null;
|
|
13
|
-
pgAlias: string | null;
|
|
14
|
-
pgType: string | null;
|
|
15
|
-
subtype: string | null;
|
|
16
|
-
typmod: number | null;
|
|
17
|
-
}
|
|
18
|
-
export interface MetaField {
|
|
19
|
-
name: string;
|
|
20
|
-
type: MetaFieldType;
|
|
21
|
-
}
|
|
22
|
-
export interface MetaConstraint {
|
|
23
|
-
name: string;
|
|
24
|
-
fields: MetaField[];
|
|
25
|
-
}
|
|
26
|
-
export interface MetaForeignKeyConstraint extends MetaConstraint {
|
|
27
|
-
refFields: MetaField[];
|
|
28
|
-
refTable: {
|
|
29
|
-
name: string;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export interface MetaTableQuery {
|
|
33
|
-
all: string;
|
|
34
|
-
create: string;
|
|
35
|
-
delete: string | null;
|
|
36
|
-
one: string;
|
|
37
|
-
update: string | null;
|
|
38
|
-
}
|
|
39
|
-
export interface MetaTableInflection {
|
|
40
|
-
allRows: string;
|
|
41
|
-
allRowsSimple: string;
|
|
42
|
-
conditionType: string;
|
|
43
|
-
connection: string;
|
|
44
|
-
createField: string;
|
|
45
|
-
createInputType: string;
|
|
46
|
-
createPayloadType: string;
|
|
47
|
-
deleteByPrimaryKey: string | null;
|
|
48
|
-
deletePayloadType: string;
|
|
49
|
-
edge: string;
|
|
50
|
-
edgeField: string;
|
|
51
|
-
enumType: string;
|
|
52
|
-
filterType: string | null;
|
|
53
|
-
inputType: string;
|
|
54
|
-
orderByType: string;
|
|
55
|
-
patchField: string;
|
|
56
|
-
patchType: string | null;
|
|
57
|
-
tableFieldName: string;
|
|
58
|
-
tableType: string;
|
|
59
|
-
typeName: string;
|
|
60
|
-
updateByPrimaryKey: string | null;
|
|
61
|
-
updatePayloadType: string | null;
|
|
62
|
-
}
|
|
63
|
-
export interface MetaBelongsToRelation {
|
|
64
|
-
fieldName: string | null;
|
|
65
|
-
isUnique: boolean;
|
|
66
|
-
keys: MetaField[];
|
|
67
|
-
references: {
|
|
68
|
-
name: string;
|
|
69
|
-
};
|
|
70
|
-
type: string | null;
|
|
71
|
-
}
|
|
72
|
-
export interface MetaHasRelation {
|
|
73
|
-
fieldName: string | null;
|
|
74
|
-
isUnique: boolean;
|
|
75
|
-
keys: MetaField[];
|
|
76
|
-
referencedBy: {
|
|
77
|
-
name: string;
|
|
78
|
-
};
|
|
79
|
-
type: string | null;
|
|
80
|
-
}
|
|
81
|
-
export interface MetaManyToManyRelation {
|
|
82
|
-
fieldName: string | null;
|
|
83
|
-
junctionTable: {
|
|
84
|
-
name: string;
|
|
85
|
-
};
|
|
86
|
-
rightTable: {
|
|
87
|
-
name: string;
|
|
88
|
-
};
|
|
89
|
-
type: string | null;
|
|
90
|
-
}
|
|
91
|
-
export interface MetaTableRelations {
|
|
92
|
-
belongsTo: MetaBelongsToRelation[];
|
|
93
|
-
hasOne: MetaHasRelation[];
|
|
94
|
-
hasMany: MetaHasRelation[];
|
|
95
|
-
manyToMany: MetaManyToManyRelation[];
|
|
96
|
-
}
|
|
97
|
-
export interface MetaTable {
|
|
98
|
-
name: string;
|
|
99
|
-
query: MetaTableQuery;
|
|
100
|
-
fields: MetaField[];
|
|
101
|
-
inflection: MetaTableInflection;
|
|
102
|
-
primaryKeyConstraints: MetaConstraint[];
|
|
103
|
-
uniqueConstraints: MetaConstraint[];
|
|
104
|
-
foreignKeyConstraints: MetaForeignKeyConstraint[];
|
|
105
|
-
relations: MetaTableRelations;
|
|
106
|
-
}
|
|
107
|
-
export interface MetaQueryResponse {
|
|
108
|
-
_meta: {
|
|
109
|
-
tables: MetaTable[];
|
|
110
|
-
};
|
|
111
|
-
}
|