@constructive-io/graphql-codegen 2.22.0 → 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.
Files changed (95) hide show
  1. package/cli/codegen/barrel.d.ts +5 -1
  2. package/cli/codegen/barrel.js +13 -11
  3. package/cli/codegen/index.d.ts +3 -3
  4. package/cli/codegen/index.js +15 -9
  5. package/cli/codegen/orm/client-generator.js +3 -2
  6. package/cli/codegen/orm/custom-ops-generator.js +17 -4
  7. package/cli/codegen/orm/input-types-generator.js +129 -18
  8. package/cli/codegen/orm/model-generator.js +2 -1
  9. package/cli/codegen/orm/query-builder.d.ts +1 -1
  10. package/cli/codegen/orm/query-builder.js +2 -2
  11. package/cli/codegen/schema-types-generator.js +5 -5
  12. package/cli/codegen/utils.d.ts +6 -1
  13. package/cli/codegen/utils.js +23 -8
  14. package/cli/commands/generate-orm.d.ts +5 -3
  15. package/cli/commands/generate-orm.js +65 -84
  16. package/cli/commands/generate.d.ts +2 -0
  17. package/cli/commands/generate.js +66 -87
  18. package/cli/commands/shared.d.ts +74 -0
  19. package/cli/commands/shared.js +88 -0
  20. package/cli/index.js +75 -45
  21. package/cli/introspect/index.d.ts +8 -5
  22. package/cli/introspect/index.js +19 -7
  23. package/cli/introspect/infer-tables.d.ts +51 -0
  24. package/cli/introspect/infer-tables.js +550 -0
  25. package/cli/introspect/pluralize.d.ts +30 -0
  26. package/cli/introspect/pluralize.js +124 -0
  27. package/cli/introspect/source/endpoint.d.ts +34 -0
  28. package/cli/introspect/source/endpoint.js +35 -0
  29. package/cli/introspect/source/file.d.ts +20 -0
  30. package/cli/introspect/source/file.js +103 -0
  31. package/cli/introspect/source/index.d.ts +48 -0
  32. package/cli/introspect/source/index.js +72 -0
  33. package/cli/introspect/source/types.d.ts +58 -0
  34. package/cli/introspect/source/types.js +27 -0
  35. package/cli/introspect/transform.d.ts +5 -6
  36. package/cli/introspect/transform.js +0 -173
  37. package/cli/watch/cache.d.ts +3 -4
  38. package/cli/watch/cache.js +6 -10
  39. package/cli/watch/poller.d.ts +1 -2
  40. package/cli/watch/poller.js +27 -45
  41. package/cli/watch/types.d.ts +0 -3
  42. package/esm/cli/codegen/barrel.d.ts +5 -1
  43. package/esm/cli/codegen/barrel.js +13 -11
  44. package/esm/cli/codegen/index.d.ts +3 -3
  45. package/esm/cli/codegen/index.js +18 -12
  46. package/esm/cli/codegen/orm/client-generator.js +3 -2
  47. package/esm/cli/codegen/orm/custom-ops-generator.js +18 -5
  48. package/esm/cli/codegen/orm/input-types-generator.js +130 -19
  49. package/esm/cli/codegen/orm/model-generator.js +3 -2
  50. package/esm/cli/codegen/orm/query-builder.d.ts +1 -1
  51. package/esm/cli/codegen/orm/query-builder.js +2 -2
  52. package/esm/cli/codegen/schema-types-generator.js +6 -6
  53. package/esm/cli/codegen/utils.d.ts +6 -1
  54. package/esm/cli/codegen/utils.js +22 -8
  55. package/esm/cli/commands/generate-orm.d.ts +5 -3
  56. package/esm/cli/commands/generate-orm.js +65 -84
  57. package/esm/cli/commands/generate.d.ts +2 -0
  58. package/esm/cli/commands/generate.js +66 -87
  59. package/esm/cli/commands/shared.d.ts +74 -0
  60. package/esm/cli/commands/shared.js +84 -0
  61. package/esm/cli/index.js +76 -46
  62. package/esm/cli/introspect/index.d.ts +8 -5
  63. package/esm/cli/introspect/index.js +10 -3
  64. package/esm/cli/introspect/infer-tables.d.ts +51 -0
  65. package/esm/cli/introspect/infer-tables.js +547 -0
  66. package/esm/cli/introspect/pluralize.d.ts +30 -0
  67. package/esm/cli/introspect/pluralize.js +83 -0
  68. package/esm/cli/introspect/source/endpoint.d.ts +34 -0
  69. package/esm/cli/introspect/source/endpoint.js +31 -0
  70. package/esm/cli/introspect/source/file.d.ts +20 -0
  71. package/esm/cli/introspect/source/file.js +66 -0
  72. package/esm/cli/introspect/source/index.d.ts +48 -0
  73. package/esm/cli/introspect/source/index.js +54 -0
  74. package/esm/cli/introspect/source/types.d.ts +58 -0
  75. package/esm/cli/introspect/source/types.js +23 -0
  76. package/esm/cli/introspect/transform.d.ts +5 -6
  77. package/esm/cli/introspect/transform.js +0 -172
  78. package/esm/cli/watch/cache.d.ts +3 -4
  79. package/esm/cli/watch/cache.js +7 -11
  80. package/esm/cli/watch/poller.d.ts +1 -2
  81. package/esm/cli/watch/poller.js +28 -46
  82. package/esm/cli/watch/types.d.ts +0 -3
  83. package/esm/types/config.d.ts +21 -5
  84. package/esm/types/config.js +2 -1
  85. package/package.json +4 -3
  86. package/types/config.d.ts +21 -5
  87. package/types/config.js +2 -1
  88. package/cli/introspect/fetch-meta.d.ts +0 -31
  89. package/cli/introspect/fetch-meta.js +0 -108
  90. package/cli/introspect/meta-query.d.ts +0 -111
  91. package/cli/introspect/meta-query.js +0 -191
  92. package/esm/cli/introspect/fetch-meta.d.ts +0 -31
  93. package/esm/cli/introspect/fetch-meta.js +0 -104
  94. package/esm/cli/introspect/meta-query.d.ts +0 -111
  95. 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(meta: MetaQueryResponse, schema: IntrospectionQueryResponse): Promise<string>;
