@constructive-io/graphql-codegen 4.6.0 → 4.7.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 (75) hide show
  1. package/client/error.d.ts +2 -93
  2. package/client/error.js +9 -273
  3. package/client/execute.d.ts +2 -55
  4. package/client/execute.js +5 -120
  5. package/client/typed-document.d.ts +2 -29
  6. package/client/typed-document.js +3 -39
  7. package/core/ast.d.ts +8 -10
  8. package/core/ast.js +17 -592
  9. package/core/custom-ast.d.ts +5 -33
  10. package/core/custom-ast.js +16 -203
  11. package/core/introspect/infer-tables.d.ts +2 -40
  12. package/core/introspect/infer-tables.js +4 -653
  13. package/core/introspect/schema-query.d.ts +3 -18
  14. package/core/introspect/schema-query.js +3 -118
  15. package/core/introspect/transform-schema.d.ts +2 -84
  16. package/core/introspect/transform-schema.js +14 -279
  17. package/core/introspect/transform.d.ts +2 -18
  18. package/core/introspect/transform.js +6 -39
  19. package/core/meta-object/convert.d.ts +2 -63
  20. package/core/meta-object/convert.js +4 -59
  21. package/core/meta-object/validate.d.ts +2 -7
  22. package/core/meta-object/validate.js +4 -30
  23. package/core/query-builder.d.ts +7 -46
  24. package/core/query-builder.js +8 -408
  25. package/core/types.d.ts +9 -139
  26. package/core/types.js +12 -26
  27. package/esm/client/error.d.ts +2 -93
  28. package/esm/client/error.js +2 -269
  29. package/esm/client/execute.d.ts +2 -55
  30. package/esm/client/execute.js +2 -118
  31. package/esm/client/typed-document.d.ts +2 -29
  32. package/esm/client/typed-document.js +2 -38
  33. package/esm/core/ast.d.ts +8 -10
  34. package/esm/core/ast.js +8 -550
  35. package/esm/core/custom-ast.d.ts +5 -33
  36. package/esm/core/custom-ast.js +5 -160
  37. package/esm/core/introspect/infer-tables.d.ts +2 -40
  38. package/esm/core/introspect/infer-tables.js +2 -652
  39. package/esm/core/introspect/schema-query.d.ts +3 -18
  40. package/esm/core/introspect/schema-query.js +2 -118
  41. package/esm/core/introspect/transform-schema.d.ts +2 -84
  42. package/esm/core/introspect/transform-schema.js +2 -269
  43. package/esm/core/introspect/transform.d.ts +2 -18
  44. package/esm/core/introspect/transform.js +2 -36
  45. package/esm/core/meta-object/convert.d.ts +2 -63
  46. package/esm/core/meta-object/convert.js +2 -58
  47. package/esm/core/meta-object/validate.d.ts +2 -7
  48. package/esm/core/meta-object/validate.js +2 -26
  49. package/esm/core/query-builder.d.ts +7 -46
  50. package/esm/core/query-builder.js +5 -373
  51. package/esm/core/types.d.ts +9 -139
  52. package/esm/core/types.js +9 -24
  53. package/esm/generators/field-selector.d.ts +5 -28
  54. package/esm/generators/field-selector.js +5 -354
  55. package/esm/generators/mutations.d.ts +5 -29
  56. package/esm/generators/mutations.js +5 -195
  57. package/esm/generators/naming-helpers.d.ts +6 -0
  58. package/esm/generators/naming-helpers.js +6 -0
  59. package/esm/generators/select.d.ts +6 -48
  60. package/esm/generators/select.js +6 -634
  61. package/esm/types/query.d.ts +9 -0
  62. package/esm/types/schema.d.ts +4 -0
  63. package/generators/field-selector.d.ts +5 -28
  64. package/generators/field-selector.js +12 -360
  65. package/generators/mutations.d.ts +5 -29
  66. package/generators/mutations.js +9 -231
  67. package/generators/naming-helpers.d.ts +6 -0
  68. package/generators/naming-helpers.js +20 -0
  69. package/generators/select.d.ts +6 -48
  70. package/generators/select.js +17 -677
  71. package/package.json +7 -6
  72. package/types/query.d.ts +9 -0
  73. package/types/schema.d.ts +4 -0
  74. package/core/meta-object/format.json +0 -93
  75. package/esm/core/meta-object/format.json +0 -93
package/client/error.d.ts CHANGED
@@ -1,95 +1,4 @@
1
1
  /**
2
- * Error handling for GraphQL operations
3
- * Provides consistent error types and parsing for PostGraphile responses
2
+ * Re-export error handling utilities from @constructive-io/graphql-query.
4
3
  */
