@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.
- package/client/error.d.ts +2 -93
- package/client/error.js +9 -273
- package/client/execute.d.ts +2 -55
- package/client/execute.js +5 -120
- package/client/typed-document.d.ts +2 -29
- package/client/typed-document.js +3 -39
- package/core/ast.d.ts +8 -10
- package/core/ast.js +17 -592
- package/core/custom-ast.d.ts +5 -33
- package/core/custom-ast.js +16 -203
- package/core/introspect/infer-tables.d.ts +2 -40
- package/core/introspect/infer-tables.js +4 -696
- package/core/introspect/schema-query.d.ts +3 -18
- package/core/introspect/schema-query.js +3 -118
- package/core/introspect/transform-schema.d.ts +2 -84
- package/core/introspect/transform-schema.js +14 -279
- package/core/introspect/transform.d.ts +2 -18
- package/core/introspect/transform.js +6 -39
- package/core/meta-object/convert.d.ts +2 -63
- package/core/meta-object/convert.js +4 -59
- package/core/meta-object/validate.d.ts +2 -7
- package/core/meta-object/validate.js +4 -30
- package/core/query-builder.d.ts +7 -46
- package/core/query-builder.js +8 -408
- package/core/types.d.ts +9 -139
- package/core/types.js +12 -26
- package/esm/client/error.d.ts +2 -93
- package/esm/client/error.js +2 -269
- package/esm/client/execute.d.ts +2 -55
- package/esm/client/execute.js +2 -118
- package/esm/client/typed-document.d.ts +2 -29
- package/esm/client/typed-document.js +2 -38
- package/esm/core/ast.d.ts +8 -10
- package/esm/core/ast.js +8 -550
- package/esm/core/custom-ast.d.ts +5 -33
- package/esm/core/custom-ast.js +5 -160
- package/esm/core/introspect/infer-tables.d.ts +2 -40
- package/esm/core/introspect/infer-tables.js +2 -695
- package/esm/core/introspect/schema-query.d.ts +3 -18
- package/esm/core/introspect/schema-query.js +2 -118
- package/esm/core/introspect/transform-schema.d.ts +2 -84
- package/esm/core/introspect/transform-schema.js +2 -269
- package/esm/core/introspect/transform.d.ts +2 -18
- package/esm/core/introspect/transform.js +2 -36
- package/esm/core/meta-object/convert.d.ts +2 -63
- package/esm/core/meta-object/convert.js +2 -58
- package/esm/core/meta-object/validate.d.ts +2 -7
- package/esm/core/meta-object/validate.js +2 -26
- package/esm/core/query-builder.d.ts +7 -46
- package/esm/core/query-builder.js +5 -373
- package/esm/core/types.d.ts +9 -139
- package/esm/core/types.js +9 -24
- package/esm/generators/field-selector.d.ts +5 -28
- package/esm/generators/field-selector.js +5 -379
- package/esm/generators/mutations.d.ts +5 -28
- package/esm/generators/mutations.js +5 -198
- package/esm/generators/naming-helpers.d.ts +3 -45
- package/esm/generators/naming-helpers.js +3 -151
- package/esm/generators/select.d.ts +6 -37
- package/esm/generators/select.js +6 -659
- package/generators/field-selector.d.ts +5 -28
- package/generators/field-selector.js +12 -385
- package/generators/mutations.d.ts +5 -28
- package/generators/mutations.js +9 -234
- package/generators/naming-helpers.d.ts +3 -45
- package/generators/naming-helpers.js +15 -164
- package/generators/select.d.ts +6 -37
- package/generators/select.js +17 -703
- package/package.json +10 -9
- package/core/meta-object/format.json +0 -93
- package/esm/core/meta-object/format.json +0 -93
package/esm/client/execute.js
CHANGED
|
@@ -1,120 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GraphQL execution utilities
|
|
2
|
+
* Re-export GraphQL execution utilities from @constructive-io/graphql-query.
|
|
3
3
|
*/
|
|
4
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
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';
|