@constructive-io/sdk 0.14.12 → 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 +16 -4
- package/admin/orm/client.js +14 -5
- package/auth/orm/client.d.ts +16 -4
- package/auth/orm/client.js +14 -5
- package/esm/admin/orm/client.d.ts +16 -4
- package/esm/admin/orm/client.js +14 -5
- package/esm/auth/orm/client.d.ts +16 -4
- package/esm/auth/orm/client.js +14 -5
- package/esm/objects/orm/client.d.ts +16 -4
- package/esm/objects/orm/client.js +14 -5
- package/esm/public/orm/client.d.ts +16 -4
- package/esm/public/orm/client.js +14 -5
- package/objects/orm/client.d.ts +16 -4
- package/objects/orm/client.js +14 -5
- package/package.json +4 -4
- package/public/orm/client.d.ts +16 -4
- package/public/orm/client.js +14 -5
package/admin/orm/client.d.ts
CHANGED
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
package/auth/orm/client.d.ts
CHANGED
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
package/esm/auth/orm/client.d.ts
CHANGED
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
package/objects/orm/client.d.ts
CHANGED
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|
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,17 +42,17 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@0no-co/graphql.web": "^1.1.2",
|
|
45
|
-
"@constructive-io/graphql-query": "^3.15.
|
|
45
|
+
"@constructive-io/graphql-query": "^3.15.2",
|
|
46
46
|
"@constructive-io/graphql-types": "^3.5.1",
|
|
47
47
|
"gql-ast": "^3.5.0",
|
|
48
48
|
"graphql": "16.13.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@constructive-io/graphql-codegen": "^4.
|
|
51
|
+
"@constructive-io/graphql-codegen": "^4.32.0",
|
|
52
52
|
"@types/node": "^22.19.11",
|
|
53
53
|
"makage": "^0.3.0",
|
|
54
54
|
"tsx": "^4.19.0",
|
|
55
55
|
"typescript": "^5.9.3"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a8ccaed4f3a7c6c82495241ee1581700db9dd2dd"
|
|
58
58
|
}
|
package/public/orm/client.d.ts
CHANGED
|
@@ -7,19 +7,24 @@ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io
|
|
|
7
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');
|