5
- export declare const DataErrorType: {
6
- readonly NETWORK_ERROR: "NETWORK_ERROR";
7
- readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
8
- readonly VALIDATION_FAILED: "VALIDATION_FAILED";
9
- readonly REQUIRED_FIELD_MISSING: "REQUIRED_FIELD_MISSING";
10
- readonly INVALID_MUTATION_DATA: "INVALID_MUTATION_DATA";
11
- readonly QUERY_GENERATION_FAILED: "QUERY_GENERATION_FAILED";
12
- readonly QUERY_EXECUTION_FAILED: "QUERY_EXECUTION_FAILED";
13
- readonly UNAUTHORIZED: "UNAUTHORIZED";
14
- readonly FORBIDDEN: "FORBIDDEN";
15
- readonly TABLE_NOT_FOUND: "TABLE_NOT_FOUND";
16
- readonly BAD_REQUEST: "BAD_REQUEST";
17
- readonly NOT_FOUND: "NOT_FOUND";
18
- readonly GRAPHQL_ERROR: "GRAPHQL_ERROR";
19
- readonly UNIQUE_VIOLATION: "UNIQUE_VIOLATION";
20
- readonly FOREIGN_KEY_VIOLATION: "FOREIGN_KEY_VIOLATION";
21
- readonly NOT_NULL_VIOLATION: "NOT_NULL_VIOLATION";
22
- readonly CHECK_VIOLATION: "CHECK_VIOLATION";
23
- readonly EXCLUSION_VIOLATION: "EXCLUSION_VIOLATION";
24
- readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
25
- };
26
- export type DataErrorType = (typeof DataErrorType)[keyof typeof DataErrorType];
27
- export interface DataErrorOptions {
28
- tableName?: string;
29
- fieldName?: string;
30
- constraint?: string;
31
- originalError?: Error;
32
- code?: string;
33
- context?: Record<string, unknown>;
34
- }
35
- /**
36
- * Standard error class for data layer operations
37
- */
38
- export declare class DataError extends Error {
39
- readonly type: DataErrorType;
40
- readonly code?: string;
41
- readonly originalError?: Error;
42
- readonly context?: Record<string, unknown>;
43
- readonly tableName?: string;
44
- readonly fieldName?: string;
45
- readonly constraint?: string;
46
- constructor(type: DataErrorType, message: string, options?: DataErrorOptions);
47
- getUserMessage(): string;
48
- isRetryable(): boolean;
49
- }
50
- export declare const PG_ERROR_CODES: {
51
- readonly UNIQUE_VIOLATION: "23505";
52
- readonly FOREIGN_KEY_VIOLATION: "23503";
53
- readonly NOT_NULL_VIOLATION: "23502";
54
- readonly CHECK_VIOLATION: "23514";
55
- readonly EXCLUSION_VIOLATION: "23P01";
56
- readonly NUMERIC_VALUE_OUT_OF_RANGE: "22003";
57
- readonly STRING_DATA_RIGHT_TRUNCATION: "22001";
58
- readonly INVALID_TEXT_REPRESENTATION: "22P02";
59
- readonly DATETIME_FIELD_OVERFLOW: "22008";
60
- readonly UNDEFINED_TABLE: "42P01";
61
- readonly UNDEFINED_COLUMN: "42703";
62
- readonly INSUFFICIENT_PRIVILEGE: "42501";
63
- };
64
- export declare const createError: {
65
- network: (originalError?: Error) => DataError;
66
- timeout: (originalError?: Error) => DataError;
67
- unauthorized: (message?: string) => DataError;
68
- forbidden: (message?: string) => DataError;
69
- badRequest: (message: string, code?: string) => DataError;
70
- notFound: (message?: string) => DataError;
71
- graphql: (message: string, code?: string) => DataError;
72
- uniqueViolation: (message: string, fieldName?: string, constraint?: string) => DataError;
73
- foreignKeyViolation: (message: string, fieldName?: string, constraint?: string) => DataError;
74
- notNullViolation: (message: string, fieldName?: string, constraint?: string) => DataError;
75
- unknown: (originalError: Error) => DataError;
76
- };
77
- export interface GraphQLError {
78
- message: string;
79
- extensions?: {
80
- code?: string;
81
- } & Record<string, unknown>;
82
- locations?: Array<{
83
- line: number;
84
- column: number;
85
- }>;
86
- path?: Array<string | number>;
87
- }
88
- /**
89
- * Parse any error into a DataError
90
- */
91
- export declare function parseGraphQLError(error: unknown): DataError;
92
- /**
93
- * Check if value is a DataError
94
- */
95
- export declare function isDataError(error: unknown): error is DataError;
4
+ export { DataError, DataErrorType, PG_ERROR_CODES, createError, parseGraphQLError, isDataError, type DataErrorOptions, type GraphQLError, } from '@constructive-io/graphql-query';
package/client/error.js CHANGED
@@ -1,277 +1,13 @@
1
1
  "use strict";
