@constructive-io/graphql-codegen 4.41.0 → 4.41.2
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/core/codegen/cli/docs-generator.js +28 -0
- package/core/codegen/cli/executor-generator.d.ts +2 -6
- package/core/codegen/cli/executor-generator.js +12 -48
- package/core/codegen/cli/index.d.ts +0 -2
- package/core/codegen/cli/index.js +2 -16
- package/core/codegen/cli/utils-generator.d.ts +0 -8
- package/core/codegen/cli/utils-generator.js +0 -14
- package/core/codegen/hooks-docs-generator.js +26 -0
- package/core/codegen/orm/client-generator.d.ts +1 -3
- package/core/codegen/orm/client-generator.js +1 -1
- package/core/codegen/orm/docs-generator.js +55 -1
- package/core/codegen/orm/index.js +1 -1
- package/core/codegen/templates/select-types.ts +1 -1
- package/core/generate.js +2 -19
- package/esm/core/codegen/cli/docs-generator.js +28 -0
- package/esm/core/codegen/cli/executor-generator.d.ts +2 -6
- package/esm/core/codegen/cli/executor-generator.js +12 -48
- package/esm/core/codegen/cli/index.d.ts +0 -2
- package/esm/core/codegen/cli/index.js +3 -17
- package/esm/core/codegen/cli/utils-generator.d.ts +0 -8
- package/esm/core/codegen/cli/utils-generator.js +0 -13
- package/esm/core/codegen/hooks-docs-generator.js +27 -1
- package/esm/core/codegen/orm/client-generator.d.ts +1 -3
- package/esm/core/codegen/orm/client-generator.js +1 -1
- package/esm/core/codegen/orm/docs-generator.js +55 -1
- package/esm/core/codegen/orm/index.js +1 -1
- package/esm/core/generate.js +2 -19
- package/esm/types/config.d.ts +0 -18
- package/package.json +4 -4
- package/types/config.d.ts +0 -18
- package/core/codegen/templates/node-fetch.ts +0 -198
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node HTTP Adapter for Node.js applications
|
|
3
|
-
*
|
|
4
|
-
* Implements the GraphQLAdapter interface using node:http / node:https
|
|
5
|
-
* instead of the Fetch API. This solves two Node.js limitations:
|
|
6
|
-
*
|
|
7
|
-
* 1. DNS: Node.js cannot resolve *.localhost subdomains (ENOTFOUND).
|
|
8
|
-
* Browsers handle this automatically, but Node requires manual resolution.
|
|
9
|
-
*
|
|
10
|
-
* 2. Host header: The Fetch API treats "Host" as a forbidden request header
|
|
11
|
-
* and silently drops it. The Constructive GraphQL server uses Host-header
|
|
12
|
-
* subdomain routing (enableServicesApi), so this header must be preserved.
|
|
13
|
-
*
|
|
14
|
-
* By using node:http.request directly, both issues are bypassed cleanly
|
|
15
|
-
* without any global patching.
|
|
16
|
-
*
|
|
17
|
-
* NOTE: This file is read at codegen time and written to output.
|
|
18
|
-
* Any changes here will affect all generated CLI node adapters.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import http from 'node:http';
|
|
22
|
-
import https from 'node:https';
|
|
23
|
-
|
|
24
|
-
import type {
|
|
25
|
-
GraphQLAdapter,
|
|
26
|
-
GraphQLError,
|
|
27
|
-
QueryResult,
|
|
28
|
-
} from '@constructive-io/graphql-types';
|
|
29
|
-
|
|
30
|
-
interface HttpResponse {
|
|
31
|
-
statusCode: number;
|
|
32
|
-
statusMessage: string;
|
|
33
|
-
data: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Check if a hostname is a localhost subdomain that needs special handling.
|
|
38
|
-
* Returns true for *.localhost (e.g. auth.localhost) but not bare "localhost".
|
|
39
|
-
*/
|
|
40
|
-
function isLocalhostSubdomain(hostname: string): boolean {
|
|
41
|
-
return hostname.endsWith('.localhost') && hostname !== 'localhost';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Make an HTTP/HTTPS request using native Node modules.
|
|
46
|
-
* Supports optional AbortSignal for request cancellation.
|
|
47
|
-
*/
|
|
48
|
-
function makeRequest(
|
|
49
|
-
url: URL,
|
|
50
|
-
options: http.RequestOptions,
|
|
51
|
-
body: string,
|
|
52
|
-
signal?: AbortSignal,
|
|
53
|
-
): Promise<HttpResponse> {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
if (signal?.aborted) {
|
|
56
|
-
reject(new Error('The operation was aborted'));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const protocol = url.protocol === 'https:' ? https : http;
|
|
61
|
-
|
|
62
|
-
const req = protocol.request(url, options, (res) => {
|
|
63
|
-
let data = '';
|
|
64
|
-
res.setEncoding('utf8');
|
|
65
|
-
res.on('data', (chunk: string) => {
|
|
66
|
-
data += chunk;
|
|
67
|
-
});
|
|
68
|
-
res.on('end', () => {
|
|
69
|
-
resolve({
|
|
70
|
-
statusCode: res.statusCode || 0,
|
|
71
|
-
statusMessage: res.statusMessage || '',
|
|
72
|
-
data,
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
req.on('error', reject);
|
|
78
|
-
|
|
79
|
-
if (signal) {
|
|
80
|
-
const onAbort = () => {
|
|
81
|
-
req.destroy(new Error('The operation was aborted'));
|
|
82
|
-
};
|
|
83
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
84
|
-
req.on('close', () => {
|
|
85
|
-
signal.removeEventListener('abort', onAbort);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
req.write(body);
|
|
90
|
-
req.end();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Options for individual execute calls.
|
|
96
|
-
* Allows per-request header overrides and request cancellation.
|
|
97
|
-
*/
|
|
98
|
-
export interface NodeHttpExecuteOptions {
|
|
99
|
-
/** Additional headers to include in this request only */
|
|
100
|
-
headers?: Record<string, string>;
|
|
101
|
-
/** AbortSignal for request cancellation */
|
|
102
|
-
signal?: AbortSignal;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* GraphQL adapter that uses node:http/node:https for requests.
|
|
107
|
-
*
|
|
108
|
-
* Handles *.localhost subdomains by rewriting the hostname to "localhost"
|
|
109
|
-
* and injecting the original Host header for server-side subdomain routing.
|
|
110
|
-
*/
|
|
111
|
-
export class NodeHttpAdapter implements GraphQLAdapter {
|
|
112
|
-
private headers: Record<string, string>;
|
|
113
|
-
private url: URL;
|
|
114
|
-
|
|
115
|
-
constructor(
|
|
116
|
-
private endpoint: string,
|
|
117
|
-
headers?: Record<string, string>,
|
|
118
|
-
) {
|
|
119
|
-
this.headers = headers ?? {};
|
|
120
|
-
this.url = new URL(endpoint);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async execute<T>(
|
|
124
|
-
document: string,
|
|
125
|
-
variables?: Record<string, unknown>,
|
|
126
|
-
options?: NodeHttpExecuteOptions,
|
|
127
|
-
): Promise<QueryResult<T>> {
|
|
128
|
-
const requestUrl = new URL(this.url.href);
|
|
129
|
-
const requestHeaders: Record<string, string> = {
|
|
130
|
-
'Content-Type': 'application/json',
|
|
131
|
-
Accept: 'application/json',
|
|
132
|
-
...this.headers,
|
|
133
|
-
...options?.headers,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// For *.localhost subdomains, rewrite hostname and inject Host header
|
|
137
|
-
if (isLocalhostSubdomain(requestUrl.hostname)) {
|
|
138
|
-
requestHeaders['Host'] = requestUrl.host;
|
|
139
|
-
requestUrl.hostname = 'localhost';
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const body = JSON.stringify({
|
|
143
|
-
query: document,
|
|
144
|
-
variables: variables ?? {},
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const requestOptions: http.RequestOptions = {
|
|
148
|
-
method: 'POST',
|
|
149
|
-
headers: requestHeaders,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const response = await makeRequest(
|
|
153
|
-
requestUrl,
|
|
154
|
-
requestOptions,
|
|
155
|
-
body,
|
|
156
|
-
options?.signal,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
160
|
-
return {
|
|
161
|
-
ok: false,
|
|
162
|
-
data: null,
|
|
163
|
-
errors: [
|
|
164
|
-
{
|
|
165
|
-
message: `HTTP ${response.statusCode}: ${response.statusMessage}`,
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const json = JSON.parse(response.data) as {
|
|
172
|
-
data?: T;
|
|
173
|
-
errors?: GraphQLError[];
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
if (json.errors && json.errors.length > 0) {
|
|
177
|
-
return {
|
|
178
|
-
ok: false,
|
|
179
|
-
data: null,
|
|
180
|
-
errors: json.errors,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
ok: true,
|
|
186
|
-
data: json.data as T,
|
|
187
|
-
errors: undefined,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
setHeaders(headers: Record<string, string>): void {
|
|
192
|
-
this.headers = { ...this.headers, ...headers };
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
getEndpoint(): string {
|
|
196
|
-
return this.endpoint;
|
|
197
|
-
}
|
|
198
|
-
}
|