@constructive-io/graphql-codegen 4.6.1 → 4.7.1

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 (71) 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 -696
  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 -695
  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 -379
  55. package/esm/generators/mutations.d.ts +5 -28
  56. package/esm/generators/mutations.js +5 -198
  57. package/esm/generators/naming-helpers.d.ts +3 -45
  58. package/esm/generators/naming-helpers.js +3 -151
  59. package/esm/generators/select.d.ts +6 -37
  60. package/esm/generators/select.js +6 -659
  61. package/generators/field-selector.d.ts +5 -28
  62. package/generators/field-selector.js +12 -385
  63. package/generators/mutations.d.ts +5 -28
  64. package/generators/mutations.js +9 -234
  65. package/generators/naming-helpers.d.ts +3 -45
  66. package/generators/naming-helpers.js +15 -164
  67. package/generators/select.d.ts +6 -37
  68. package/generators/select.js +17 -703
  69. package/package.json +10 -9
  70. package/core/meta-object/format.json +0 -93
  71. package/esm/core/meta-object/format.json +0 -93
@@ -1,120 +1,4 @@
1
1
  /**
2
- * GraphQL execution utilities
2
+ * Re-export GraphQL execution utilities from @constructive-io/graphql-query.
3
3
  */
4
- import { print } from 'graphql';
5
- import { createError, parseGraphQLError } from './error';
6
- import { TypedDocumentString } from './typed-document';
7
- // ============================================================================
8
- // Helpers
9
- // ============================================================================
10
- function documentToString(document) {
11
- if (typeof document === 'string')
12
- return document;
13
- if (document instanceof TypedDocumentString)
14
- return document.toString();
15
- // DocumentNode
16
- if (document && typeof document === 'object' && 'kind' in document) {
17
- return print(document);
18
- }
19
- throw createError.badRequest('Invalid GraphQL document');
20
- }
21
- // ============================================================================
22
- // Execute Function
23
- // ============================================================================
24
- /**
25
- * Execute a GraphQL operation against an endpoint
26
- */
27
- export async function execute(endpoint, document, variables, options = {}) {
28
- const { headers = {}, timeout = 30000, signal } = options;
29
- // Create timeout controller
30
- const controller = new AbortController();
31
- const timeoutId = setTimeout(() => controller.abort(), timeout);
32
- // Combine signals if provided
33
- const combinedSignal = signal
34
- ? AbortSignal.any([signal, controller.signal])
35
- : controller.signal;
36
- try {
37
- const response = await fetch(endpoint, {
38
- method: 'POST',
39
- headers: {
40
- 'Content-Type': 'application/json',
41
- Accept: 'application/graphql-response+json, application/json',
42
- ...headers,
43
- },
44
- body: JSON.stringify({
45
- query: documentToString(document),
46
- ...(variables !== undefined && { variables }),
47
- }),
48
- signal: combinedSignal,
49
- });
50
- clearTimeout(timeoutId);
51
- if (!response.ok) {
52
- throw await handleHttpError(response);
53
- }
54
- const result = await response.json();
55
- if (result.errors?.length) {
56
- throw parseGraphQLError(result.errors[0]);
57
- }
58
- return result.data;
59
- }
60
- catch (error) {
61
- clearTimeout(timeoutId);
62
- if (error instanceof Error && error.name === 'AbortError') {
63
- throw createError.timeout();
64
- }
65
- if (error instanceof Error && error.message.includes('fetch')) {
66
- throw createError.network(error);
67
- }
68
- throw parseGraphQLError(error);
69
- }
70
- }
71
- async function handleHttpError(response) {
72
- const { status, statusText } = response;
73
- if (status === 401) {
74
- return createError.unauthorized('Authentication required');
75
- }
76
- if (status === 403) {
77
- return createError.forbidden('Access forbidden');
78
- }
79
- if (status === 404) {
80
- return createError.notFound('GraphQL endpoint not found');
81
- }
82
- // Try to extract error from response body
83
- try {
84
- const body = await response.json();
85
- if (body.errors?.length) {
86
- return parseGraphQLError(body.errors[0]);
87
- }
88
- if (body.message) {
89
- return createError.badRequest(body.message);
90
- }
91
- }
92
- catch {
93
- // Couldn't parse response
94
- }
95
- return createError.badRequest(`Request failed: ${status} ${statusText}`);
96
- }
97
- /**
98
- * Create a GraphQL client instance
99
- */
100
- export function createGraphQLClient(options) {
101
- const { endpoint, headers: defaultHeaders = {}, timeout: defaultTimeout = 30000, } = options;
102
- return {
103
- /**
104
- * Execute a GraphQL operation
105
- */
106
- async execute(document, variables, options = {}) {
107
- return execute(endpoint, document, variables, {
108
- headers: { ...defaultHeaders, ...options.headers },
109
- timeout: options.timeout ?? defaultTimeout,
110
- signal: options.signal,
111
- });
112
- },
113
- /**
114
- * Get the endpoint URL
115
- */
116
- getEndpoint() {
117
- return endpoint;
118
- },
119
- };
120
- }
4
+ export { execute, createGraphQLClient, } from '@constructive-io/graphql-query';
@@ -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,40 +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
- * Enhanced TypedDocumentString with type inference capabilities
7
- * Compatible with GraphQL codegen client preset
8
- */
9
- export class TypedDocumentString extends String {
10
- /** Same shape as the codegen implementation for structural typing */
11
- __apiType;
12
- __meta__;
13
- value;
14
- constructor(value, meta) {
15
- super(value);
16
- this.value = value;
17
- this.__meta__ = {
18
- hash: this.generateHash(value),
19
- ...meta,
20
- };
21
- }
22
- generateHash(value) {
23
- let hash = 0;
24
- for (let i = 0; i < value.length; i++) {
25
- const char = value.charCodeAt(i);
26
- hash = (hash << 5) - hash + char;
27
- hash = hash & hash; // Convert to 32-bit integer
28
- }
29
- return Math.abs(hash).toString(36);
30
- }
31
- toString() {
32
- return this.value;
33
- }
34
- /**
35
- * Get the hash for caching purposes
36
- */
37
- getHash() {
38
- return this.__meta__?.hash;
39
- }
40
- }
4
+ export { TypedDocumentString, } from '@constructive-io/graphql-query';
package/esm/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';