2
- /**
3
- * Error handling for GraphQL operations
4
- * Provides consistent error types and parsing for PostGraphile responses
5
- */
6
2
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createError = exports.PG_ERROR_CODES = exports.DataError = exports.DataErrorType = void 0;
8
- exports.parseGraphQLError = parseGraphQLError;
9
- exports.isDataError = isDataError;
10
- // ============================================================================
11
- // Error Types
12
- // ============================================================================
13
- exports.DataErrorType = {
14
- // Network/Connection errors
15
- NETWORK_ERROR: 'NETWORK_ERROR',
16
- TIMEOUT_ERROR: 'TIMEOUT_ERROR',
17
- // Validation errors
18
- VALIDATION_FAILED: 'VALIDATION_FAILED',
19
- REQUIRED_FIELD_MISSING: 'REQUIRED_FIELD_MISSING',
20
- INVALID_MUTATION_DATA: 'INVALID_MUTATION_DATA',
21
- // Query errors
22
- QUERY_GENERATION_FAILED: 'QUERY_GENERATION_FAILED',
23
- QUERY_EXECUTION_FAILED: 'QUERY_EXECUTION_FAILED',
24
- // Permission errors
25
- UNAUTHORIZED: 'UNAUTHORIZED',
26
- FORBIDDEN: 'FORBIDDEN',
27
- // Schema errors
28
- TABLE_NOT_FOUND: 'TABLE_NOT_FOUND',
29
- // Request errors
30
- BAD_REQUEST: 'BAD_REQUEST',
31
- NOT_FOUND: 'NOT_FOUND',
32
- // GraphQL-specific errors
33
- GRAPHQL_ERROR: 'GRAPHQL_ERROR',
34
- // PostgreSQL constraint errors (surfaced via PostGraphile)
35
- UNIQUE_VIOLATION: 'UNIQUE_VIOLATION',
36
- FOREIGN_KEY_VIOLATION: 'FOREIGN_KEY_VIOLATION',
37
- NOT_NULL_VIOLATION: 'NOT_NULL_VIOLATION',
38
- CHECK_VIOLATION: 'CHECK_VIOLATION',
39
- EXCLUSION_VIOLATION: 'EXCLUSION_VIOLATION',
40
- // Generic errors
41
- UNKNOWN_ERROR: 'UNKNOWN_ERROR',
42
- };
43
- /**
44
- * Standard error class for data layer operations
45
- */
46
- class DataError extends Error {
47
- type;
48
- code;
49
- originalError;
50
- context;
51
- tableName;
52
- fieldName;
53
- constraint;
54
- constructor(type, message, options = {}) {
55
- super(message);
56
- this.name = 'DataError';
57
- this.type = type;
58
- this.code = options.code;
59
- this.originalError = options.originalError;
60
- this.context = options.context;
61
- this.tableName = options.tableName;
62
- this.fieldName = options.fieldName;
63
- this.constraint = options.constraint;
64
- if (Error.captureStackTrace) {
65
- Error.captureStackTrace(this, DataError);
66
- }
67
- }
68
- getUserMessage() {
69
- switch (this.type) {
70
- case exports.DataErrorType.NETWORK_ERROR:
71
- return 'Network error. Please check your connection and try again.';
72
- case exports.DataErrorType.TIMEOUT_ERROR:
73
- return 'Request timed out. Please try again.';
74
- case exports.DataErrorType.UNAUTHORIZED:
75
- return 'You are not authorized. Please log in and try again.';
76
- case exports.DataErrorType.FORBIDDEN:
77
- return 'You do not have permission to access this resource.';
78
- case exports.DataErrorType.VALIDATION_FAILED:
79
- return 'Validation failed. Please check your input and try again.';
80
- case exports.DataErrorType.REQUIRED_FIELD_MISSING:
81
- return this.fieldName
82
- ? `The field "${this.fieldName}" is required.`
83
- : 'A required field is missing.';
84
- case exports.DataErrorType.UNIQUE_VIOLATION:
85
- return this.fieldName
86
- ? `A record with this ${this.fieldName} already exists.`
87
- : 'A record with this value already exists.';
88
- case exports.DataErrorType.FOREIGN_KEY_VIOLATION:
89
- return 'This record references a record that does not exist.';
90
- case exports.DataErrorType.NOT_NULL_VIOLATION:
91
- return this.fieldName
92
- ? `The field "${this.fieldName}" cannot be empty.`
93
- : 'A required field cannot be empty.';
94
- case exports.DataErrorType.CHECK_VIOLATION:
95
- return this.fieldName
96
- ? `The value for "${this.fieldName}" is not valid.`
97
- : 'The value does not meet the required constraints.';
98
- default:
99
- return this.message || 'An unexpected error occurred.';
100
- }
101
- }
102
- isRetryable() {
103
- return (this.type === exports.DataErrorType.NETWORK_ERROR ||
104
- this.type === exports.DataErrorType.TIMEOUT_ERROR);
105
- }
106
- }
107
- exports.DataError = DataError;
108
- // ============================================================================
109
- // PostgreSQL Error Codes
110
- // ============================================================================
111
- exports.PG_ERROR_CODES = {
112
- UNIQUE_VIOLATION: '23505',
113
- FOREIGN_KEY_VIOLATION: '23503',
114
- NOT_NULL_VIOLATION: '23502',
115
- CHECK_VIOLATION: '23514',
116
- EXCLUSION_VIOLATION: '23P01',
117
- NUMERIC_VALUE_OUT_OF_RANGE: '22003',
118
- STRING_DATA_RIGHT_TRUNCATION: '22001',
119
- INVALID_TEXT_REPRESENTATION: '22P02',
120
- DATETIME_FIELD_OVERFLOW: '22008',
121
- UNDEFINED_TABLE: '42P01',
122
- UNDEFINED_COLUMN: '42703',
123
- INSUFFICIENT_PRIVILEGE: '42501',
124
- };
125
- // ============================================================================
126
- // Error Factory
127
- // ============================================================================
128
- exports.createError = {
129
- network: (originalError) => new DataError(exports.DataErrorType.NETWORK_ERROR, 'Network error occurred', {
130
- originalError,
131
- }),
132
- timeout: (originalError) => new DataError(exports.DataErrorType.TIMEOUT_ERROR, 'Request timed out', {
133
- originalError,
134
- }),
135
- unauthorized: (message = 'Authentication required') => new DataError(exports.DataErrorType.UNAUTHORIZED, message),
136
- forbidden: (message = 'Access forbidden') => new DataError(exports.DataErrorType.FORBIDDEN, message),
137
- badRequest: (message, code) => new DataError(exports.DataErrorType.BAD_REQUEST, message, { code }),
138
- notFound: (message = 'Resource not found') => new DataError(exports.DataErrorType.NOT_FOUND, message),
139
- graphql: (message, code) => new DataError(exports.DataErrorType.GRAPHQL_ERROR, message, { code }),
140
- uniqueViolation: (message, fieldName, constraint) => new DataError(exports.DataErrorType.UNIQUE_VIOLATION, message, {
141
- fieldName,
142
- constraint,
143
- code: '23505',
144
- }),
145
- foreignKeyViolation: (message, fieldName, constraint) => new DataError(exports.DataErrorType.FOREIGN_KEY_VIOLATION, message, {
146
- fieldName,
147
- constraint,
148
- code: '23503',
149
- }),
150
- notNullViolation: (message, fieldName, constraint) => new DataError(exports.DataErrorType.NOT_NULL_VIOLATION, message, {
151
- fieldName,
152
- constraint,
153
- code: '23502',
154
- }),
155
- unknown: (originalError) => new DataError(exports.DataErrorType.UNKNOWN_ERROR, originalError.message, {
156
- originalError,
157
- }),
158
- };
159
- function parseGraphQLErrorCode(code) {
160
- if (!code)
161
- return exports.DataErrorType.UNKNOWN_ERROR;
162
- const normalized = code.toUpperCase();
163
- // GraphQL standard codes
164
- if (normalized === 'UNAUTHENTICATED')
165
- return exports.DataErrorType.UNAUTHORIZED;
166
- if (normalized === 'FORBIDDEN')
167
- return exports.DataErrorType.FORBIDDEN;
168
- if (normalized === 'GRAPHQL_VALIDATION_FAILED')
169
- return exports.DataErrorType.QUERY_GENERATION_FAILED;
170
- // PostgreSQL SQLSTATE codes
171
- if (code === exports.PG_ERROR_CODES.UNIQUE_VIOLATION)
172
- return exports.DataErrorType.UNIQUE_VIOLATION;
173
- if (code === exports.PG_ERROR_CODES.FOREIGN_KEY_VIOLATION)
174
- return exports.DataErrorType.FOREIGN_KEY_VIOLATION;
175
- if (code === exports.PG_ERROR_CODES.NOT_NULL_VIOLATION)
176
- return exports.DataErrorType.NOT_NULL_VIOLATION;
177
- if (code === exports.PG_ERROR_CODES.CHECK_VIOLATION)
178
- return exports.DataErrorType.CHECK_VIOLATION;
179
- if (code === exports.PG_ERROR_CODES.EXCLUSION_VIOLATION)
180
- return exports.DataErrorType.EXCLUSION_VIOLATION;
181
- return exports.DataErrorType.UNKNOWN_ERROR;
182
- }
183
- function classifyByMessage(message) {
184
- const lower = message.toLowerCase();
185
- if (lower.includes('timeout') || lower.includes('timed out')) {
186
- return exports.DataErrorType.TIMEOUT_ERROR;
187
- }
188
- if (lower.includes('network') ||
189
- lower.includes('fetch') ||
190
- lower.includes('failed to fetch')) {
191
- return exports.DataErrorType.NETWORK_ERROR;
192
- }
193
- if (lower.includes('unauthorized') ||
194
- lower.includes('authentication required')) {
195
- return exports.DataErrorType.UNAUTHORIZED;
196
- }
197
- if (lower.includes('forbidden') || lower.includes('permission')) {
198
- return exports.DataErrorType.FORBIDDEN;
199
- }
200
- if (lower.includes('duplicate key') || lower.includes('already exists')) {
201
- return exports.DataErrorType.UNIQUE_VIOLATION;
202
- }
203
- if (lower.includes('foreign key constraint')) {
204
- return exports.DataErrorType.FOREIGN_KEY_VIOLATION;
205
- }
206
- if (lower.includes('not-null constraint') ||
207
- lower.includes('null value in column')) {
208
- return exports.DataErrorType.NOT_NULL_VIOLATION;
209
- }
210
- return exports.DataErrorType.UNKNOWN_ERROR;
211
- }
212
- function extractFieldFromError(message, constraint, column) {
213
- if (column)
214
- return column;
215
- const columnMatch = message.match(/column\s+"?([a-z_][a-z0-9_]*)"?/i);
216
- if (columnMatch)
217
- return columnMatch[1];
218
- if (constraint) {
219
- const constraintMatch = constraint.match(/_([a-z_][a-z0-9_]*)_(?:key|fkey|check|pkey)$/i);
220
- if (constraintMatch)
221
- return constraintMatch[1];
222
- }
223
- const keyMatch = message.match(/Key\s+\(([a-z_][a-z0-9_]*)\)/i);
224
- if (keyMatch)
225
- return keyMatch[1];
226
- return undefined;
227
- }
228
- /**
229
- * Parse any error into a DataError
230
- */
231
- function parseGraphQLError(error) {
232
- if (error instanceof DataError) {
233
- return error;
234
- }
235
- // GraphQL error object
236
- if (error &&
237
- typeof error === 'object' &&
238
- 'message' in error &&
239
- typeof error.message === 'string') {
240
- const gqlError = error;
241
- const extCode = gqlError.extensions?.code;
242
- const mappedType = parseGraphQLErrorCode(extCode);
243
- const column = gqlError.extensions?.column;
244
- const constraint = gqlError.extensions?.constraint;
245
- const fieldName = extractFieldFromError(gqlError.message, constraint, column);
246
- if (mappedType !== exports.DataErrorType.UNKNOWN_ERROR) {
247
- return new DataError(mappedType, gqlError.message, {
248
- code: extCode,
249
- fieldName,
250
- constraint,
251
- context: gqlError.extensions,
252
- });
253
- }
254
- // Fallback: classify by message
255
- const fallbackType = classifyByMessage(gqlError.message);
256
- return new DataError(fallbackType, gqlError.message, {
257
- code: extCode,
258
- fieldName,
259
- constraint,
260
- context: gqlError.extensions,
261
- });
262
- }
263
- // Standard Error
264
- if (error instanceof Error) {
265
- const type = classifyByMessage(error.message);
266
- return new DataError(type, error.message, { originalError: error });
267
- }
268
- // Unknown
269
- const message = typeof error === 'string' ? error : 'Unknown error occurred';
270
- return new DataError(exports.DataErrorType.UNKNOWN_ERROR, message);
271
- }
3
+ exports.isDataError = exports.parseGraphQLError = exports.createError = exports.PG_ERROR_CODES = exports.DataErrorType = exports.DataError = void 0;
272
4
  /**
273
- * Check if value is a DataError
5
+ * Re-export error handling utilities from @constructive-io/graphql-query.
274
6
  */
