@rxdi/graphql-client 0.7.258 → 0.7.260

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/dist/index.d.ts CHANGED
@@ -1,6 +1,22 @@
1
1
  import { ModuleWithServices } from '@rxdi/core';
2
2
  import type { DocumentNode } from '@apollo/client/core';
3
3
  import { GraphqlModuleConfig } from './graphql.injection';
4
+ /**
5
+ * Ask for one operation to go over the WebSocket instead of HTTP:
6
+ * `client.mutate({ ..., context: OVER_WEBSOCKET })`. For chatty operations
7
+ * that must not pay a request each (a terminal's keystrokes): the socket is
8
+ * already open, with no HTTP / TLS / gateway per message. The server must
9
+ * execute that operation over its subscriptions socket.
10
+ */
11
+ export declare const OVER_WEBSOCKET: {
12
+ readonly transport: "websocket";
13
+ };
14
+ /** The link split: subscriptions always over the WebSocket (as before),
15
+ any other operation only when its context asks (OVER_WEBSOCKET). */
16
+ export declare function overWebSocket(operation: {
17
+ query: DocumentNode;
18
+ getContext?: () => Record<string, unknown>;
19
+ }): boolean;
4
20
  export declare class GraphqlModule {
5
21
  static forRoot({ uri, pubsub, refreshOnUnauthenticated, onRequest, cache, apolloRequestHandler, cancelPendingRequests, apolloClientOptions, httpOptions, pubsubOptions, onSubscriptionConnectionError, }?: GraphqlModuleConfig, documents?: Record<string, DocumentNode | string>): ModuleWithServices;
6
22
  }
package/dist/index.js CHANGED
@@ -30,7 +30,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
30
30
  };
31
31
  var GraphqlModule_1;
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.InMemoryCache = exports.GraphqlModule = void 0;
33
+ exports.InMemoryCache = exports.GraphqlModule = exports.OVER_WEBSOCKET = void 0;
34
+ exports.overWebSocket = overWebSocket;
34
35
  const core_1 = require("@rxdi/core");
35
36
  const cache_1 = require("@apollo/client/cache");
36
37
  const graphql_injection_1 = require("./graphql.injection");
@@ -39,6 +40,25 @@ const ws_1 = require("@apollo/client/link/ws");
39
40
  const subscription_client_1 = require("./subscription-client");
40
41
  const utilities_1 = require("@apollo/client/utilities");
41
42
  const context_1 = require("@apollo/client/link/context");
43
+ /**
44
+ * Ask for one operation to go over the WebSocket instead of HTTP:
45
+ * `client.mutate({ ..., context: OVER_WEBSOCKET })`. For chatty operations
46
+ * that must not pay a request each (a terminal's keystrokes): the socket is
47
+ * already open, with no HTTP / TLS / gateway per message. The server must
48
+ * execute that operation over its subscriptions socket.
49
+ */
50
+ exports.OVER_WEBSOCKET = { transport: 'websocket' };
51
+ /** The link split: subscriptions always over the WebSocket (as before),
52
+ any other operation only when its context asks (OVER_WEBSOCKET). */
53
+ function overWebSocket(operation) {
54
+ var _a, _b;
55
+ const { kind, operation: type } = (0, utilities_1.getMainDefinition)(operation.query);
56
+ if (kind !== 'OperationDefinition') {
57
+ return false;
58
+ }
59
+ return (type === 'subscription' ||
60
+ ((_b = (_a = operation.getContext) === null || _a === void 0 ? void 0 : _a.call(operation)) === null || _b === void 0 ? void 0 : _b.transport) === exports.OVER_WEBSOCKET.transport);
61
+ }
42
62
  let GraphqlModule = GraphqlModule_1 = class GraphqlModule {
43
63
  static forRoot({ uri, pubsub, refreshOnUnauthenticated, onRequest, cache, apolloRequestHandler, cancelPendingRequests, apolloClientOptions, httpOptions = {}, pubsubOptions = {}, onSubscriptionConnectionError, } = {}, documents = {}) {
44
64
  const headers = {};
@@ -133,10 +153,7 @@ let GraphqlModule = GraphqlModule_1 = class GraphqlModule {
133
153
  /* End cancel request */
134
154
  return forward(operation);
135
155
  }),
136
- ]), (0, core_2.split)(({ query }) => {
137
- const { kind, operation } = (0, utilities_1.getMainDefinition)(query);
138
- return kind === 'OperationDefinition' && operation === 'subscription';
139
- }, new ws_1.WebSocketLink(subscriptionClient), (0, core_2.createHttpLink)(Object.assign({ uri }, httpOptions)))), cache: cache || new cache_1.InMemoryCache() }, apolloClientOptions)),
156
+ ]), (0, core_2.split)(overWebSocket, new ws_1.WebSocketLink(subscriptionClient), (0, core_2.createHttpLink)(Object.assign({ uri }, httpOptions)))), cache: cache || new cache_1.InMemoryCache() }, apolloClientOptions)),
140
157
  },
141
158
  ],
142
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/graphql-client",
3
- "version": "0.7.258",
3
+ "version": "0.7.260",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Kristiyan Tachev",
6
6
  "license": "MIT",
@@ -17,7 +17,7 @@
17
17
  "subscriptions-transport-ws": "^0.9.19"
18
18
  },
19
19
  "devDependencies": {
20
- "@rxdi/core": "^0.7.257",
20
+ "@rxdi/core": "^0.7.259",
21
21
  "@types/jest": "^29.5.0",
22
22
  "graphql": "^16.12.0",
23
23
  "jest": "^29.7.0",