@rxdi/graphql 0.7.198 → 0.7.199

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/README.md CHANGED
@@ -30,23 +30,7 @@ import { GraphQLModule } from "@rxdi/graphql";
30
30
  }),
31
31
  GraphQLModule.forRoot({
32
32
  path: '/graphql',
33
- openBrowser: false,
34
33
  writeEffects: false,
35
- graphiQlPath: '/graphiql',
36
- graphiqlOptions: {
37
- endpointURL: '/graphql',
38
- subscriptionsEndpoint: `${
39
- process.env.GRAPHIQL_WS_SSH ? 'wss' : 'ws'
40
- }://${process.env.GRAPHIQL_WS_PATH || 'localhost'}${
41
- process.env.DEPLOY_PLATFORM === 'heroku'
42
- ? ''
43
- : `:${process.env.API_PORT ||
44
- process.env.PORT}`
45
- }/subscriptions`,
46
- websocketConnectionParams: {
47
- token: process.env.GRAPHIQL_TOKEN
48
- }
49
- },
50
34
  graphqlOptions: {
51
35
  schema: null
52
36
  }
@@ -84,23 +68,7 @@ import * as neo4jgql from 'neo4j-graphql-js';
84
68
  }),
85
69
  GraphQLModule.forRoot({
86
70
  path: '/graphql',
87
- openBrowser: false,
88
71
  writeEffects: false,
89
- graphiQlPath: '/graphiql',
90
- graphiqlOptions: {
91
- endpointURL: '/graphql',
92
- subscriptionsEndpoint: `${
93
- process.env.GRAPHIQL_WS_SSH ? 'wss' : 'ws'
94
- }://${process.env.GRAPHIQL_WS_PATH || 'localhost'}${
95
- process.env.DEPLOY_PLATFORM === 'heroku'
96
- ? ''
97
- : `:${process.env.API_PORT ||
98
- process.env.PORT}`
99
- }/subscriptions`,
100
- websocketConnectionParams: {
101
- token: process.env.GRAPHIQL_TOKEN
102
- }
103
- },
104
72
  graphqlOptions: {
105
73
  context: {
106
74
  driver: (neo4j.driver(
@@ -1,31 +1,17 @@
1
1
  import { InjectionToken } from '@rxdi/core';
2
- import * as GraphiQL from 'apollo-server-module-graphiql';
3
2
  import { GraphQLSchema, GraphQLField, GraphQLDirective } from 'graphql';
4
3
  import { Server, ResponseToolkit } from '@hapi/hapi';
5
- import { RenderPageOptions } from 'graphql-playground-html';
6
4
  import { AltairConfig } from '@rxdi/altair';
7
5
  export interface HapiOptionsFunction {
8
6
  (req?: Request): any | Promise<any>;
9
7
  }
10
- export interface HapiGraphiQLOptionsFunction {
11
- (req?: Request): GraphiQL.GraphiQLData | Promise<GraphiQL.GraphiQLData>;
12
- }
13
- export interface HapiGraphiQLPluginOptions {
14
- path: string;
15
- route?: any;
16
- graphiqlOptions: GraphiQL.GraphiQLData | HapiGraphiQLOptionsFunction;
17
- }
18
8
  export interface GRAPHQL_PLUGIN_CONFIG {
19
9
  path?: string;
20
10
  initQuery?: boolean;
21
11
  disableGlobalGuards?: boolean;
22
12
  directives?: GraphQLDirective[] | any[];
23
13
  buildAstDefinitions?: boolean;
24
- graphiQlPlayground?: boolean;
25
- graphiql?: boolean;
26
- graphiQlPath?: string;
27
14
  writeEffects?: boolean;
28
- openBrowser?: boolean;
29
15
  watcherPort?: string | number;
30
16
  authentication?: Function | InjectionToken<any>;
31
17
  vhost?: string;
@@ -33,8 +19,6 @@ export interface GRAPHQL_PLUGIN_CONFIG {
33
19
  cors?: boolean;
34
20
  };
35
21
  graphqlOptions?: any;
36
- graphiqlOptions?: GraphiQL.GraphiQLData;
37
- graphiqlPlaygroundConfig?: RenderPageOptions;
38
22
  altair?: {
39
23
  enabled: boolean;
40
24
  options?: AltairConfig;
package/dist/index.js CHANGED
@@ -27,18 +27,11 @@ const services_1 = require("./services");
27
27
  const apollo_service_1 = require("./services/apollo.service");
28
28
  const config_tokens_1 = require("./config.tokens");
29
29
  const bootstrap_service_1 = require("./services/bootstrap.service");
30
- const graphiql_service_1 = require("./services/graphiql.service");
31
- const start_service_1 = require("./services/start.service");
32
- const playground_1 = require("@gapi/playground");
33
30
  const altair_1 = require("@rxdi/altair");
34
31
  const plugin_init_1 = require("./plugin-init");
35
32
  let GraphQLModule = GraphQLModule_1 = class GraphQLModule {
36
33
  static forRoot(config) {
37
34
  var _a, _b;
38
- config.graphiqlPlaygroundConfig = config.graphiqlPlaygroundConfig || {};
39
- config.graphiqlPlaygroundConfig.subscriptionEndpoint =
40
- config.graphiqlOptions.subscriptionsEndpoint ||
41
- 'ws://localhost:9000/subscriptions';
42
35
  return {
43
36
  module: GraphQLModule_1,
44
37
  providers: [
@@ -49,15 +42,12 @@ let GraphQLModule = GraphQLModule_1 = class GraphQLModule {
49
42
  },
50
43
  services_1.HookService,
51
44
  bootstrap_service_1.BootstrapService,
52
- apollo_service_1.ApolloService,
53
- graphiql_service_1.GraphiQLService,
54
- start_service_1.StartService
45
+ apollo_service_1.GraphqlService,
55
46
  ],
56
47
  frameworkImports: [
57
48
  ...(((_a = config.altair) === null || _a === void 0 ? void 0 : _a.enabled) ? [altair_1.AltairModule.forRoot((_b = config.altair) === null || _b === void 0 ? void 0 : _b.options)] : []),
58
- playground_1.PlaygroundModule.forRoot(Object.assign(Object.assign({ path: config.graphiQlPath || '/graphiql', endpoint: config.path || '/graphql', version: '1.7.1' }, config.graphiqlPlaygroundConfig), { graphiqlPlayground: config.graphiQlPlayground }))
59
49
  ],
60
- plugins: [services_1.ServerPushPlugin, plugin_init_1.PluginInit]
50
+ plugins: [plugin_init_1.PluginInit]
61
51
  };
62
52
  }
63
53
  };
@@ -1,6 +1,7 @@
1
1
  import { PluginInterface, AfterStarterService } from '@rxdi/core';
2
2
  import { Server } from '@hapi/hapi';
3
3
  import { GRAPHQL_PLUGIN_CONFIG } from './config.tokens';
4
+ import { GraphQLResponse } from './services';
4
5
  export interface Response<T> {
5
6
  raw: string;
6
7
  data: T;
@@ -28,8 +29,7 @@ export declare class PluginInit implements PluginInterface {
28
29
  private afterStarter;
29
30
  defaultQuery: string;
30
31
  constructor(server: Server, config: GRAPHQL_PLUGIN_CONFIG, afterStarter: AfterStarterService);
31
- private tester;
32
32
  register(): Promise<void>;
33
- sendRequest: <T>(request: SendRequestQueryType, url?: string) => PromiseLike<Response<T>>;
34
- checkStatus<T = {}>(request: Response<T>): Promise<void>;
33
+ sendRequest: <T>(request: SendRequestQueryType, url?: string) => Promise<GraphQLResponse<T>>;
34
+ checkStatus(status: number): Promise<void>;
35
35
  }
@@ -23,11 +23,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.PluginInit = void 0;
25
25
  const core_1 = require("@rxdi/core");
26
- const graphql_tester_1 = require("graphql-tester");
27
26
  const hapi_1 = require("@rxdi/hapi");
28
27
  const hapi_2 = require("@hapi/hapi");
29
28
  const operators_1 = require("rxjs/operators");
30
29
  const config_tokens_1 = require("./config.tokens");
30
+ const services_1 = require("./services");
31
31
  let PluginInit = class PluginInit {
32
32
  constructor(server, config, afterStarter) {
33
33
  this.server = server;
@@ -35,11 +35,8 @@ let PluginInit = class PluginInit {
35
35
  this.afterStarter = afterStarter;
36
36
  this.defaultQuery = `query { status { status } } `;
37
37
  this.sendRequest = (request, url = `http://localhost:${this.server.info.port}/graphql`) => {
38
- this.tester = (0, graphql_tester_1.tester)({
39
- url,
40
- contentType: 'application/json'
41
- });
42
- return this.tester(JSON.stringify(request));
38
+ const client = new services_1.GraphQLHttpClient(url);
39
+ return client.request(request);
43
40
  };
44
41
  }
45
42
  register() {
@@ -52,15 +49,15 @@ let PluginInit = class PluginInit {
52
49
  return yield this.sendRequest({
53
50
  query: this.defaultQuery
54
51
  });
55
- })), (0, operators_1.tap)(res => this.checkStatus(res)))
52
+ })), (0, operators_1.tap)(res => this.checkStatus(res.data.status.status)))
56
53
  .subscribe();
57
54
  });
58
55
  }
59
- checkStatus(request) {
56
+ checkStatus(status) {
60
57
  return __awaiter(this, void 0, void 0, function* () {
61
- if (request.status !== 200) {
58
+ if (status !== 200) {
62
59
  yield this.server.stop();
63
- console.error(request);
60
+ console.error(status);
64
61
  process.exit(1);
65
62
  }
66
63
  });
@@ -3,7 +3,7 @@ import { Server, Request, ResponseToolkit } from '@hapi/hapi';
3
3
  import { GRAPHQL_PLUGIN_CONFIG } from '../config.tokens';
4
4
  import { BootstrapService } from '../services/bootstrap.service';
5
5
  import { HookService } from './hooks.service';
6
- export declare class ApolloService implements PluginInterface {
6
+ export declare class GraphqlService implements PluginInterface {
7
7
  private server;
8
8
  private config;
9
9
  private bootstrapService;
@@ -21,7 +21,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
21
21
  });
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.ApolloService = void 0;
24
+ exports.GraphqlService = void 0;
25
25
  const core_1 = require("@rxdi/core");
26
26
  const boom_1 = require("@hapi/boom");
27
27
  const hapi_1 = require("@hapi/hapi");
@@ -30,7 +30,7 @@ const config_tokens_1 = require("../config.tokens");
30
30
  const bootstrap_service_1 = require("../services/bootstrap.service");
31
31
  const hooks_service_1 = require("./hooks.service");
32
32
  const graphql_1 = require("graphql");
33
- let ApolloService = class ApolloService {
33
+ let GraphqlService = class GraphqlService {
34
34
  constructor(server, config, bootstrapService, hookService) {
35
35
  this.server = server;
36
36
  this.config = config;
@@ -168,11 +168,11 @@ let ApolloService = class ApolloService {
168
168
  });
169
169
  }
170
170
  };
171
- exports.ApolloService = ApolloService;
172
- exports.ApolloService = ApolloService = __decorate([
171
+ exports.GraphqlService = GraphqlService;
172
+ exports.GraphqlService = GraphqlService = __decorate([
173
173
  (0, core_1.Service)(),
174
174
  __param(0, (0, core_1.Inject)(hapi_2.HAPI_SERVER)),
175
175
  __param(1, (0, core_1.Inject)(config_tokens_1.GRAPHQL_PLUGIN_CONFIG)),
176
176
  __metadata("design:paramtypes", [hapi_1.Server, Object, bootstrap_service_1.BootstrapService,
177
177
  hooks_service_1.HookService])
178
- ], ApolloService);
178
+ ], GraphqlService);
@@ -17,7 +17,6 @@ const core_1 = require("@rxdi/core");
17
17
  const graphql_1 = require("graphql");
18
18
  const config_tokens_1 = require("../config.tokens");
19
19
  const custom_directive_1 = require("../helpers/directives/custom-directive");
20
- // import { makeExecutableSchema, addMockFunctionsToSchema, mergeSchemas, } from 'graphql-tools';
21
20
  class FieldsModule {
22
21
  }
23
22
  exports.FieldsModule = FieldsModule;
@@ -0,0 +1,19 @@
1
+ export interface GraphQLRequest {
2
+ query: string;
3
+ variables?: Record<string, unknown>;
4
+ operationName?: string;
5
+ }
6
+ export interface GraphQLResponse<TData = unknown> {
7
+ data?: TData;
8
+ errors?: Array<{
9
+ message: string;
10
+ path?: (string | number)[];
11
+ extensions?: Record<string, unknown>;
12
+ }>;
13
+ }
14
+ export declare class GraphQLHttpClient {
15
+ private readonly url;
16
+ private readonly headers;
17
+ constructor(url: string, headers?: Record<string, string>);
18
+ request<TData = unknown>(request: GraphQLRequest): Promise<GraphQLResponse<TData>>;
19
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GraphQLHttpClient = void 0;
13
+ class GraphQLHttpClient {
14
+ constructor(url, headers = {
15
+ 'content-type': 'application/json',
16
+ }) {
17
+ this.url = url;
18
+ this.headers = headers;
19
+ }
20
+ request(request) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const response = yield fetch(this.url, {
23
+ method: 'POST',
24
+ headers: this.headers,
25
+ body: JSON.stringify(request),
26
+ });
27
+ if (!response.ok) {
28
+ const text = yield response.text();
29
+ throw new Error(`GraphQL HTTP error ${response.status}: ${text}`);
30
+ }
31
+ return response.json();
32
+ });
33
+ }
34
+ }
35
+ exports.GraphQLHttpClient = GraphQLHttpClient;
@@ -170,7 +170,7 @@ export type EffectTypes = keyof typeof EffectTypes;
170
170
  result = observable;
171
171
  }
172
172
  else {
173
- result = yield observable.toPromise();
173
+ result = yield (0, rxjs_1.lastValueFrom)(observable);
174
174
  }
175
175
  if (events.map.has(resolver.method_name) ||
176
176
  events.map.has(resolver.effect)) {
@@ -2,7 +2,6 @@ export * from './hooks.service';
2
2
  export * from './apollo.service';
3
3
  export * from './bootstrap.service';
4
4
  export * from './error.service';
5
- export * from './graphiql.service';
6
5
  export * from './hooks.service';
7
6
  export * from './effect.service';
8
- export * from './server-push.service';
7
+ export * from './graphql-http-client';
@@ -18,7 +18,6 @@ __exportStar(require("./hooks.service"), exports);
18
18
  __exportStar(require("./apollo.service"), exports);
19
19
  __exportStar(require("./bootstrap.service"), exports);
20
20
  __exportStar(require("./error.service"), exports);
21
- __exportStar(require("./graphiql.service"), exports);
22
21
  __exportStar(require("./hooks.service"), exports);
23
22
  __exportStar(require("./effect.service"), exports);
24
- __exportStar(require("./server-push.service"), exports);
23
+ __exportStar(require("./graphql-http-client"), exports);
@@ -17,19 +17,8 @@ export declare const DEFAULT_CONFIG: {
17
17
  path: string;
18
18
  initQuery: boolean;
19
19
  buildAstDefinitions: boolean;
20
- openBrowser: boolean;
21
20
  writeEffects: boolean;
22
- graphiql: boolean;
23
- graphiQlPlayground: boolean;
24
- graphiQlPath: string;
25
21
  watcherPort: string;
26
- graphiqlOptions: {
27
- endpointURL: string;
28
- subscriptionsEndpoint: string;
29
- websocketConnectionParams: {
30
- token: string;
31
- };
32
- };
33
22
  graphqlOptions: {
34
23
  schema: any;
35
24
  };
@@ -49,11 +38,7 @@ export declare const setConfigGraphql: (config?: GRAPHQL_PLUGIN_CONFIG) => {
49
38
  disableGlobalGuards?: boolean;
50
39
  directives?: import("graphql").GraphQLDirective[] | any[];
51
40
  buildAstDefinitions: boolean;
52
- graphiQlPlayground: boolean;
53
- graphiql: boolean;
54
- graphiQlPath: string;
55
41
  writeEffects: boolean;
56
- openBrowser: boolean;
57
42
  watcherPort: string | number;
58
43
  authentication?: Function | import("@rxdi/core").InjectionToken<any>;
59
44
  vhost?: string;
@@ -61,14 +46,6 @@ export declare const setConfigGraphql: (config?: GRAPHQL_PLUGIN_CONFIG) => {
61
46
  cors?: boolean;
62
47
  };
63
48
  graphqlOptions: any;
64
- graphiqlOptions: import("apollo-server-module-graphiql").GraphiQLData | {
65
- endpointURL: string;
66
- subscriptionsEndpoint: string;
67
- websocketConnectionParams: {
68
- token: string;
69
- };
70
- };
71
- graphiqlPlaygroundConfig?: import("graphql-playground-html").RenderPageOptions;
72
49
  altair?: {
73
50
  enabled: boolean;
74
51
  options?: import("@rxdi/altair").AltairConfig;
@@ -78,4 +55,4 @@ export declare const startServer: any;
78
55
  export declare const stopServer: () => never;
79
56
  export declare const getServer: () => import("rxjs").Observable<Server<import("@hapi/hapi").ServerApplicationState>>;
80
57
  export declare const getGraphqlSchema: () => import("rxjs").Observable<any>;
81
- export declare const sendRequest: <T = {}>(request: SendRequestQueryType, url?: string) => PromiseLike<import("../../plugin-init").Response<T>>;
58
+ export declare const sendRequest: <T = {}>(request: SendRequestQueryType, url?: string) => Promise<import("../..").GraphQLResponse<T>>;
@@ -18,21 +18,8 @@ exports.DEFAULT_CONFIG = {
18
18
  path: '/graphql',
19
19
  initQuery: true,
20
20
  buildAstDefinitions: true,
21
- openBrowser: false,
22
21
  writeEffects: false,
23
- graphiql: false,
24
- graphiQlPlayground: false,
25
- graphiQlPath: '/graphiql',
26
22
  watcherPort: '',
27
- graphiqlOptions: {
28
- endpointURL: '/graphql',
29
- subscriptionsEndpoint: `${process.env.GRAPHIQL_WS_SSH ? 'wss' : 'ws'}://${process.env.GRAPHIQL_WS_PATH || 'localhost'}${process.env.DEPLOY_PLATFORM === 'heroku'
30
- ? ''
31
- : `:${process.env.API_PORT || process.env.PORT || 9000}`}/subscriptions`,
32
- websocketConnectionParams: {
33
- token: process.env.GRAPHIQL_TOKEN
34
- }
35
- },
36
23
  graphqlOptions: {
37
24
  schema: null
38
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/graphql",
3
- "version": "0.7.198",
3
+ "version": "0.7.199",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rxdi/graphql"
@@ -30,16 +30,13 @@
30
30
  "module": "./dist/index.js",
31
31
  "typings": "./dist/index.d.ts",
32
32
  "dependencies": {
33
- "@gapi/playground": "^1.8.172",
34
- "@rxdi/altair": "^0.7.196",
33
+ "@rxdi/altair": "^0.7.197",
35
34
  "apollo-errors": "1.9.0",
36
- "apollo-server-module-graphiql": "1.4.0",
37
- "@hapi/boom": "^10.0.1",
38
- "graphql-tester": "0.0.5"
35
+ "@hapi/boom": "^10.0.1"
39
36
  },
40
37
  "devDependencies": {
41
- "@rxdi/core": "^0.7.197",
42
- "@rxdi/hapi": "^0.7.197",
38
+ "@rxdi/core": "^0.7.198",
39
+ "@rxdi/hapi": "^0.7.198",
43
40
  "graphql": "^16.12.0",
44
41
  "@types/graphql": "^14.5.0",
45
42
  "@types/jest": "^24.0.22",
@@ -1,11 +0,0 @@
1
- import { PluginInterface } from '@rxdi/core';
2
- import { GRAPHQL_PLUGIN_CONFIG } from '../config.tokens';
3
- import { Request, Server, ResponseToolkit } from '@hapi/hapi';
4
- export declare class GraphiQLService implements PluginInterface {
5
- private server;
6
- private config;
7
- constructor(server: Server, config: GRAPHQL_PLUGIN_CONFIG);
8
- OnInit(): void;
9
- register(): Promise<void>;
10
- handler: (request: Request, h: ResponseToolkit, err?: Error) => Promise<import("@hapi/hapi").ResponseObject>;
11
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.GraphiQLService = void 0;
25
- const core_1 = require("@rxdi/core");
26
- const hapi_1 = require("@rxdi/hapi");
27
- const config_tokens_1 = require("../config.tokens");
28
- const hapi_2 = require("@hapi/hapi");
29
- const GraphiQL = require("apollo-server-module-graphiql");
30
- let GraphiQLService = class GraphiQLService {
31
- constructor(server, config) {
32
- this.server = server;
33
- this.config = config;
34
- this.handler = (request, h, err) => __awaiter(this, void 0, void 0, function* () {
35
- const graphiqlString = yield GraphiQL.resolveGraphiQLString(request['query'], this.config.graphiqlOptions, request);
36
- const response = h.response(graphiqlString);
37
- response.type('text/html');
38
- return response;
39
- });
40
- }
41
- OnInit() {
42
- if (!this.config || !this.config.graphiqlOptions) {
43
- throw new Error('Apollo Server GraphiQL requires options.');
44
- }
45
- this.register();
46
- }
47
- register() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- if (this.config.graphiql) {
50
- this.server.route({
51
- method: 'GET',
52
- path: this.config.graphiQlPath || '/graphiql',
53
- options: this.config.route,
54
- handler: this.handler
55
- });
56
- }
57
- });
58
- }
59
- };
60
- exports.GraphiQLService = GraphiQLService;
61
- exports.GraphiQLService = GraphiQLService = __decorate([
62
- (0, core_1.Service)(),
63
- __param(0, (0, core_1.Inject)(hapi_1.HAPI_SERVER)),
64
- __param(1, (0, core_1.Inject)(config_tokens_1.GRAPHQL_PLUGIN_CONFIG)),
65
- __metadata("design:paramtypes", [hapi_2.Server, Object])
66
- ], GraphiQLService);
@@ -1,24 +0,0 @@
1
- import { PluginInterface, ExitHandlerService, AfterStarterService } from '@rxdi/core';
2
- import { GRAPHQL_PLUGIN_CONFIG } from '../config.tokens';
3
- import { Server, IncomingMessage, ServerResponse } from 'http';
4
- import { Server as HapiServer } from '@hapi/hapi';
5
- import { Subject, Observable } from 'rxjs';
6
- import { StartService } from './start.service';
7
- export declare class ServerPushPlugin implements PluginInterface {
8
- private config;
9
- private server;
10
- private exitHandler;
11
- private afterStarterService;
12
- private startService;
13
- serverWatcher: Server;
14
- connected: boolean;
15
- sendToClient: Subject<any>;
16
- sendTime: Subject<boolean>;
17
- clientConnected: Subject<boolean>;
18
- constructor(config: GRAPHQL_PLUGIN_CONFIG, server: HapiServer, exitHandler: ExitHandlerService, afterStarterService: AfterStarterService, startService: StartService);
19
- waitXSeconds(sec: any): Observable<any>;
20
- register(): Promise<void>;
21
- stopServerWatcher(): Promise<unknown>;
22
- createServerWatcher(): void;
23
- OnRequest(req: IncomingMessage, res: ServerResponse): ServerResponse<IncomingMessage>;
24
- }
@@ -1,131 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.ServerPushPlugin = void 0;
25
- const core_1 = require("@rxdi/core");
26
- const config_tokens_1 = require("../config.tokens");
27
- const http_1 = require("http");
28
- const hapi_1 = require("@hapi/hapi");
29
- const hapi_2 = require("@rxdi/hapi");
30
- const rxjs_1 = require("rxjs");
31
- const operators_1 = require("rxjs/operators");
32
- const start_service_1 = require("./start.service");
33
- let ServerPushPlugin = class ServerPushPlugin {
34
- constructor(config, server, exitHandler, afterStarterService, startService) {
35
- this.config = config;
36
- this.server = server;
37
- this.exitHandler = exitHandler;
38
- this.afterStarterService = afterStarterService;
39
- this.startService = startService;
40
- this.sendToClient = new rxjs_1.Subject();
41
- this.sendTime = new rxjs_1.Subject();
42
- this.clientConnected = new rxjs_1.Subject();
43
- this.exitHandler.errorHandler.subscribe((e) => __awaiter(this, void 0, void 0, function* () { return yield this.stopServerWatcher(); }));
44
- this.server.events.on('response', request => this.sendToClient.next({
45
- query: request.payload,
46
- response: request.response['source']
47
- }));
48
- (0, rxjs_1.timer)(0, 1000)
49
- .pipe((0, operators_1.tap)(() => this.sendTime.next(true)))
50
- .subscribe();
51
- this.afterStarterService.appStarted
52
- .pipe((0, operators_1.timeout)(5000), (0, operators_1.take)(1), (0, operators_1.filter)(() => !this.connected), (0, operators_1.filter)(() => this.config.openBrowser), (0, operators_1.tap)(() => this.startService.startBrowser()))
53
- .subscribe();
54
- }
55
- waitXSeconds(sec) {
56
- return rxjs_1.Observable.create(o => {
57
- const timeout = setTimeout(() => o.next(true), sec * 1000);
58
- return () => clearTimeout(timeout);
59
- });
60
- }
61
- register() {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- if (this.config.openBrowser) {
64
- this.createServerWatcher();
65
- this.server.route({
66
- method: 'GET',
67
- path: '/devtools/{param*}',
68
- handler: {
69
- directory: {
70
- path: `${__dirname.replace('dist/services', '')}/public`,
71
- index: ['index.html', 'default.html']
72
- }
73
- }
74
- });
75
- }
76
- });
77
- }
78
- stopServerWatcher() {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- return yield new Promise(resolve => this.serverWatcher.close(resolve));
81
- });
82
- }
83
- createServerWatcher() {
84
- this.serverWatcher = (0, http_1.createServer)(this.OnRequest.bind(this));
85
- this.serverWatcher.listen(this.config.watcherPort || 8967);
86
- }
87
- OnRequest(req, res) {
88
- if (req.url === '/status') {
89
- if (!this.connected) {
90
- this.clientConnected.next(true);
91
- res.write('data: ' + JSON.stringify({ response: { init: true } }) + '\n\n');
92
- }
93
- this.connected = true;
94
- res.writeHead(200, {
95
- 'Content-Type': 'text/event-stream',
96
- 'Access-Control-Allow-Origin': '*',
97
- 'Cache-Control': 'no-cache',
98
- Connection: 'keep-alive'
99
- });
100
- this.sendToClient.subscribe(data => res.write('data: ' + JSON.stringify(data) + '\n\n'));
101
- this.sendTime.subscribe(() => res.write('data: ' +
102
- JSON.stringify({ time: new Date().toLocaleTimeString() }) +
103
- '\n\n'));
104
- this.sendTime.subscribe(() => res.write('data: ' +
105
- JSON.stringify({
106
- config: {
107
- graphql: Object.assign(Object.assign({}, this.config), { graphqlOptions: null }),
108
- hapi: this.server.info
109
- }
110
- }) +
111
- '\n\n'));
112
- req.on('end', () => {
113
- this.connected = false;
114
- req.destroy();
115
- });
116
- return;
117
- }
118
- res.statusCode = 400;
119
- return res.end();
120
- }
121
- };
122
- exports.ServerPushPlugin = ServerPushPlugin;
123
- exports.ServerPushPlugin = ServerPushPlugin = __decorate([
124
- (0, core_1.Plugin)(),
125
- __param(0, (0, core_1.Inject)(config_tokens_1.GRAPHQL_PLUGIN_CONFIG)),
126
- __param(1, (0, core_1.Inject)(hapi_2.HAPI_SERVER)),
127
- __metadata("design:paramtypes", [Object, hapi_1.Server,
128
- core_1.ExitHandlerService,
129
- core_1.AfterStarterService,
130
- start_service_1.StartService])
131
- ], ServerPushPlugin);
@@ -1,6 +0,0 @@
1
- import { BootstrapLogger } from '@rxdi/core';
2
- export declare class StartService {
3
- private logger;
4
- constructor(logger: BootstrapLogger);
5
- startBrowser(): void;
6
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.StartService = void 0;
13
- const core_1 = require("@rxdi/core");
14
- let StartService = class StartService {
15
- constructor(logger) {
16
- this.logger = logger;
17
- }
18
- startBrowser() {
19
- this.logger.log('Browser started!');
20
- }
21
- };
22
- exports.StartService = StartService;
23
- exports.StartService = StartService = __decorate([
24
- (0, core_1.Service)(),
25
- __metadata("design:paramtypes", [core_1.BootstrapLogger])
26
- ], StartService);