@constructive-io/sdk 0.14.11 → 0.15.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.
- package/admin/orm/client.d.ts +18 -6
- package/admin/orm/client.js +14 -5
- package/admin/orm/query-builder.js +10 -10
- package/auth/orm/client.d.ts +18 -6
- package/auth/orm/client.js +14 -5
- package/auth/orm/query-builder.js +10 -10
- package/esm/admin/orm/client.d.ts +18 -6
- package/esm/admin/orm/client.js +14 -5
- package/esm/admin/orm/query-builder.js +1 -1
- package/esm/auth/orm/client.d.ts +18 -6
- package/esm/auth/orm/client.js +14 -5
- package/esm/auth/orm/query-builder.js +1 -1
- package/esm/objects/orm/client.d.ts +18 -6
- package/esm/objects/orm/client.js +14 -5
- package/esm/objects/orm/query-builder.js +1 -1
- package/esm/public/orm/client.d.ts +18 -6
- package/esm/public/orm/client.js +14 -5
- package/esm/public/orm/query-builder.js +1 -1
- package/objects/orm/client.d.ts +18 -6
- package/objects/orm/client.js +14 -5
- package/objects/orm/query-builder.js +10 -10
- package/package.json +4 -3
- package/public/orm/client.d.ts +18 -6
- package/public/orm/client.js +14 -5
- package/public/orm/query-builder.js +10 -10
package/admin/orm/client.d.ts
CHANGED
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/admin/orm/client.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrmClient = exports.GraphQLRequestError = exports.FetchAdapter = void 0;
|
|
4
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
4
5
|
/**
|
|
5
6
|
* Default adapter that uses fetch for HTTP requests.
|
|
6
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
9
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
10
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
11
|
+
* proxy/credentials.
|
|
7
12
|
*/
|
|
8
13
|
class FetchAdapter {
|
|
9
14
|
endpoint;
|
|
10
15
|
headers;
|
|
11
|
-
|
|
16
|
+
fetchFn;
|
|
17
|
+
constructor(endpoint, headers, fetchFn) {
|
|
12
18
|
this.endpoint = endpoint;
|
|
13
19
|
this.headers = headers ?? {};
|
|
20
|
+
this.fetchFn = fetchFn ?? (0, runtime_1.createFetch)();
|
|
14
21
|
}
|
|
15
22
|
async execute(document, variables) {
|
|
16
|
-
const response = await
|
|
23
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
17
24
|
method: 'POST',
|
|
18
25
|
headers: {
|
|
19
26
|
'Content-Type': 'application/json',
|
|
@@ -29,7 +36,9 @@ class FetchAdapter {
|
|
|
29
36
|
return {
|
|
30
37
|
ok: false,
|
|
31
38
|
data: null,
|
|
32
|
-
errors: [
|
|
39
|
+
errors: [
|
|
40
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
41
|
+
],
|
|
33
42
|
};
|
|
34
43
|
}
|
|
35
44
|
const json = (await response.json());
|
|
@@ -76,7 +85,7 @@ class OrmClient {
|
|
|
76
85
|
this.adapter = config.adapter;
|
|
77
86
|
}
|
|
78
87
|
else if (config.endpoint) {
|
|
79
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
88
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
80
89
|
}
|
|
81
90
|
else {
|
|
82
91
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -50,7 +50,7 @@ exports.buildCustomDocument = buildCustomDocument;
|
|
|
50
50
|
* @generated by @constructive-io/graphql-codegen
|
|
51
51
|
* DO NOT EDIT - changes will be overwritten
|
|
52
52
|
*/
|
|
53
|
-
const
|
|
53
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
54
54
|
const t = __importStar(require("gql-ast"));
|
|
55
55
|
const client_1 = require("./client");
|
|
56
56
|
class QueryBuilder {
|
|
@@ -221,7 +221,7 @@ function buildFindManyDocument(operationName, queryField, select, args, filterTy
|
|
|
221
221
|
}),
|
|
222
222
|
],
|
|
223
223
|
});
|
|
224
|
-
return { document: (0,
|
|
224
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
225
225
|
}
|
|
226
226
|
function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName, connectionFieldsMap) {
|
|
227
227
|
const selections = select
|
|
@@ -262,7 +262,7 @@ function buildFindFirstDocument(operationName, queryField, select, args, filterT
|
|
|
262
262
|
}),
|
|
263
263
|
],
|
|
264
264
|
});
|
|
265
|
-
return { document: (0,
|
|
265
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
266
266
|
}
|
|
267
267
|
function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName, connectionFieldsMap) {
|
|
268
268
|
const selections = select
|
|
@@ -342,7 +342,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
342
342
|
const variableDefinitions = [
|
|
343
343
|
t.variableDefinition({
|
|
344
344
|
variable: t.variable({ name: idArgName }),
|
|
345
|
-
type: (0,
|
|
345
|
+
type: (0, runtime_1.parseType)(idTypeName),
|
|
346
346
|
}),
|
|
347
347
|
];
|
|
348
348
|
const queryArgs = [
|
|
@@ -370,7 +370,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
370
370
|
],
|
|
371
371
|
});
|
|
372
372
|
return {
|
|
373
|
-
document: (0,
|
|
373
|
+
document: (0, runtime_1.print)(document),
|
|
374
374
|
variables: { [idArgName]: id },
|
|
375
375
|
};
|
|
376
376
|
}
|
|
@@ -445,7 +445,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
445
445
|
: [];
|
|
446
446
|
const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
|
|
447
447
|
variable: t.variable({ name: definition.name }),
|
|
448
|
-
type: (0,
|
|
448
|
+
type: (0, runtime_1.parseType)(definition.type),
|
|
449
449
|
}));
|
|
450
450
|
const fieldArgs = variableDefinitions.map((definition) => t.argument({
|
|
451
451
|
name: definition.name,
|
|
@@ -473,7 +473,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
473
473
|
],
|
|
474
474
|
});
|
|
475
475
|
return {
|
|
476
|
-
document: (0,
|
|
476
|
+
document: (0, runtime_1.print)(document),
|
|
477
477
|
variables: (args ?? {}),
|
|
478
478
|
};
|
|
479
479
|
}
|
|
@@ -551,7 +551,7 @@ function buildInputMutationDocument(config) {
|
|
|
551
551
|
variableDefinitions: [
|
|
552
552
|
t.variableDefinition({
|
|
553
553
|
variable: t.variable({ name: 'input' }),
|
|
554
|
-
type: (0,
|
|
554
|
+
type: (0, runtime_1.parseType)(config.inputTypeName + '!'),
|
|
555
555
|
}),
|
|
556
556
|
],
|
|
557
557
|
selectionSet: t.selectionSet({
|
|
@@ -573,14 +573,14 @@ function buildInputMutationDocument(config) {
|
|
|
573
573
|
}),
|
|
574
574
|
],
|
|
575
575
|
});
|
|
576
|
-
return (0,
|
|
576
|
+
return (0, runtime_1.print)(document);
|
|
577
577
|
}
|
|
578
578
|
function addVariable(spec, definitions, args, variables) {
|
|
579
579
|
if (spec.value === undefined || !spec.typeName)
|
|
580
580
|
return;
|
|
581
581
|
definitions.push(t.variableDefinition({
|
|
582
582
|
variable: t.variable({ name: spec.varName }),
|
|
583
|
-
type: (0,
|
|
583
|
+
type: (0, runtime_1.parseType)(spec.typeName),
|
|
584
584
|
}));
|
|
585
585
|
args.push(t.argument({
|
|
586
586
|
name: spec.argName ?? spec.varName,
|
package/auth/orm/client.d.ts
CHANGED
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/auth/orm/client.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrmClient = exports.GraphQLRequestError = exports.FetchAdapter = void 0;
|
|
4
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
4
5
|
/**
|
|
5
6
|
* Default adapter that uses fetch for HTTP requests.
|
|
6
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
9
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
10
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
11
|
+
* proxy/credentials.
|
|
7
12
|
*/
|
|
8
13
|
class FetchAdapter {
|
|
9
14
|
endpoint;
|
|
10
15
|
headers;
|
|
11
|
-
|
|
16
|
+
fetchFn;
|
|
17
|
+
constructor(endpoint, headers, fetchFn) {
|
|
12
18
|
this.endpoint = endpoint;
|
|
13
19
|
this.headers = headers ?? {};
|
|
20
|
+
this.fetchFn = fetchFn ?? (0, runtime_1.createFetch)();
|
|
14
21
|
}
|
|
15
22
|
async execute(document, variables) {
|
|
16
|
-
const response = await
|
|
23
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
17
24
|
method: 'POST',
|
|
18
25
|
headers: {
|
|
19
26
|
'Content-Type': 'application/json',
|
|
@@ -29,7 +36,9 @@ class FetchAdapter {
|
|
|
29
36
|
return {
|
|
30
37
|
ok: false,
|
|
31
38
|
data: null,
|
|
32
|
-
errors: [
|
|
39
|
+
errors: [
|
|
40
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
41
|
+
],
|
|
33
42
|
};
|
|
34
43
|
}
|
|
35
44
|
const json = (await response.json());
|
|
@@ -76,7 +85,7 @@ class OrmClient {
|
|
|
76
85
|
this.adapter = config.adapter;
|
|
77
86
|
}
|
|
78
87
|
else if (config.endpoint) {
|
|
79
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
88
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
80
89
|
}
|
|
81
90
|
else {
|
|
82
91
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -50,7 +50,7 @@ exports.buildCustomDocument = buildCustomDocument;
|
|
|
50
50
|
* @generated by @constructive-io/graphql-codegen
|
|
51
51
|
* DO NOT EDIT - changes will be overwritten
|
|
52
52
|
*/
|
|
53
|
-
const
|
|
53
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
54
54
|
const t = __importStar(require("gql-ast"));
|
|
55
55
|
const client_1 = require("./client");
|
|
56
56
|
class QueryBuilder {
|
|
@@ -221,7 +221,7 @@ function buildFindManyDocument(operationName, queryField, select, args, filterTy
|
|
|
221
221
|
}),
|
|
222
222
|
],
|
|
223
223
|
});
|
|
224
|
-
return { document: (0,
|
|
224
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
225
225
|
}
|
|
226
226
|
function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName, connectionFieldsMap) {
|
|
227
227
|
const selections = select
|
|
@@ -262,7 +262,7 @@ function buildFindFirstDocument(operationName, queryField, select, args, filterT
|
|
|
262
262
|
}),
|
|
263
263
|
],
|
|
264
264
|
});
|
|
265
|
-
return { document: (0,
|
|
265
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
266
266
|
}
|
|
267
267
|
function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName, connectionFieldsMap) {
|
|
268
268
|
const selections = select
|
|
@@ -342,7 +342,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
342
342
|
const variableDefinitions = [
|
|
343
343
|
t.variableDefinition({
|
|
344
344
|
variable: t.variable({ name: idArgName }),
|
|
345
|
-
type: (0,
|
|
345
|
+
type: (0, runtime_1.parseType)(idTypeName),
|
|
346
346
|
}),
|
|
347
347
|
];
|
|
348
348
|
const queryArgs = [
|
|
@@ -370,7 +370,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
370
370
|
],
|
|
371
371
|
});
|
|
372
372
|
return {
|
|
373
|
-
document: (0,
|
|
373
|
+
document: (0, runtime_1.print)(document),
|
|
374
374
|
variables: { [idArgName]: id },
|
|
375
375
|
};
|
|
376
376
|
}
|
|
@@ -445,7 +445,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
445
445
|
: [];
|
|
446
446
|
const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
|
|
447
447
|
variable: t.variable({ name: definition.name }),
|
|
448
|
-
type: (0,
|
|
448
|
+
type: (0, runtime_1.parseType)(definition.type),
|
|
449
449
|
}));
|
|
450
450
|
const fieldArgs = variableDefinitions.map((definition) => t.argument({
|
|
451
451
|
name: definition.name,
|
|
@@ -473,7 +473,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
473
473
|
],
|
|
474
474
|
});
|
|
475
475
|
return {
|
|
476
|
-
document: (0,
|
|
476
|
+
document: (0, runtime_1.print)(document),
|
|
477
477
|
variables: (args ?? {}),
|
|
478
478
|
};
|
|
479
479
|
}
|
|
@@ -551,7 +551,7 @@ function buildInputMutationDocument(config) {
|
|
|
551
551
|
variableDefinitions: [
|
|
552
552
|
t.variableDefinition({
|
|
553
553
|
variable: t.variable({ name: 'input' }),
|
|
554
|
-
type: (0,
|
|
554
|
+
type: (0, runtime_1.parseType)(config.inputTypeName + '!'),
|
|
555
555
|
}),
|
|
556
556
|
],
|
|
557
557
|
selectionSet: t.selectionSet({
|
|
@@ -573,14 +573,14 @@ function buildInputMutationDocument(config) {
|
|
|
573
573
|
}),
|
|
574
574
|
],
|
|
575
575
|
});
|
|
576
|
-
return (0,
|
|
576
|
+
return (0, runtime_1.print)(document);
|
|
577
577
|
}
|
|
578
578
|
function addVariable(spec, definitions, args, variables) {
|
|
579
579
|
if (spec.value === undefined || !spec.typeName)
|
|
580
580
|
return;
|
|
581
581
|
definitions.push(t.variableDefinition({
|
|
582
582
|
variable: t.variable({ name: spec.varName }),
|
|
583
|
-
type: (0,
|
|
583
|
+
type: (0, runtime_1.parseType)(spec.typeName),
|
|
584
584
|
}));
|
|
585
585
|
args.push(t.argument({
|
|
586
586
|
name: spec.argName ?? spec.varName,
|
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/esm/admin/orm/client.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { createFetch } from '@constructive-io/graphql-query/runtime';
|
|
1
2
|
/**
|
|
2
3
|
* Default adapter that uses fetch for HTTP requests.
|
|
3
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
6
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
7
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
8
|
+
* proxy/credentials.
|
|
4
9
|
*/
|
|
5
10
|
export class FetchAdapter {
|
|
6
11
|
endpoint;
|
|
7
12
|
headers;
|
|
8
|
-
|
|
13
|
+
fetchFn;
|
|
14
|
+
constructor(endpoint, headers, fetchFn) {
|
|
9
15
|
this.endpoint = endpoint;
|
|
10
16
|
this.headers = headers ?? {};
|
|
17
|
+
this.fetchFn = fetchFn ?? createFetch();
|
|
11
18
|
}
|
|
12
19
|
async execute(document, variables) {
|
|
13
|
-
const response = await
|
|
20
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
14
21
|
method: 'POST',
|
|
15
22
|
headers: {
|
|
16
23
|
'Content-Type': 'application/json',
|
|
@@ -26,7 +33,9 @@ export class FetchAdapter {
|
|
|
26
33
|
return {
|
|
27
34
|
ok: false,
|
|
28
35
|
data: null,
|
|
29
|
-
errors: [
|
|
36
|
+
errors: [
|
|
37
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
38
|
+
],
|
|
30
39
|
};
|
|
31
40
|
}
|
|
32
41
|
const json = (await response.json());
|
|
@@ -71,7 +80,7 @@ export class OrmClient {
|
|
|
71
80
|
this.adapter = config.adapter;
|
|
72
81
|
}
|
|
73
82
|
else if (config.endpoint) {
|
|
74
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
83
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
75
84
|
}
|
|
76
85
|
else {
|
|
77
86
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import { parseType, print } from '@
|
|
6
|
+
import { parseType, print } from '@constructive-io/graphql-query/runtime';
|
|
7
7
|
import * as t from 'gql-ast';
|
|
8
8
|
import { GraphQLRequestError } from './client';
|
|
9
9
|
export class QueryBuilder {
|
package/esm/auth/orm/client.d.ts
CHANGED
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/esm/auth/orm/client.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { createFetch } from '@constructive-io/graphql-query/runtime';
|
|
1
2
|
/**
|
|
2
3
|
* Default adapter that uses fetch for HTTP requests.
|
|
3
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
6
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
7
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
8
|
+
* proxy/credentials.
|
|
4
9
|
*/
|
|
5
10
|
export class FetchAdapter {
|
|
6
11
|
endpoint;
|
|
7
12
|
headers;
|
|
8
|
-
|
|
13
|
+
fetchFn;
|
|
14
|
+
constructor(endpoint, headers, fetchFn) {
|
|
9
15
|
this.endpoint = endpoint;
|
|
10
16
|
this.headers = headers ?? {};
|
|
17
|
+
this.fetchFn = fetchFn ?? createFetch();
|
|
11
18
|
}
|
|
12
19
|
async execute(document, variables) {
|
|
13
|
-
const response = await
|
|
20
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
14
21
|
method: 'POST',
|
|
15
22
|
headers: {
|
|
16
23
|
'Content-Type': 'application/json',
|
|
@@ -26,7 +33,9 @@ export class FetchAdapter {
|
|
|
26
33
|
return {
|
|
27
34
|
ok: false,
|
|
28
35
|
data: null,
|
|
29
|
-
errors: [
|
|
36
|
+
errors: [
|
|
37
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
38
|
+
],
|
|
30
39
|
};
|
|
31
40
|
}
|
|
32
41
|
const json = (await response.json());
|
|
@@ -71,7 +80,7 @@ export class OrmClient {
|
|
|
71
80
|
this.adapter = config.adapter;
|
|
72
81
|
}
|
|
73
82
|
else if (config.endpoint) {
|
|
74
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
83
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
75
84
|
}
|
|
76
85
|
else {
|
|
77
86
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import { parseType, print } from '@
|
|
6
|
+
import { parseType, print } from '@constructive-io/graphql-query/runtime';
|
|
7
7
|
import * as t from 'gql-ast';
|
|
8
8
|
import { GraphQLRequestError } from './client';
|
|
9
9
|
export class QueryBuilder {
|
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { createFetch } from '@constructive-io/graphql-query/runtime';
|
|
1
2
|
/**
|
|
2
3
|
* Default adapter that uses fetch for HTTP requests.
|
|
3
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
6
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
7
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
8
|
+
* proxy/credentials.
|
|
4
9
|
*/
|
|
5
10
|
export class FetchAdapter {
|
|
6
11
|
endpoint;
|
|
7
12
|
headers;
|
|
8
|
-
|
|
13
|
+
fetchFn;
|
|
14
|
+
constructor(endpoint, headers, fetchFn) {
|
|
9
15
|
this.endpoint = endpoint;
|
|
10
16
|
this.headers = headers ?? {};
|
|
17
|
+
this.fetchFn = fetchFn ?? createFetch();
|
|
11
18
|
}
|
|
12
19
|
async execute(document, variables) {
|
|
13
|
-
const response = await
|
|
20
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
14
21
|
method: 'POST',
|
|
15
22
|
headers: {
|
|
16
23
|
'Content-Type': 'application/json',
|
|
@@ -26,7 +33,9 @@ export class FetchAdapter {
|
|
|
26
33
|
return {
|
|
27
34
|
ok: false,
|
|
28
35
|
data: null,
|
|
29
|
-
errors: [
|
|
36
|
+
errors: [
|
|
37
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
38
|
+
],
|
|
30
39
|
};
|
|
31
40
|
}
|
|
32
41
|
const json = (await response.json());
|
|
@@ -71,7 +80,7 @@ export class OrmClient {
|
|
|
71
80
|
this.adapter = config.adapter;
|
|
72
81
|
}
|
|
73
82
|
else if (config.endpoint) {
|
|
74
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
83
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
75
84
|
}
|
|
76
85
|
else {
|
|
77
86
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import { parseType, print } from '@
|
|
6
|
+
import { parseType, print } from '@constructive-io/graphql-query/runtime';
|
|
7
7
|
import * as t from 'gql-ast';
|
|
8
8
|
import { GraphQLRequestError } from './client';
|
|
9
9
|
export class QueryBuilder {
|
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/esm/public/orm/client.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { createFetch } from '@constructive-io/graphql-query/runtime';
|
|
1
2
|
/**
|
|
2
3
|
* Default adapter that uses fetch for HTTP requests.
|
|
3
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
6
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
7
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
8
|
+
* proxy/credentials.
|
|
4
9
|
*/
|
|
5
10
|
export class FetchAdapter {
|
|
6
11
|
endpoint;
|
|
7
12
|
headers;
|
|
8
|
-
|
|
13
|
+
fetchFn;
|
|
14
|
+
constructor(endpoint, headers, fetchFn) {
|
|
9
15
|
this.endpoint = endpoint;
|
|
10
16
|
this.headers = headers ?? {};
|
|
17
|
+
this.fetchFn = fetchFn ?? createFetch();
|
|
11
18
|
}
|
|
12
19
|
async execute(document, variables) {
|
|
13
|
-
const response = await
|
|
20
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
14
21
|
method: 'POST',
|
|
15
22
|
headers: {
|
|
16
23
|
'Content-Type': 'application/json',
|
|
@@ -26,7 +33,9 @@ export class FetchAdapter {
|
|
|
26
33
|
return {
|
|
27
34
|
ok: false,
|
|
28
35
|
data: null,
|
|
29
|
-
errors: [
|
|
36
|
+
errors: [
|
|
37
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
38
|
+
],
|
|
30
39
|
};
|
|
31
40
|
}
|
|
32
41
|
const json = (await response.json());
|
|
@@ -71,7 +80,7 @@ export class OrmClient {
|
|
|
71
80
|
this.adapter = config.adapter;
|
|
72
81
|
}
|
|
73
82
|
else if (config.endpoint) {
|
|
74
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
83
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
75
84
|
}
|
|
76
85
|
else {
|
|
77
86
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import { parseType, print } from '@
|
|
6
|
+
import { parseType, print } from '@constructive-io/graphql-query/runtime';
|
|
7
7
|
import * as t from 'gql-ast';
|
|
8
8
|
import { GraphQLRequestError } from './client';
|
|
9
9
|
export class QueryBuilder {
|
package/objects/orm/client.d.ts
CHANGED
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/objects/orm/client.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrmClient = exports.GraphQLRequestError = exports.FetchAdapter = void 0;
|
|
4
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
4
5
|
/**
|
|
5
6
|
* Default adapter that uses fetch for HTTP requests.
|
|
6
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
9
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
10
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
11
|
+
* proxy/credentials.
|
|
7
12
|
*/
|
|
8
13
|
class FetchAdapter {
|
|
9
14
|
endpoint;
|
|
10
15
|
headers;
|
|
11
|
-
|
|
16
|
+
fetchFn;
|
|
17
|
+
constructor(endpoint, headers, fetchFn) {
|
|
12
18
|
this.endpoint = endpoint;
|
|
13
19
|
this.headers = headers ?? {};
|
|
20
|
+
this.fetchFn = fetchFn ?? (0, runtime_1.createFetch)();
|
|
14
21
|
}
|
|
15
22
|
async execute(document, variables) {
|
|
16
|
-
const response = await
|
|
23
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
17
24
|
method: 'POST',
|
|
18
25
|
headers: {
|
|
19
26
|
'Content-Type': 'application/json',
|
|
@@ -29,7 +36,9 @@ class FetchAdapter {
|
|
|
29
36
|
return {
|
|
30
37
|
ok: false,
|
|
31
38
|
data: null,
|
|
32
|
-
errors: [
|
|
39
|
+
errors: [
|
|
40
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
41
|
+
],
|
|
33
42
|
};
|
|
34
43
|
}
|
|
35
44
|
const json = (await response.json());
|
|
@@ -76,7 +85,7 @@ class OrmClient {
|
|
|
76
85
|
this.adapter = config.adapter;
|
|
77
86
|
}
|
|
78
87
|
else if (config.endpoint) {
|
|
79
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
88
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
80
89
|
}
|
|
81
90
|
else {
|
|
82
91
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -50,7 +50,7 @@ exports.buildCustomDocument = buildCustomDocument;
|
|
|
50
50
|
* @generated by @constructive-io/graphql-codegen
|
|
51
51
|
* DO NOT EDIT - changes will be overwritten
|
|
52
52
|
*/
|
|
53
|
-
const
|
|
53
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
54
54
|
const t = __importStar(require("gql-ast"));
|
|
55
55
|
const client_1 = require("./client");
|
|
56
56
|
class QueryBuilder {
|
|
@@ -221,7 +221,7 @@ function buildFindManyDocument(operationName, queryField, select, args, filterTy
|
|
|
221
221
|
}),
|
|
222
222
|
],
|
|
223
223
|
});
|
|
224
|
-
return { document: (0,
|
|
224
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
225
225
|
}
|
|
226
226
|
function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName, connectionFieldsMap) {
|
|
227
227
|
const selections = select
|
|
@@ -262,7 +262,7 @@ function buildFindFirstDocument(operationName, queryField, select, args, filterT
|
|
|
262
262
|
}),
|
|
263
263
|
],
|
|
264
264
|
});
|
|
265
|
-
return { document: (0,
|
|
265
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
266
266
|
}
|
|
267
267
|
function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName, connectionFieldsMap) {
|
|
268
268
|
const selections = select
|
|
@@ -342,7 +342,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
342
342
|
const variableDefinitions = [
|
|
343
343
|
t.variableDefinition({
|
|
344
344
|
variable: t.variable({ name: idArgName }),
|
|
345
|
-
type: (0,
|
|
345
|
+
type: (0, runtime_1.parseType)(idTypeName),
|
|
346
346
|
}),
|
|
347
347
|
];
|
|
348
348
|
const queryArgs = [
|
|
@@ -370,7 +370,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
370
370
|
],
|
|
371
371
|
});
|
|
372
372
|
return {
|
|
373
|
-
document: (0,
|
|
373
|
+
document: (0, runtime_1.print)(document),
|
|
374
374
|
variables: { [idArgName]: id },
|
|
375
375
|
};
|
|
376
376
|
}
|
|
@@ -445,7 +445,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
445
445
|
: [];
|
|
446
446
|
const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
|
|
447
447
|
variable: t.variable({ name: definition.name }),
|
|
448
|
-
type: (0,
|
|
448
|
+
type: (0, runtime_1.parseType)(definition.type),
|
|
449
449
|
}));
|
|
450
450
|
const fieldArgs = variableDefinitions.map((definition) => t.argument({
|
|
451
451
|
name: definition.name,
|
|
@@ -473,7 +473,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
473
473
|
],
|
|
474
474
|
});
|
|
475
475
|
return {
|
|
476
|
-
document: (0,
|
|
476
|
+
document: (0, runtime_1.print)(document),
|
|
477
477
|
variables: (args ?? {}),
|
|
478
478
|
};
|
|
479
479
|
}
|
|
@@ -551,7 +551,7 @@ function buildInputMutationDocument(config) {
|
|
|
551
551
|
variableDefinitions: [
|
|
552
552
|
t.variableDefinition({
|
|
553
553
|
variable: t.variable({ name: 'input' }),
|
|
554
|
-
type: (0,
|
|
554
|
+
type: (0, runtime_1.parseType)(config.inputTypeName + '!'),
|
|
555
555
|
}),
|
|
556
556
|
],
|
|
557
557
|
selectionSet: t.selectionSet({
|
|
@@ -573,14 +573,14 @@ function buildInputMutationDocument(config) {
|
|
|
573
573
|
}),
|
|
574
574
|
],
|
|
575
575
|
});
|
|
576
|
-
return (0,
|
|
576
|
+
return (0, runtime_1.print)(document);
|
|
577
577
|
}
|
|
578
578
|
function addVariable(spec, definitions, args, variables) {
|
|
579
579
|
if (spec.value === undefined || !spec.typeName)
|
|
580
580
|
return;
|
|
581
581
|
definitions.push(t.variableDefinition({
|
|
582
582
|
variable: t.variable({ name: spec.varName }),
|
|
583
|
-
type: (0,
|
|
583
|
+
type: (0, runtime_1.parseType)(spec.typeName),
|
|
584
584
|
}));
|
|
585
585
|
args.push(t.argument({
|
|
586
586
|
name: spec.argName ?? spec.varName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive SDK - Auto-generated GraphQL types and ORM client",
|
|
6
6
|
"main": "index.js",
|
|
@@ -42,16 +42,17 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@0no-co/graphql.web": "^1.1.2",
|
|
45
|
+
"@constructive-io/graphql-query": "^3.15.2",
|
|
45
46
|
"@constructive-io/graphql-types": "^3.5.1",
|
|
46
47
|
"gql-ast": "^3.5.0",
|
|
47
48
|
"graphql": "16.13.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@constructive-io/graphql-codegen": "^4.
|
|
51
|
+
"@constructive-io/graphql-codegen": "^4.32.0",
|
|
51
52
|
"@types/node": "^22.19.11",
|
|
52
53
|
"makage": "^0.3.0",
|
|
53
54
|
"tsx": "^4.19.0",
|
|
54
55
|
"typescript": "^5.9.3"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a8ccaed4f3a7c6c82495241ee1581700db9dd2dd"
|
|
57
58
|
}
|
package/public/orm/client.d.ts
CHANGED
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
-
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
7
|
-
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-
|
|
6
|
+
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
|
|
7
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
|
|
8
8
|
/**
|
|
9
9
|
* Default adapter that uses fetch for HTTP requests.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
12
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
13
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
14
|
+
* proxy/credentials.
|
|
11
15
|
*/
|
|
12
16
|
export declare class FetchAdapter implements GraphQLAdapter {
|
|
13
17
|
private endpoint;
|
|
14
18
|
private headers;
|
|
15
|
-
|
|
19
|
+
private fetchFn;
|
|
20
|
+
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
|
|
16
21
|
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
17
22
|
setHeaders(headers: Record<string, string>): void;
|
|
18
23
|
getEndpoint(): string;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Configuration for creating an ORM client.
|
|
22
|
-
* Either provide endpoint (and optional headers) for HTTP requests,
|
|
27
|
+
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
|
|
23
28
|
* or provide a custom adapter for alternative execution strategies.
|
|
24
29
|
*/
|
|
25
30
|
export interface OrmClientConfig {
|
|
@@ -27,7 +32,14 @@ export interface OrmClientConfig {
|
|
|
27
32
|
endpoint?: string;
|
|
28
33
|
/** Default headers for HTTP requests (only used with endpoint) */
|
|
29
34
|
headers?: Record<string, string>;
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation. Defaults to createFetch() from
|
|
37
|
+
* @constructive-io/graphql-query/runtime which handles *.localhost
|
|
38
|
+
* DNS and Host headers in Node.js. Pass your own for test mocking
|
|
39
|
+
* or custom proxy/credentials.
|
|
40
|
+
*/
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
|
|
31
43
|
adapter?: GraphQLAdapter;
|
|
32
44
|
}
|
|
33
45
|
/**
|
package/public/orm/client.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrmClient = exports.GraphQLRequestError = exports.FetchAdapter = void 0;
|
|
4
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
4
5
|
/**
|
|
5
6
|
* Default adapter that uses fetch for HTTP requests.
|
|
6
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* When no custom fetch is provided, uses @constructive-io/fetch which
|
|
9
|
+
* handles *.localhost DNS rewriting and Host header preservation in
|
|
10
|
+
* Node.js. Pass a custom fetch to override for test mocking or custom
|
|
11
|
+
* proxy/credentials.
|
|
7
12
|
*/
|
|
8
13
|
class FetchAdapter {
|
|
9
14
|
endpoint;
|
|
10
15
|
headers;
|
|
11
|
-
|
|
16
|
+
fetchFn;
|
|
17
|
+
constructor(endpoint, headers, fetchFn) {
|
|
12
18
|
this.endpoint = endpoint;
|
|
13
19
|
this.headers = headers ?? {};
|
|
20
|
+
this.fetchFn = fetchFn ?? (0, runtime_1.createFetch)();
|
|
14
21
|
}
|
|
15
22
|
async execute(document, variables) {
|
|
16
|
-
const response = await
|
|
23
|
+
const response = await this.fetchFn(this.endpoint, {
|
|
17
24
|
method: 'POST',
|
|
18
25
|
headers: {
|
|
19
26
|
'Content-Type': 'application/json',
|
|
@@ -29,7 +36,9 @@ class FetchAdapter {
|
|
|
29
36
|
return {
|
|
30
37
|
ok: false,
|
|
31
38
|
data: null,
|
|
32
|
-
errors: [
|
|
39
|
+
errors: [
|
|
40
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
41
|
+
],
|
|
33
42
|
};
|
|
34
43
|
}
|
|
35
44
|
const json = (await response.json());
|
|
@@ -76,7 +85,7 @@ class OrmClient {
|
|
|
76
85
|
this.adapter = config.adapter;
|
|
77
86
|
}
|
|
78
87
|
else if (config.endpoint) {
|
|
79
|
-
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
88
|
+
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
|
|
80
89
|
}
|
|
81
90
|
else {
|
|
82
91
|
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
|
|
@@ -50,7 +50,7 @@ exports.buildCustomDocument = buildCustomDocument;
|
|
|
50
50
|
* @generated by @constructive-io/graphql-codegen
|
|
51
51
|
* DO NOT EDIT - changes will be overwritten
|
|
52
52
|
*/
|
|
53
|
-
const
|
|
53
|
+
const runtime_1 = require("@constructive-io/graphql-query/runtime");
|
|
54
54
|
const t = __importStar(require("gql-ast"));
|
|
55
55
|
const client_1 = require("./client");
|
|
56
56
|
class QueryBuilder {
|
|
@@ -221,7 +221,7 @@ function buildFindManyDocument(operationName, queryField, select, args, filterTy
|
|
|
221
221
|
}),
|
|
222
222
|
],
|
|
223
223
|
});
|
|
224
|
-
return { document: (0,
|
|
224
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
225
225
|
}
|
|
226
226
|
function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName, connectionFieldsMap) {
|
|
227
227
|
const selections = select
|
|
@@ -262,7 +262,7 @@ function buildFindFirstDocument(operationName, queryField, select, args, filterT
|
|
|
262
262
|
}),
|
|
263
263
|
],
|
|
264
264
|
});
|
|
265
|
-
return { document: (0,
|
|
265
|
+
return { document: (0, runtime_1.print)(document), variables };
|
|
266
266
|
}
|
|
267
267
|
function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName, connectionFieldsMap) {
|
|
268
268
|
const selections = select
|
|
@@ -342,7 +342,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
342
342
|
const variableDefinitions = [
|
|
343
343
|
t.variableDefinition({
|
|
344
344
|
variable: t.variable({ name: idArgName }),
|
|
345
|
-
type: (0,
|
|
345
|
+
type: (0, runtime_1.parseType)(idTypeName),
|
|
346
346
|
}),
|
|
347
347
|
];
|
|
348
348
|
const queryArgs = [
|
|
@@ -370,7 +370,7 @@ function buildFindOneDocument(operationName, queryField, id, select, idArgName,
|
|
|
370
370
|
],
|
|
371
371
|
});
|
|
372
372
|
return {
|
|
373
|
-
document: (0,
|
|
373
|
+
document: (0, runtime_1.print)(document),
|
|
374
374
|
variables: { [idArgName]: id },
|
|
375
375
|
};
|
|
376
376
|
}
|
|
@@ -445,7 +445,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
445
445
|
: [];
|
|
446
446
|
const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
|
|
447
447
|
variable: t.variable({ name: definition.name }),
|
|
448
|
-
type: (0,
|
|
448
|
+
type: (0, runtime_1.parseType)(definition.type),
|
|
449
449
|
}));
|
|
450
450
|
const fieldArgs = variableDefinitions.map((definition) => t.argument({
|
|
451
451
|
name: definition.name,
|
|
@@ -473,7 +473,7 @@ function buildCustomDocument(operationType, operationName, fieldName, select, ar
|
|
|
473
473
|
],
|
|
474
474
|
});
|
|
475
475
|
return {
|
|
476
|
-
document: (0,
|
|
476
|
+
document: (0, runtime_1.print)(document),
|
|
477
477
|
variables: (args ?? {}),
|
|
478
478
|
};
|
|
479
479
|
}
|
|
@@ -551,7 +551,7 @@ function buildInputMutationDocument(config) {
|
|
|
551
551
|
variableDefinitions: [
|
|
552
552
|
t.variableDefinition({
|
|
553
553
|
variable: t.variable({ name: 'input' }),
|
|
554
|
-
type: (0,
|
|
554
|
+
type: (0, runtime_1.parseType)(config.inputTypeName + '!'),
|
|
555
555
|
}),
|
|
556
556
|
],
|
|
557
557
|
selectionSet: t.selectionSet({
|
|
@@ -573,14 +573,14 @@ function buildInputMutationDocument(config) {
|
|
|
573
573
|
}),
|
|
574
574
|
],
|
|
575
575
|
});
|
|
576
|
-
return (0,
|
|
576
|
+
return (0, runtime_1.print)(document);
|
|
577
577
|
}
|
|
578
578
|
function addVariable(spec, definitions, args, variables) {
|
|
579
579
|
if (spec.value === undefined || !spec.typeName)
|
|
580
580
|
return;
|
|
581
581
|
definitions.push(t.variableDefinition({
|
|
582
582
|
variable: t.variable({ name: spec.varName }),
|
|
583
|
-
type: (0,
|
|
583
|
+
type: (0, runtime_1.parseType)(spec.typeName),
|
|
584
584
|
}));
|
|
585
585
|
args.push(t.argument({
|
|
586
586
|
name: spec.argName ?? spec.varName,
|