275
- function isDataError(error) {
276
- return error instanceof DataError;
277
- }
7
+ var graphql_query_1 = require("@constructive-io/graphql-query");
8
+ Object.defineProperty(exports, "DataError", { enumerable: true, get: function () { return graphql_query_1.DataError; } });
9
+ Object.defineProperty(exports, "DataErrorType", { enumerable: true, get: function () { return graphql_query_1.DataErrorType; } });
10
+ Object.defineProperty(exports, "PG_ERROR_CODES", { enumerable: true, get: function () { return graphql_query_1.PG_ERROR_CODES; } });
11
+ Object.defineProperty(exports, "createError", { enumerable: true, get: function () { return graphql_query_1.createError; } });
12
+ Object.defineProperty(exports, "parseGraphQLError", { enumerable: true, get: function () { return graphql_query_1.parseGraphQLError; } });
13
+ Object.defineProperty(exports, "isDataError", { enumerable: true, get: function () { return graphql_query_1.isDataError; } });
@@ -1,57 +1,4 @@
1
1
  /**
2
- * GraphQL execution utilities
2
+ * Re-export GraphQL execution utilities from @constructive-io/graphql-query.
3
3
  */
4
- import type { DocumentNode } from 'graphql';
5
- import { TypedDocumentString } from './typed-document';
6
- type ExecutableDocument = TypedDocumentString<unknown, unknown> | DocumentNode | string;
7
- type ResultOf<TDocument> = TDocument extends TypedDocumentString<infer TResult, unknown> ? TResult : unknown;
8
- type VariablesOf<TDocument> = TDocument extends TypedDocumentString<unknown, infer TVariables> ? TVariables : Record<string, unknown>;
9
- export interface ExecuteOptions {
10
- /** Custom headers to include */
11
- headers?: Record<string, string>;
12
- /** Request timeout in milliseconds */
13
- timeout?: number;
14
- /** Signal for request cancellation */
15
- signal?: AbortSignal;
16
- }
17
- export interface GraphQLResponse<T = unknown> {
18
- data?: T;
19
- errors?: Array<{
20
- message: string;
21
- extensions?: {
22
- code?: string;
23
- } & Record<string, unknown>;
24
- locations?: Array<{
25
- line: number;
26
- column: number;
27
- }>;
28
- path?: Array<string | number>;
29
- }>;
30
- }
31
- /**
32
- * Execute a GraphQL operation against an endpoint
33
- */
34
- export declare function execute<TDocument extends ExecutableDocument>(endpoint: string, document: TDocument, variables?: VariablesOf<TDocument>, options?: ExecuteOptions): Promise<ResultOf<TDocument>>;
35
- export interface GraphQLClientOptions {
36
- /** GraphQL endpoint URL */
37
- endpoint: string;
38
- /** Default headers to include with every request */
39
- headers?: Record<string, string>;
40
- /** Default timeout in milliseconds */
41
- timeout?: number;
42
- }
43
- /**
44
- * Create a GraphQL client instance
45
- */
46
- export declare function createGraphQLClient(options: GraphQLClientOptions): {
47
- /**
48
- * Execute a GraphQL operation
49
- */
50
- execute<TDocument extends ExecutableDocument>(document: TDocument, variables?: VariablesOf<TDocument>, options?: ExecuteOptions): Promise<ResultOf<TDocument>>;
51
- /**
52
- * Get the endpoint URL
53
- */
54
- getEndpoint(): string;
55
- };
56
- export type GraphQLClient = ReturnType<typeof createGraphQLClient>;
57
- export {};
4
+ export { execute, createGraphQLClient, type ExecuteOptions, type GraphQLResponse, type GraphQLClientOptions, type GraphQLClient, } from '@constructive-io/graphql-query';
package/client/execute.js CHANGED
@@ -1,124 +1,9 @@
1
1
  "use strict";
