@rxdi/graphql-pubsub-test 0.7.201
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/.travis.yml +9 -0
- package/README.md +94 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +58 -0
- package/gapi-cli.conf.yml +15 -0
- package/package.json +76 -0
package/.travis.yml
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @rxdi Graphql-Pub-Sub Module
|
|
2
|
+
|
|
3
|
+
##### More information about Hapi server can be found here [Hapi](https://hapijs.com/)
|
|
4
|
+
|
|
5
|
+
##### For questions/issues you can write ticket [here](http://gitlab.youvolio.com/rxdi/graphql/issues)
|
|
6
|
+
|
|
7
|
+
##### This module is intended to be used with [rxdi](https://github.com/rxdi/core)
|
|
8
|
+
|
|
9
|
+
## Installation and basic examples:
|
|
10
|
+
|
|
11
|
+
##### To install this Gapi module, run:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
$ npm install @rxdi/graphql-pubsub --save
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Consuming @rxdi/graphql-pubsub
|
|
18
|
+
|
|
19
|
+
##### Import inside AppModule or CoreModule
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Module } from "@rxdi/core";
|
|
23
|
+
import { HapiModule } from "@rxdi/hapi";
|
|
24
|
+
import { GraphQLPubSubModule } from "@rxdi/graphql-pubsub";
|
|
25
|
+
|
|
26
|
+
@Module({
|
|
27
|
+
imports: [GraphQLPubSubModule.forRoot()],
|
|
28
|
+
})
|
|
29
|
+
export class CoreModule {}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Correct usage with `@rxdi/graphql`
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Module } from "@rxdi/core";
|
|
36
|
+
import { HapiModule } from "@rxdi/hapi";
|
|
37
|
+
import { GraphQLModule } from "@rxdi/graphql";
|
|
38
|
+
import { GraphQLPubSubModule } from "@rxdi/graphql-pubsub";
|
|
39
|
+
|
|
40
|
+
@Module({
|
|
41
|
+
imports: [
|
|
42
|
+
HapiModule.forRoot({
|
|
43
|
+
hapi: {
|
|
44
|
+
port: 9000,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
GraphQLModule.forRoot({
|
|
48
|
+
path: "/graphql",
|
|
49
|
+
writeEffects: false,
|
|
50
|
+
graphqlOptions: {
|
|
51
|
+
schema: null,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
GraphQLPubSubModule.forRoot(),
|
|
55
|
+
],
|
|
56
|
+
})
|
|
57
|
+
export class CoreModule {}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Options for pubsub server can be defined like so
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
GraphQLPubSubModule.forRoot({
|
|
64
|
+
activateRabbitMQ: false,
|
|
65
|
+
host: "182.10.0.5",
|
|
66
|
+
port: 5672,
|
|
67
|
+
// authentication: AuthService as never,
|
|
68
|
+
subscriptionServerOptions: {
|
|
69
|
+
perMessageDeflate: {
|
|
70
|
+
zlibDeflateOptions: {
|
|
71
|
+
// See zlib defaults.
|
|
72
|
+
chunkSize: 1024,
|
|
73
|
+
memLevel: 7,
|
|
74
|
+
level: 3,
|
|
75
|
+
},
|
|
76
|
+
zlibInflateOptions: {
|
|
77
|
+
chunkSize: 10 * 1024,
|
|
78
|
+
},
|
|
79
|
+
// Other options settable:
|
|
80
|
+
clientNoContextTakeover: true, // Defaults to negotiated value.
|
|
81
|
+
serverNoContextTakeover: true, // Defaults to negotiated value.
|
|
82
|
+
serverMaxWindowBits: 10, // Defaults to negotiated value.
|
|
83
|
+
// Below options specified as default values.
|
|
84
|
+
concurrencyLimit: 10, // Limits zlib concurrency for perf.
|
|
85
|
+
threshold: 1024, // Size (in bytes) below which messages
|
|
86
|
+
// should not be compressed.
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
TODO: Better documentation...
|
|
93
|
+
|
|
94
|
+
Enjoy ! :)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DocumentNode } from '@apollo/client/core';
|
|
2
|
+
import { WebSocketLink } from '@apollo/client/link/ws';
|
|
3
|
+
import { ClientOptions } from 'subscriptions-transport-ws';
|
|
4
|
+
import { Server } from '@hapi/hapi';
|
|
5
|
+
import { Observable } from 'rxjs';
|
|
6
|
+
export interface WSLinkOptions extends ClientOptions {
|
|
7
|
+
server?: any;
|
|
8
|
+
uri: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ExtendedServer extends Server {
|
|
11
|
+
port: number | string;
|
|
12
|
+
}
|
|
13
|
+
export declare const createWebsocketLink: (options?: WSLinkOptions) => WebSocketLink;
|
|
14
|
+
export declare const subscribeToTopic: <T, V = any>(query: DocumentNode, variables?: V, link?: WebSocketLink) => Observable<T>;
|
|
15
|
+
export { WebSocketLink } from '@apollo/client/link/ws';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketLink = exports.subscribeToTopic = exports.createWebsocketLink = void 0;
|
|
4
|
+
const core_1 = require("@apollo/client/core");
|
|
5
|
+
const ws_1 = require("@apollo/client/link/ws");
|
|
6
|
+
const core_2 = require("@rxdi/core");
|
|
7
|
+
const hapi_1 = require("@rxdi/hapi");
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
const ws = require('ws');
|
|
10
|
+
const createWebsocketLink = (options = { uri: 'ws://localhost:9000/subscriptions' }) => {
|
|
11
|
+
let server;
|
|
12
|
+
try {
|
|
13
|
+
server = core_2.Container.get(options.server || hapi_1.HAPI_SERVER);
|
|
14
|
+
}
|
|
15
|
+
catch (e) { }
|
|
16
|
+
if (server) {
|
|
17
|
+
options.uri = `ws://localhost:${server.info.port || server.port}/subscriptions`;
|
|
18
|
+
}
|
|
19
|
+
if (!core_2.Container.has(ws_1.WebSocketLink)) {
|
|
20
|
+
core_2.Container.set(ws_1.WebSocketLink, new ws_1.WebSocketLink({
|
|
21
|
+
uri: options.uri,
|
|
22
|
+
options: options || {
|
|
23
|
+
reconnect: true,
|
|
24
|
+
},
|
|
25
|
+
webSocketImpl: ws,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
return core_2.Container.get(ws_1.WebSocketLink);
|
|
29
|
+
};
|
|
30
|
+
exports.createWebsocketLink = createWebsocketLink;
|
|
31
|
+
const subscribeToTopic = (query, variables, link) => {
|
|
32
|
+
return new rxjs_1.Observable((o) => {
|
|
33
|
+
const cmd = (0, core_1.execute)(link || (0, exports.createWebsocketLink)(), {
|
|
34
|
+
query,
|
|
35
|
+
variables,
|
|
36
|
+
}).subscribe({
|
|
37
|
+
next: o.next.bind(o),
|
|
38
|
+
error: o.error.bind(o),
|
|
39
|
+
complete: o.complete.bind(o),
|
|
40
|
+
});
|
|
41
|
+
return () => cmd.unsubscribe();
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.subscribeToTopic = subscribeToTopic;
|
|
45
|
+
var ws_2 = require("@apollo/client/link/ws");
|
|
46
|
+
Object.defineProperty(exports, "WebSocketLink", { enumerable: true, get: function () { return ws_2.WebSocketLink; } });
|
|
47
|
+
// const subscription = subscribeToTopic<{data: {statusSubscription: { status: string }}}>(gql`
|
|
48
|
+
// subscription {
|
|
49
|
+
// statusSubscription {
|
|
50
|
+
// status
|
|
51
|
+
// }
|
|
52
|
+
// }
|
|
53
|
+
// `).subscribe(stream => {
|
|
54
|
+
// console.log(stream.data.statusSubscription.status);
|
|
55
|
+
// });
|
|
56
|
+
// setTimeout(() => {
|
|
57
|
+
// subscription.unsubscribe();
|
|
58
|
+
// }, 5000);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
commands:
|
|
3
|
+
testing:
|
|
4
|
+
browser: jest --env jsdom --testPathPattern="/src/.*\\.browser.spec.(ts|tsx|js)$"
|
|
5
|
+
node: jest --env node --testPathPattern="/src/.*\\.spec.(ts|tsx|js)$"
|
|
6
|
+
build:
|
|
7
|
+
core:
|
|
8
|
+
- tsc
|
|
9
|
+
- find . -not -path "./node_modules/*" -type f -iname \*.js -delete
|
|
10
|
+
- parcel build --target node development/index.ts
|
|
11
|
+
- cp -r dist/index.js index.js
|
|
12
|
+
- gapi build clean
|
|
13
|
+
clean:
|
|
14
|
+
- rm -rf dist
|
|
15
|
+
- rm -rf .cache
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rxdi/graphql-pubsub-test",
|
|
3
|
+
"version": "0.7.201",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/rxdi/graphql-pubsub"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"typings": "./dist/index.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "jest | true",
|
|
14
|
+
"build": "tsc || true",
|
|
15
|
+
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
|
|
16
|
+
"pretest": "npm run lint"
|
|
17
|
+
},
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Kristian Tachev(Stradivario)",
|
|
20
|
+
"email": "kristiqn.tachev@gmail.com"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"graphql",
|
|
24
|
+
"gapi",
|
|
25
|
+
"node"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/rxdi/graphql-pubsub/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/rxdi/graphql-pubsub#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@apollo/client": "^3.7.3",
|
|
34
|
+
"subscriptions-transport-ws": "^0.9.19",
|
|
35
|
+
"ws": "6.2.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@rxdi/core": "^0.7.200",
|
|
39
|
+
"@rxdi/graphql": "^0.7.200",
|
|
40
|
+
"@rxdi/hapi": "^0.7.200",
|
|
41
|
+
"@types/graphql": "^14.5.0",
|
|
42
|
+
"@types/hapi": "^18.0.4",
|
|
43
|
+
"@types/jest": "^24.0.22",
|
|
44
|
+
"@types/node": "^25.0.3",
|
|
45
|
+
"jest": "^24.8.0",
|
|
46
|
+
"jest-cli": "^24.8.1",
|
|
47
|
+
"ts-jest": "^24.0.2",
|
|
48
|
+
"tslint": "^5.20.1",
|
|
49
|
+
"tslint-language-service": "^0.9.9",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
},
|
|
52
|
+
"jest": {
|
|
53
|
+
"testEnvironment": "node",
|
|
54
|
+
"testPathIgnorePatterns": [
|
|
55
|
+
"/node_modules/"
|
|
56
|
+
],
|
|
57
|
+
"coverageReporters": [
|
|
58
|
+
"lcov",
|
|
59
|
+
"html"
|
|
60
|
+
],
|
|
61
|
+
"rootDir": "./",
|
|
62
|
+
"moduleFileExtensions": [
|
|
63
|
+
"ts",
|
|
64
|
+
"tsx",
|
|
65
|
+
"js",
|
|
66
|
+
"json",
|
|
67
|
+
"node"
|
|
68
|
+
],
|
|
69
|
+
"transform": {
|
|
70
|
+
"\\.(ts|tsx)$": "ts-jest"
|
|
71
|
+
},
|
|
72
|
+
"testRegex": "/src/.*\\.spec.(ts|tsx|js)$",
|
|
73
|
+
"verbose": true,
|
|
74
|
+
"collectCoverage": true
|
|
75
|
+
}
|
|
76
|
+
}
|