@rxdi/graphql-client 0.7.259 → 0.7.261

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.
@@ -89,3 +89,13 @@ export interface Definintion {
89
89
  kind: string;
90
90
  operation?: string;
91
91
  }
92
+ /**
93
+ * Ask for one operation to go over the WebSocket instead of HTTP:
94
+ * `client.mutate({ ..., context: OVER_WEBSOCKET })`. For chatty operations
95
+ * that must not pay a request each (a terminal's keystrokes): the socket is
96
+ * already open, with no HTTP / TLS / gateway per message. The server must
97
+ * execute that operation over its subscriptions socket.
98
+ */
99
+ export declare const OVER_WEBSOCKET: {
100
+ readonly transport: "websocket";
101
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noop = exports.noopHeaders = exports.GraphqlDocuments = exports.GraphqlSubscriptionClient = exports.ApolloClient = void 0;
3
+ exports.OVER_WEBSOCKET = exports.noop = exports.noopHeaders = exports.GraphqlDocuments = exports.GraphqlSubscriptionClient = exports.ApolloClient = void 0;
4
4
  exports.isAuthorizationConnectionError = isAuthorizationConnectionError;
5
5
  const core_1 = require("@rxdi/core");
6
6
  exports.ApolloClient = new core_1.InjectionToken('apollo-link');
@@ -51,3 +51,11 @@ const noopHeaders = () => new Headers();
51
51
  exports.noopHeaders = noopHeaders;
52
52
  const noop = () => null;
53
53
  exports.noop = noop;
54
+ /**
55
+ * Ask for one operation to go over the WebSocket instead of HTTP:
56
+ * `client.mutate({ ..., context: OVER_WEBSOCKET })`. For chatty operations
57
+ * that must not pay a request each (a terminal's keystrokes): the socket is
58
+ * already open, with no HTTP / TLS / gateway per message. The server must
59
+ * execute that operation over its subscriptions socket.
60
+ */
61
+ exports.OVER_WEBSOCKET = { transport: 'websocket' };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { ModuleWithServices } from '@rxdi/core';
2
2
  import type { DocumentNode } from '@apollo/client/core';
3
3
  import { GraphqlModuleConfig } from './graphql.injection';
4
+ /** The link split: subscriptions always over the WebSocket (as before),
5
+ any other operation only when its context asks (OVER_WEBSOCKET). */
6
+ export declare function overWebSocket(operation: {
7
+ query: DocumentNode;
8
+ getContext?: () => Record<string, unknown>;
9
+ }): boolean;
4
10
  export declare class GraphqlModule {
5
11
  static forRoot({ uri, pubsub, refreshOnUnauthenticated, onRequest, cache, apolloRequestHandler, cancelPendingRequests, apolloClientOptions, httpOptions, pubsubOptions, onSubscriptionConnectionError, }?: GraphqlModuleConfig, documents?: Record<string, DocumentNode | string>): ModuleWithServices;
6
12
  }
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  var GraphqlModule_1;
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
33
  exports.InMemoryCache = exports.GraphqlModule = 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,17 @@ 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
+ /** The link split: subscriptions always over the WebSocket (as before),
44
+ any other operation only when its context asks (OVER_WEBSOCKET). */
45
+ function overWebSocket(operation) {
46
+ var _a, _b;
47
+ const { kind, operation: type } = (0, utilities_1.getMainDefinition)(operation.query);
48
+ if (kind !== 'OperationDefinition') {
49
+ return false;
50
+ }
51
+ return (type === 'subscription' ||
52
+ ((_b = (_a = operation.getContext) === null || _a === void 0 ? void 0 : _a.call(operation)) === null || _b === void 0 ? void 0 : _b.transport) === graphql_injection_1.OVER_WEBSOCKET.transport);
53
+ }
42
54
  let GraphqlModule = GraphqlModule_1 = class GraphqlModule {
43
55
  static forRoot({ uri, pubsub, refreshOnUnauthenticated, onRequest, cache, apolloRequestHandler, cancelPendingRequests, apolloClientOptions, httpOptions = {}, pubsubOptions = {}, onSubscriptionConnectionError, } = {}, documents = {}) {
44
56
  const headers = {};
@@ -133,10 +145,7 @@ let GraphqlModule = GraphqlModule_1 = class GraphqlModule {
133
145
  /* End cancel request */
134
146
  return forward(operation);
135
147
  }),
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)),
148
+ ]), (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
149
  },
141
150
  ],
142
151
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/graphql-client",
3
- "version": "0.7.259",
3
+ "version": "0.7.261",
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.258",
20
+ "@rxdi/core": "^0.7.260",
21
21
  "@types/jest": "^29.5.0",
22
22
  "graphql": "^16.12.0",
23
23
  "jest": "^29.7.0",