2
- /**
3
- * GraphQL execution utilities
4
- */
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.execute = execute;
7
- exports.createGraphQLClient = createGraphQLClient;
8
- const graphql_1 = require("graphql");
9
- const error_1 = require("./error");
10
- const typed_document_1 = require("./typed-document");
11
- // ============================================================================
12
- // Helpers
13
- // ============================================================================
14
- function documentToString(document) {
15
- if (typeof document === 'string')
16
- return document;
17
- if (document instanceof typed_document_1.TypedDocumentString)
18
- return document.toString();
19
- // DocumentNode
20
- if (document && typeof document === 'object' && 'kind' in document) {
21
- return (0, graphql_1.print)(document);
22
- }
23
- throw error_1.createError.badRequest('Invalid GraphQL document');
24
- }
25
- // ============================================================================
26
- // Execute Function
27
- // ============================================================================
28
- /**
29
- * Execute a GraphQL operation against an endpoint
30
- */
31
- async function execute(endpoint, document, variables, options = {}) {
32
- const { headers = {}, timeout = 30000, signal } = options;
33
- // Create timeout controller
34
- const controller = new AbortController();
35
- const timeoutId = setTimeout(() => controller.abort(), timeout);
36
- // Combine signals if provided
37
- const combinedSignal = signal
38
- ? AbortSignal.any([signal, controller.signal])
39
- : controller.signal;
40
- try {
41
- const response = await fetch(endpoint, {
42
- method: 'POST',
43
- headers: {
44
- 'Content-Type': 'application/json',
45
- Accept: 'application/graphql-response+json, application/json',
46
- ...headers,
47
- },
48
- body: JSON.stringify({
49
- query: documentToString(document),
50
- ...(variables !== undefined && { variables }),
51
- }),
52
- signal: combinedSignal,
53
- });
54
- clearTimeout(timeoutId);
55
- if (!response.ok) {
56
- throw await handleHttpError(response);
57
- }
58
- const result = await response.json();
59
- if (result.errors?.length) {
60
- throw (0, error_1.parseGraphQLError)(result.errors[0]);
61
- }
62
- return result.data;
63
- }
64
- catch (error) {
65
- clearTimeout(timeoutId);
66
- if (error instanceof Error && error.name === 'AbortError') {
67
- throw error_1.createError.timeout();
68
- }
69
- if (error instanceof Error && error.message.includes('fetch')) {
70
- throw error_1.createError.network(error);
71
- }
72
- throw (0, error_1.parseGraphQLError)(error);
73
- }
74
- }
75
- async function handleHttpError(response) {
76
- const { status, statusText } = response;
77
- if (status === 401) {
78
- return error_1.createError.unauthorized('Authentication required');
79
- }
80
- if (status === 403) {
81
- return error_1.createError.forbidden('Access forbidden');
82
- }
83
- if (status === 404) {
84
- return error_1.createError.notFound('GraphQL endpoint not found');
85
- }
86
- // Try to extract error from response body
87
- try {
88
- const body = await response.json();
89
- if (body.errors?.length) {
90
- return (0, error_1.parseGraphQLError)(body.errors[0]);
91
- }
92
- if (body.message) {
93
- return error_1.createError.badRequest(body.message);
94
- }
95
- }
96
- catch {
97
- // Couldn't parse response
98
- }
99
- return error_1.createError.badRequest(`Request failed: ${status} ${statusText}`);
100
- }
3
+ exports.createGraphQLClient = exports.execute = void 0;
101
4
  /**
102
- * Create a GraphQL client instance
5
+ * Re-export GraphQL execution utilities from @constructive-io/graphql-query.
103
6
  */
