@graphql-tools/url-loader 8.0.0 → 8.0.1-alpha-20230809181317-aca946d4
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/cjs/index.js +10 -8
- package/esm/index.js +9 -7
- package/package.json +7 -7
- package/typings/index.d.cts +3 -3
- package/typings/index.d.ts +3 -3
package/cjs/index.js
CHANGED
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UrlLoader = exports.SubscriptionProtocol = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
7
|
-
const wrap_1 = require("@graphql-tools/wrap");
|
|
8
6
|
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
|
|
9
7
|
const value_or_promise_1 = require("value-or-promise");
|
|
10
|
-
const defaultAsyncFetch_js_1 = require("./defaultAsyncFetch.js");
|
|
11
|
-
const defaultSyncFetch_js_1 = require("./defaultSyncFetch.js");
|
|
12
8
|
const executor_graphql_ws_1 = require("@graphql-tools/executor-graphql-ws");
|
|
13
9
|
const executor_http_1 = require("@graphql-tools/executor-http");
|
|
14
10
|
const executor_legacy_ws_1 = require("@graphql-tools/executor-legacy-ws");
|
|
11
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
12
|
+
const wrap_1 = require("@graphql-tools/wrap");
|
|
13
|
+
const defaultAsyncFetch_js_1 = require("./defaultAsyncFetch.js");
|
|
14
|
+
const defaultSyncFetch_js_1 = require("./defaultSyncFetch.js");
|
|
15
15
|
const asyncImport = (moduleName) => Promise.resolve(`${`${moduleName}`}`).then(s => tslib_1.__importStar(require(s)));
|
|
16
16
|
const syncImport = (moduleName) => require(`${moduleName}`);
|
|
17
17
|
var SubscriptionProtocol;
|
|
@@ -29,7 +29,7 @@ var SubscriptionProtocol;
|
|
|
29
29
|
* Use `graphql-sse` for subscriptions
|
|
30
30
|
*/
|
|
31
31
|
SubscriptionProtocol["GRAPHQL_SSE"] = "GRAPHQL_SSE";
|
|
32
|
-
})(SubscriptionProtocol
|
|
32
|
+
})(SubscriptionProtocol || (exports.SubscriptionProtocol = SubscriptionProtocol = {}));
|
|
33
33
|
const acceptableProtocols = ['http:', 'https:', 'ws:', 'wss:'];
|
|
34
34
|
function isCompatibleUri(uri) {
|
|
35
35
|
try {
|
|
@@ -111,7 +111,7 @@ class UrlLoader {
|
|
|
111
111
|
if (typeof options?.webSocketImpl === 'string') {
|
|
112
112
|
const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
|
|
113
113
|
return new value_or_promise_1.ValueOrPromise(() => importFn(moduleName))
|
|
114
|
-
.then(importedModule =>
|
|
114
|
+
.then(importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule)
|
|
115
115
|
.resolve();
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
@@ -149,14 +149,16 @@ class UrlLoader {
|
|
|
149
149
|
const httpExecutor$ = fetch$.then(fetch => {
|
|
150
150
|
return this.buildHTTPExecutor(endpoint, fetch, options);
|
|
151
151
|
});
|
|
152
|
-
if (options?.subscriptionsEndpoint != null ||
|
|
152
|
+
if (options?.subscriptionsEndpoint != null ||
|
|
153
|
+
options?.subscriptionsProtocol !== SubscriptionProtocol.SSE) {
|
|
153
154
|
const subscriptionExecutor$ = fetch$.then(fetch => {
|
|
154
155
|
const subscriptionsEndpoint = options?.subscriptionsEndpoint || endpoint;
|
|
155
156
|
return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
|
|
156
157
|
});
|
|
157
158
|
// eslint-disable-next-line no-inner-declarations
|
|
158
159
|
function getExecutorByRequest(request) {
|
|
159
|
-
request.operationType =
|
|
160
|
+
request.operationType =
|
|
161
|
+
request.operationType || (0, utils_1.getOperationASTFromRequest)(request)?.operation;
|
|
160
162
|
if (request.operationType === 'subscription' &&
|
|
161
163
|
(0, executor_http_1.isLiveQueryOperationDefinitionNode)((0, utils_1.getOperationASTFromRequest)(request))) {
|
|
162
164
|
request.operationType = 'subscription';
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { buildASTSchema, buildSchema } from 'graphql';
|
|
2
|
-
import { parseGraphQLSDL, getOperationASTFromRequest, } from '@graphql-tools/utils';
|
|
3
|
-
import { schemaFromExecutor, wrapSchema } from '@graphql-tools/wrap';
|
|
4
2
|
import WebSocket from 'isomorphic-ws';
|
|
5
3
|
import { ValueOrPromise } from 'value-or-promise';
|
|
6
|
-
import { defaultAsyncFetch } from './defaultAsyncFetch.js';
|
|
7
|
-
import { defaultSyncFetch } from './defaultSyncFetch.js';
|
|
8
4
|
import { buildGraphQLWSExecutor } from '@graphql-tools/executor-graphql-ws';
|
|
9
5
|
import { buildHTTPExecutor, isLiveQueryOperationDefinitionNode, } from '@graphql-tools/executor-http';
|
|
10
6
|
import { buildWSLegacyExecutor } from '@graphql-tools/executor-legacy-ws';
|
|
7
|
+
import { getOperationASTFromRequest, parseGraphQLSDL, } from '@graphql-tools/utils';
|
|
8
|
+
import { schemaFromExecutor, wrapSchema } from '@graphql-tools/wrap';
|
|
9
|
+
import { defaultAsyncFetch } from './defaultAsyncFetch.js';
|
|
10
|
+
import { defaultSyncFetch } from './defaultSyncFetch.js';
|
|
11
11
|
const asyncImport = (moduleName) => import(`${moduleName}`);
|
|
12
12
|
const syncImport = (moduleName) => require(`${moduleName}`);
|
|
13
13
|
export var SubscriptionProtocol;
|
|
@@ -107,7 +107,7 @@ export class UrlLoader {
|
|
|
107
107
|
if (typeof options?.webSocketImpl === 'string') {
|
|
108
108
|
const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
|
|
109
109
|
return new ValueOrPromise(() => importFn(moduleName))
|
|
110
|
-
.then(importedModule =>
|
|
110
|
+
.then(importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule)
|
|
111
111
|
.resolve();
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
@@ -145,14 +145,16 @@ export class UrlLoader {
|
|
|
145
145
|
const httpExecutor$ = fetch$.then(fetch => {
|
|
146
146
|
return this.buildHTTPExecutor(endpoint, fetch, options);
|
|
147
147
|
});
|
|
148
|
-
if (options?.subscriptionsEndpoint != null ||
|
|
148
|
+
if (options?.subscriptionsEndpoint != null ||
|
|
149
|
+
options?.subscriptionsProtocol !== SubscriptionProtocol.SSE) {
|
|
149
150
|
const subscriptionExecutor$ = fetch$.then(fetch => {
|
|
150
151
|
const subscriptionsEndpoint = options?.subscriptionsEndpoint || endpoint;
|
|
151
152
|
return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
|
|
152
153
|
});
|
|
153
154
|
// eslint-disable-next-line no-inner-declarations
|
|
154
155
|
function getExecutorByRequest(request) {
|
|
155
|
-
request.operationType =
|
|
156
|
+
request.operationType =
|
|
157
|
+
request.operationType || getOperationASTFromRequest(request)?.operation;
|
|
156
158
|
if (request.operationType === 'subscription' &&
|
|
157
159
|
isLiveQueryOperationDefinitionNode(getOperationASTFromRequest(request))) {
|
|
158
160
|
request.operationType = 'subscription';
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/url-loader",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.1-alpha-20230809181317-aca946d4",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@
|
|
11
|
-
"@graphql-tools/
|
|
10
|
+
"@ardatan/sync-fetch": "^0.0.1",
|
|
11
|
+
"@graphql-tools/delegate": "10.0.2-alpha-20230809181317-aca946d4",
|
|
12
12
|
"@graphql-tools/executor-graphql-ws": "^1.0.0",
|
|
13
|
+
"@graphql-tools/executor-http": "1.0.3-alpha-20230809181317-aca946d4",
|
|
13
14
|
"@graphql-tools/executor-legacy-ws": "^1.0.0",
|
|
14
15
|
"@graphql-tools/utils": "^10.0.0",
|
|
15
16
|
"@graphql-tools/wrap": "^10.0.0",
|
|
16
|
-
"@ardatan/sync-fetch": "^0.0.1",
|
|
17
|
-
"@whatwg-node/fetch": "^0.9.0",
|
|
18
17
|
"@types/ws": "^8.0.0",
|
|
19
|
-
"
|
|
18
|
+
"@whatwg-node/fetch": "^0.9.0",
|
|
20
19
|
"isomorphic-ws": "^5.0.0",
|
|
21
20
|
"tslib": "^2.4.0",
|
|
22
|
-
"value-or-promise": "^1.0.11"
|
|
21
|
+
"value-or-promise": "^1.0.11",
|
|
22
|
+
"ws": "^8.12.0"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
package/typings/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="ws" />
|
|
2
2
|
import { IntrospectionOptions } from 'graphql';
|
|
3
|
-
import { AsyncExecutor, Executor, SyncExecutor, Source, Loader, BaseLoaderOptions } from '@graphql-tools/utils';
|
|
4
3
|
import WebSocket from 'isomorphic-ws';
|
|
5
4
|
import { AsyncFetchFn, FetchFn, HTTPExecutorOptions, SyncFetchFn } from '@graphql-tools/executor-http';
|
|
5
|
+
import { AsyncExecutor, BaseLoaderOptions, Executor, Loader, Source, SyncExecutor } from '@graphql-tools/utils';
|
|
6
6
|
export { FetchFn };
|
|
7
7
|
export type AsyncImportFn = (moduleName: string) => PromiseLike<any>;
|
|
8
8
|
export type SyncImportFn = (moduleName: string) => any;
|
|
@@ -59,7 +59,7 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
59
59
|
/**
|
|
60
60
|
* Connection Parameters for WebSockets connection
|
|
61
61
|
*/
|
|
62
|
-
connectionParams?:
|
|
62
|
+
connectionParams?: Record<string, unknown> | (() => Record<string, unknown>);
|
|
63
63
|
/**
|
|
64
64
|
* Enable Batching
|
|
65
65
|
*/
|
|
@@ -80,7 +80,7 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
80
80
|
export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
|
|
81
81
|
buildHTTPExecutor(endpoint: string, fetchFn: SyncFetchFn, options?: LoadFromUrlOptions): SyncExecutor<any, ExecutionExtensions>;
|
|
82
82
|
buildHTTPExecutor(endpoint: string, fetchFn: AsyncFetchFn, options?: LoadFromUrlOptions): AsyncExecutor<any, ExecutionExtensions>;
|
|
83
|
-
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: Record<string,
|
|
83
|
+
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: Record<string, unknown> | (() => Record<string, unknown>)): Executor;
|
|
84
84
|
buildWSLegacyExecutor(subscriptionsEndpoint: string, WebSocketImpl: typeof WebSocket, options?: LoadFromUrlOptions): Executor;
|
|
85
85
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: AsyncImportFn): PromiseLike<AsyncFetchFn> | AsyncFetchFn;
|
|
86
86
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: SyncImportFn): SyncFetchFn;
|
package/typings/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="ws" />
|
|
2
2
|
import { IntrospectionOptions } from 'graphql';
|
|
3
|
-
import { AsyncExecutor, Executor, SyncExecutor, Source, Loader, BaseLoaderOptions } from '@graphql-tools/utils';
|
|
4
3
|
import WebSocket from 'isomorphic-ws';
|
|
5
4
|
import { AsyncFetchFn, FetchFn, HTTPExecutorOptions, SyncFetchFn } from '@graphql-tools/executor-http';
|
|
5
|
+
import { AsyncExecutor, BaseLoaderOptions, Executor, Loader, Source, SyncExecutor } from '@graphql-tools/utils';
|
|
6
6
|
export { FetchFn };
|
|
7
7
|
export type AsyncImportFn = (moduleName: string) => PromiseLike<any>;
|
|
8
8
|
export type SyncImportFn = (moduleName: string) => any;
|
|
@@ -59,7 +59,7 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
59
59
|
/**
|
|
60
60
|
* Connection Parameters for WebSockets connection
|
|
61
61
|
*/
|
|
62
|
-
connectionParams?:
|
|
62
|
+
connectionParams?: Record<string, unknown> | (() => Record<string, unknown>);
|
|
63
63
|
/**
|
|
64
64
|
* Enable Batching
|
|
65
65
|
*/
|
|
@@ -80,7 +80,7 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
80
80
|
export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
|
|
81
81
|
buildHTTPExecutor(endpoint: string, fetchFn: SyncFetchFn, options?: LoadFromUrlOptions): SyncExecutor<any, ExecutionExtensions>;
|
|
82
82
|
buildHTTPExecutor(endpoint: string, fetchFn: AsyncFetchFn, options?: LoadFromUrlOptions): AsyncExecutor<any, ExecutionExtensions>;
|
|
83
|
-
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: Record<string,
|
|
83
|
+
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: Record<string, unknown> | (() => Record<string, unknown>)): Executor;
|
|
84
84
|
buildWSLegacyExecutor(subscriptionsEndpoint: string, WebSocketImpl: typeof WebSocket, options?: LoadFromUrlOptions): Executor;
|
|
85
85
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: AsyncImportFn): PromiseLike<AsyncFetchFn> | AsyncFetchFn;
|
|
86
86
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: SyncImportFn): SyncFetchFn;
|