64
+ export declare function computeSchemaHash(schema: IntrospectionQueryResponse): Promise<string>;
@@ -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, combineHashes } from './hash';
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 { success: false, changed: false, error: 'Poll already in progress' };
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 both _meta and __schema
66
- const [metaResult, schemaResult] = await Promise.all([
67
- fetchMeta({
68
- endpoint: this.options.endpoint,
69
- authorization: this.options.authorization,
70
- headers: this.options.headers,
71
- timeout: 30000,
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(meta, schema);
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, meta, schema };
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, meta, schema };
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 [metaResult, schemaResult] = await Promise.all([
130
- fetchMeta({
131
- endpoint: this.options.endpoint,
132
- authorization: this.options.authorization,
133
- headers: this.options.headers,
134
- timeout: 30000,
135
- }),
136
- fetchSchema({
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 && this.pollTimer) {
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(meta, schema) {
195
- const metaHash = await hashObject(meta);
196
- const schemaHash = await hashObject(schema);
197
- return combineHashes(metaHash, schemaHash);
178
+ export async function computeSchemaHash(schema) {
179
+ return hashObject(schema);
198
180
  }
@@ -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
  }
@@ -6,9 +6,15 @@
6
6
  */
7
7
  export interface GraphQLSDKConfig {
8
8
  /**
9
- * GraphQL endpoint URL (must expose _meta query)
9
+ * GraphQL endpoint URL for live introspection
10
+ * Either endpoint or schema must be provided
10
11
  */
11
- endpoint: string;
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 from _meta)
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 extends Required<Omit<GraphQLSDKConfig, 'headers' | 'tables' | 'queries' | 'mutations' | 'hooks' | 'postgraphile' | 'codegen' | 'orm' | 'reactQuery' | 'watch'>> {
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
  */
@@ -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.22.0",
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
  },
@@ -70,7 +72,6 @@
70
72
  },
71
73
  "devDependencies": {
72
74
  "@tanstack/react-query": "^5.90.16",
73
- "@types/inflection": "^1.13.2",
74
75
  "@types/jest": "^29.5.14",
75
76
  "@types/node": "^20.19.27",
76
77
  "@types/react": "^19.2.7",
@@ -80,5 +81,5 @@
80
81
  "tsx": "^4.21.0",
81
82
  "typescript": "^5.9.3"
82
83
  },
83
- "gitHead": "fe5e59d3a4497d7ac91a051b74e181851393f56c"
84
+ "gitHead": "ba5bbacf7ccc1980cba10bf3f45ebb0ca639fb79"
84
85
  }
package/types/config.d.ts CHANGED
@@ -6,9 +6,15 @@
6
6
  */
7
7
  export interface GraphQLSDKConfig {
8
8
  /**
9
- * GraphQL endpoint URL (must expose _meta query)
9
+ * GraphQL endpoint URL for live introspection
10
+ * Either endpoint or schema must be provided
10
11
  */
11
- endpoint: string;
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 from _meta)
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 extends Required<Omit<GraphQLSDKConfig, 'headers' | 'tables' | 'queries' | 'mutations' | 'hooks' | 'postgraphile' | 'codegen' | 'orm' | 'reactQuery' | 'watch'>> {
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
- }