104
- function createGraphQLClient(options) {
105
- const { endpoint, headers: defaultHeaders = {}, timeout: defaultTimeout = 30000, } = options;
106
- return {
107
- /**
108
- * Execute a GraphQL operation
109
- */
110
- async execute(document, variables, options = {}) {
111
- return execute(endpoint, document, variables, {
112
- headers: { ...defaultHeaders, ...options.headers },
113
- timeout: options.timeout ?? defaultTimeout,
114
- signal: options.signal,
115
- });
116
- },
117
- /**
118
- * Get the endpoint URL
119
- */
120
- getEndpoint() {
121
- return endpoint;
122
- },
123
- };
124
- }
7
+ var graphql_query_1 = require("@constructive-io/graphql-query");
8
+ Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return graphql_query_1.execute; } });
9
+ Object.defineProperty(exports, "createGraphQLClient", { enumerable: true, get: function () { return graphql_query_1.createGraphQLClient; } });
@@ -1,31 +1,4 @@
1
1
  /**
2
- * TypedDocumentString - Type-safe wrapper for GraphQL documents
3
- * Compatible with GraphQL codegen client preset
2
+ * Re-export TypedDocumentString from @constructive-io/graphql-query.
4
3
  */
5
- /**
6
- * Document type decoration interface (from @graphql-typed-document-node/core)
7
- */
8
- export interface DocumentTypeDecoration<TResult, TVariables> {
9
- /**
10
- * This type is used to ensure that the variables you pass in to the query are assignable to Variables
11
- * and that the Result is assignable to whatever you pass your result to.
12
- */
13
- __apiType?: (variables: TVariables) => TResult;
14
- }
15
- /**
16
- * Enhanced TypedDocumentString with type inference capabilities
17
- * Compatible with GraphQL codegen client preset
18
- */
19
- export declare class TypedDocumentString<TResult = unknown, TVariables = unknown> extends String implements DocumentTypeDecoration<TResult, TVariables> {
20
- /** Same shape as the codegen implementation for structural typing */
21
- __apiType?: (variables: TVariables) => TResult;
22
- __meta__?: Record<string, unknown>;
23
- private value;
24
- constructor(value: string, meta?: Record<string, unknown>);
25
- private generateHash;
26
- toString(): string;
27
- /**
28
- * Get the hash for caching purposes
29
- */
30
- getHash(): string;
31
- }
4
+ export { TypedDocumentString, type DocumentTypeDecoration, } from '@constructive-io/graphql-query';
@@ -1,44 +1,8 @@
1
1
  "use strict";
2
- /**
3
- * TypedDocumentString - Type-safe wrapper for GraphQL documents
4
- * Compatible with GraphQL codegen client preset
5
- */
6
2
  Object.defineProperty(exports, "__esModule", { value: true });
7
3
  exports.TypedDocumentString = void 0;
8
4
  /**
9
- * Enhanced TypedDocumentString with type inference capabilities
10
- * Compatible with GraphQL codegen client preset
5
+ * Re-export TypedDocumentString from @constructive-io/graphql-query.
11
6
  */
12
- class TypedDocumentString extends String {
13
- /** Same shape as the codegen implementation for structural typing */
14
- __apiType;
15
- __meta__;
16
- value;
17
- constructor(value, meta) {
18
- super(value);
19
- this.value = value;
20
- this.__meta__ = {
21
- hash: this.generateHash(value),
22
- ...meta,
23
- };
24
- }
25
- generateHash(value) {
26
- let hash = 0;
27
- for (let i = 0; i < value.length; i++) {
28
- const char = value.charCodeAt(i);
29
- hash = (hash << 5) - hash + char;
30
- hash = hash & hash; // Convert to 32-bit integer
31
- }
32
- return Math.abs(hash).toString(36);
33
- }
34
- toString() {
35
- return this.value;
36
- }
37
- /**
38
- * Get the hash for caching purposes
39
- */
40
- getHash() {
41
- return this.__meta__?.hash;
42
- }
43
- }
44
- exports.TypedDocumentString = TypedDocumentString;
7
+ var graphql_query_1 = require("@constructive-io/graphql-query");
8
+ Object.defineProperty(exports, "TypedDocumentString", { enumerable: true, get: function () { return graphql_query_1.TypedDocumentString; } });
package/core/ast.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { DocumentNode, FieldNode } from 'graphql';
2
- import type { ASTFunctionParams, MutationASTParams, QueryFieldSelection } from './types';
3
- export declare const getAll: ({ queryName, operationName, selection, }: ASTFunctionParams) => DocumentNode;
4
- export declare const getCount: ({ queryName, operationName, query, }: Omit<ASTFunctionParams, "selection">) => DocumentNode;
5
- export declare const getMany: ({ builder, queryName, operationName, query, selection, }: ASTFunctionParams) => DocumentNode;
6
- export declare const getOne: ({ queryName, operationName, query, selection, }: ASTFunctionParams) => DocumentNode;
7
- export declare const createOne: ({ mutationName, operationName, mutation, selection, }: MutationASTParams) => DocumentNode;
8
- export declare const patchOne: ({ mutationName, operationName, mutation, selection, }: MutationASTParams) => DocumentNode;
9
- export declare const deleteOne: ({ mutationName, operationName, mutation, }: Omit<MutationASTParams, "selection">) => DocumentNode;
10
- export declare function getSelections(selection?: QueryFieldSelection[]): FieldNode[];
1
+ /**
2
+ * Re-export AST builders from @constructive-io/graphql-query.
3
+ *
4
+ * These are the low-level AST generation functions (getAll, getMany, getOne,
5
+ * createOne, patchOne, deleteOne, getSelections). The canonical implementations
6
+ * now live in graphql-query.
7
+ */
8
+ export { getAll, getCount, getMany, getOne, createOne, patchOne, deleteOne, getSelections, } from '@constructive-io/graphql-query';