@rsdk/graphql 0.14.0
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/.eslintignore +4 -0
- package/.eslintrc.js +4 -0
- package/.prettierignore +1 -0
- package/.prettierrc.json +1 -0
- package/dist/apollo-logger.adapter.d.ts +10 -0
- package/dist/apollo-logger.adapter.js +23 -0
- package/dist/apollo-logger.adapter.js.map +1 -0
- package/dist/error-handling/graphql-errors.formatter.d.ts +17 -0
- package/dist/error-handling/graphql-errors.formatter.js +69 -0
- package/dist/error-handling/graphql-errors.formatter.js.map +1 -0
- package/dist/error-handling/graphql-errors.sender.d.ts +7 -0
- package/dist/error-handling/graphql-errors.sender.js +14 -0
- package/dist/error-handling/graphql-errors.sender.js.map +1 -0
- package/dist/error-handling/index.d.ts +2 -0
- package/dist/error-handling/index.js +19 -0
- package/dist/error-handling/index.js.map +1 -0
- package/dist/graphql.config.d.ts +4 -0
- package/dist/graphql.config.js +28 -0
- package/dist/graphql.config.js.map +1 -0
- package/dist/graphql.plugin.d.ts +16 -0
- package/dist/graphql.plugin.js +98 -0
- package/dist/graphql.plugin.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +42 -0
- package/src/apollo-logger.adapter.ts +22 -0
- package/src/error-handling/graphql-errors.formatter.ts +82 -0
- package/src/error-handling/graphql-errors.sender.ts +14 -0
- package/src/error-handling/index.ts +2 -0
- package/src/graphql.config.ts +10 -0
- package/src/graphql.plugin.ts +122 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +9 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
**/*.spec.ts
|
package/.prettierrc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"@rsdk/prettier-config"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Logger } from '@apollo/utils.logger';
|
|
2
|
+
import type { ILogger } from '@rsdk/logging';
|
|
3
|
+
export declare class ApolloLoggerAdapter implements Logger {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
constructor(logger: ILogger);
|
|
6
|
+
debug(message?: any): void;
|
|
7
|
+
info(message?: any): void;
|
|
8
|
+
warn(message?: any): void;
|
|
9
|
+
error(message?: any): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApolloLoggerAdapter = void 0;
|
|
4
|
+
class ApolloLoggerAdapter {
|
|
5
|
+
logger;
|
|
6
|
+
constructor(logger) {
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
debug(message) {
|
|
10
|
+
this.logger.debug(message);
|
|
11
|
+
}
|
|
12
|
+
info(message) {
|
|
13
|
+
this.logger.info(message);
|
|
14
|
+
}
|
|
15
|
+
warn(message) {
|
|
16
|
+
this.logger.warn(message);
|
|
17
|
+
}
|
|
18
|
+
error(message) {
|
|
19
|
+
this.logger.error(message);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ApolloLoggerAdapter = ApolloLoggerAdapter;
|
|
23
|
+
//# sourceMappingURL=apollo-logger.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-logger.adapter.js","sourceRoot":"","sources":["../src/apollo-logger.adapter.ts"],"names":[],"mappings":";;;AAGA,MAAa,mBAAmB;IACD;IAA7B,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD,KAAK,CAAC,OAAa;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,OAAa;QAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC,OAAa;QAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAa;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;CACF;AAlBD,kDAkBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { IErrorsFormatter } from '@rsdk/core';
|
|
3
|
+
import type { GraphQLFormattedError } from 'graphql';
|
|
4
|
+
import { GraphQLError } from 'graphql';
|
|
5
|
+
/**
|
|
6
|
+
* Форматирование ошибок происходит в 2 этапа:
|
|
7
|
+
* 1) в GlobalExceptionFilter при помощи данного форматтера. На этом этапе в extentions
|
|
8
|
+
* кладётся вся необходимая информация в зависимости от параметра VERBOSE_ERRORS.
|
|
9
|
+
* 2) во встроенном в Apollo обработчике formatError (finalFormat) - там происходит удаление
|
|
10
|
+
* лишних данных (которые apollo неизбежно добавляет уже после обработки ошибки
|
|
11
|
+
* в ErrorsFormatter) и нормализация объектов.
|
|
12
|
+
*/
|
|
13
|
+
export declare class GraphQLErrorsFormatter implements IErrorsFormatter {
|
|
14
|
+
static finalFormat(formattedError: GraphQLFormattedError, error: unknown): GraphQLFormattedError;
|
|
15
|
+
match(host: ArgumentsHost): boolean;
|
|
16
|
+
format(ex: unknown, verbose?: boolean): GraphQLError;
|
|
17
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLErrorsFormatter = void 0;
|
|
4
|
+
const common_1 = require("@rsdk/common");
|
|
5
|
+
const core_1 = require("@rsdk/core");
|
|
6
|
+
const graphql_1 = require("graphql");
|
|
7
|
+
const ALWAYS_VERBOSE = [core_1.ExceptionKind.INPUT];
|
|
8
|
+
const DEFAULT_MESSAGE = 'Something went wrong';
|
|
9
|
+
/**
|
|
10
|
+
* Форматирование ошибок происходит в 2 этапа:
|
|
11
|
+
* 1) в GlobalExceptionFilter при помощи данного форматтера. На этом этапе в extentions
|
|
12
|
+
* кладётся вся необходимая информация в зависимости от параметра VERBOSE_ERRORS.
|
|
13
|
+
* 2) во встроенном в Apollo обработчике formatError (finalFormat) - там происходит удаление
|
|
14
|
+
* лишних данных (которые apollo неизбежно добавляет уже после обработки ошибки
|
|
15
|
+
* в ErrorsFormatter) и нормализация объектов.
|
|
16
|
+
*/
|
|
17
|
+
class GraphQLErrorsFormatter {
|
|
18
|
+
static finalFormat(formattedError,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
error) {
|
|
21
|
+
delete formattedError.extensions?.exception;
|
|
22
|
+
return {
|
|
23
|
+
message: formattedError.message,
|
|
24
|
+
...(formattedError.path && {
|
|
25
|
+
path: formattedError.path,
|
|
26
|
+
}),
|
|
27
|
+
...(formattedError.locations && {
|
|
28
|
+
locations: formattedError.locations,
|
|
29
|
+
}),
|
|
30
|
+
extensions: (0, common_1.normalizer)()(formattedError.extensions, {
|
|
31
|
+
// This means stacktrace will never be sent to user
|
|
32
|
+
filterKeys: ['stack'],
|
|
33
|
+
sortKeys: common_1.sortErrorKeys,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
match(host) {
|
|
38
|
+
return host.getType() === 'graphql';
|
|
39
|
+
}
|
|
40
|
+
format(ex, verbose) {
|
|
41
|
+
if (ex instanceof core_1.PipelineException) {
|
|
42
|
+
const formatVerbose = verbose || ALWAYS_VERBOSE.includes(ex.kind);
|
|
43
|
+
const { kind, code, details, cause } = ex;
|
|
44
|
+
const message = formatVerbose
|
|
45
|
+
? [ex.message, ...core_1.PipelineException.innerMessages(ex)].join(' > ')
|
|
46
|
+
: DEFAULT_MESSAGE;
|
|
47
|
+
return new graphql_1.GraphQLError(message, {
|
|
48
|
+
extensions: {
|
|
49
|
+
kind: core_1.ExceptionKind[kind],
|
|
50
|
+
code,
|
|
51
|
+
/**
|
|
52
|
+
* We don't normalize object here because it fill be normalized
|
|
53
|
+
* in formatError method of apollo server
|
|
54
|
+
*/
|
|
55
|
+
...(verbose && {
|
|
56
|
+
cause,
|
|
57
|
+
details,
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const message = verbose
|
|
63
|
+
? ex.message ?? JSON.stringify(ex)
|
|
64
|
+
: DEFAULT_MESSAGE;
|
|
65
|
+
return new graphql_1.GraphQLError(message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.GraphQLErrorsFormatter = GraphQLErrorsFormatter;
|
|
69
|
+
//# sourceMappingURL=graphql-errors.formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-errors.formatter.js","sourceRoot":"","sources":["../../src/error-handling/graphql-errors.formatter.ts"],"names":[],"mappings":";;;AACA,yCAAyD;AAEzD,qCAA8D;AAE9D,qCAAuC;AAEvC,MAAM,cAAc,GAAG,CAAC,oBAAa,CAAC,KAAK,CAAC,CAAC;AAC7C,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAa,sBAAsB;IACjC,MAAM,CAAC,WAAW,CAChB,cAAqC;IACrC,6DAA6D;IAC7D,KAAc;QAEd,OAAO,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC;QAE5C,OAAO;YACL,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,GAAG,CAAC,cAAc,CAAC,IAAI,IAAI;gBACzB,IAAI,EAAE,cAAc,CAAC,IAAI;aAC1B,CAAC;YAEF,GAAG,CAAC,cAAc,CAAC,SAAS,IAAI;gBAC9B,SAAS,EAAE,cAAc,CAAC,SAAS;aACpC,CAAC;YAEF,UAAU,EAAE,IAAA,mBAAU,GAAE,CAAC,cAAc,CAAC,UAAU,EAA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type { Observable } from 'rxjs';
|
|
4
|
+
export declare class GraphQLErrorsSender implements IErrorsSender {
|
|
5
|
+
match(host: ArgumentsHost): boolean;
|
|
6
|
+
send(host: ArgumentsHost, ex: unknown): Observable<never>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLErrorsSender = void 0;
|
|
4
|
+
class GraphQLErrorsSender {
|
|
5
|
+
match(host) {
|
|
6
|
+
return host.getType() === 'graphql';
|
|
7
|
+
}
|
|
8
|
+
send(host, ex) {
|
|
9
|
+
// Only throwing will provision exception data to apollo-server
|
|
10
|
+
throw ex;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.GraphQLErrorsSender = GraphQLErrorsSender;
|
|
14
|
+
//# sourceMappingURL=graphql-errors.sender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-errors.sender.js","sourceRoot":"","sources":["../../src/error-handling/graphql-errors.sender.ts"],"names":[],"mappings":";;;AAIA,MAAa,mBAAmB;IAC9B,KAAK,CAAC,IAAmB;QACvB,OAAO,IAAI,CAAC,OAAO,EAAa,KAAK,SAAS,CAAC;IACjD,CAAC;IAED,IAAI,CAAC,IAAmB,EAAE,EAAW;QACnC,+DAA+D;QAC/D,MAAM,EAAE,CAAC;IACX,CAAC;CACF;AATD,kDASC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./graphql-errors.formatter"), exports);
|
|
18
|
+
__exportStar(require("./graphql-errors.sender"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error-handling/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,0DAAwC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.GraphQLConfig = void 0;
|
|
13
|
+
const core_1 = require("@rsdk/core");
|
|
14
|
+
let GraphQLConfig = class GraphQLConfig extends core_1.Config {
|
|
15
|
+
playground;
|
|
16
|
+
};
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, core_1.Property)('GRAPHQL_ENABLE_PLAYGROUND', new core_1.BoolParser(), {
|
|
19
|
+
defaultValue: false,
|
|
20
|
+
description: 'Enables GraphQL playground and introspection',
|
|
21
|
+
}),
|
|
22
|
+
__metadata("design:type", Boolean)
|
|
23
|
+
], GraphQLConfig.prototype, "playground", void 0);
|
|
24
|
+
GraphQLConfig = __decorate([
|
|
25
|
+
(0, core_1.ConfigSection)()
|
|
26
|
+
], GraphQLConfig);
|
|
27
|
+
exports.GraphQLConfig = GraphQLConfig;
|
|
28
|
+
//# sourceMappingURL=graphql.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.config.js","sourceRoot":"","sources":["../src/graphql.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAyE;AAGlE,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,aAAM;IAKvC,UAAU,CAAW;CACtB,CAAA;AALC;IAAC,IAAA,eAAQ,EAAC,2BAA2B,EAAE,IAAI,iBAAU,EAAE,EAAE;QACvD,YAAY,EAAE,KAAK;QACnB,WAAW,EAAE,8CAA8C;KAC5D,CAAC;;iDACmB;AALV,aAAa;IADzB,IAAA,oBAAa,GAAE;GACH,aAAa,CAMzB;AANY,sCAAa"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
+
import type { IErrorsFormatter, IErrorsSender, PlatformAppPlugin } from '@rsdk/core';
|
|
3
|
+
export interface GraphQLPluginOptions {
|
|
4
|
+
path?: string;
|
|
5
|
+
middleware?: Function[];
|
|
6
|
+
}
|
|
7
|
+
export declare class GraphQLPlugin implements PlatformAppPlugin {
|
|
8
|
+
private readonly options;
|
|
9
|
+
private readonly path;
|
|
10
|
+
constructor(options?: GraphQLPluginOptions);
|
|
11
|
+
forTransports(): Readonly<string[]>;
|
|
12
|
+
modules(): any[];
|
|
13
|
+
configureMiddleware(consumer: MiddlewareConsumer): void;
|
|
14
|
+
errorFormatter(): IErrorsFormatter;
|
|
15
|
+
errorSender(): IErrorsSender;
|
|
16
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLPlugin = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const apollo_1 = require("@nestjs/apollo");
|
|
6
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
7
|
+
const core_1 = require("@rsdk/core");
|
|
8
|
+
const logging_1 = require("@rsdk/logging");
|
|
9
|
+
const apollo_logger_adapter_1 = require("./apollo-logger.adapter");
|
|
10
|
+
const error_handling_1 = require("./error-handling");
|
|
11
|
+
const graphql_config_1 = require("./graphql.config");
|
|
12
|
+
const onConnect = (connectionParams) => {
|
|
13
|
+
const out = connectionParams ?? {};
|
|
14
|
+
const headers = out.headers ?? {};
|
|
15
|
+
// workaround for playground
|
|
16
|
+
if (connectionParams?.Authorization || connectionParams?.authorization) {
|
|
17
|
+
headers.authorization =
|
|
18
|
+
connectionParams?.Authorization || connectionParams?.authorization;
|
|
19
|
+
}
|
|
20
|
+
return { req: { ...out, headers } };
|
|
21
|
+
};
|
|
22
|
+
class GraphQLPlugin {
|
|
23
|
+
options;
|
|
24
|
+
path;
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.path = options.path || '/graphql';
|
|
28
|
+
if (!this.path.startsWith('/')) {
|
|
29
|
+
this.path = '/' + this.path;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
forTransports() {
|
|
33
|
+
return ['http'];
|
|
34
|
+
}
|
|
35
|
+
modules() {
|
|
36
|
+
const config = core_1.PlatformConfigModule.resolve(graphql_config_1.GraphQLConfig);
|
|
37
|
+
/**
|
|
38
|
+
* FIXME: В целом объект настроек взят из TDP с небольшими изменениями.
|
|
39
|
+
* Смысл некоторых настроек ен совсем понятен. Нужно разобраться, когда
|
|
40
|
+
* будем делать schema-first
|
|
41
|
+
*/
|
|
42
|
+
return [
|
|
43
|
+
graphql_1.GraphQLModule.forRoot({
|
|
44
|
+
path: this.path,
|
|
45
|
+
autoSchemaFile: (0, path_1.join)('schema.gql'),
|
|
46
|
+
buildSchemaOptions: {
|
|
47
|
+
numberScalarMode: 'integer',
|
|
48
|
+
},
|
|
49
|
+
// Что это?
|
|
50
|
+
context: ({ req, connection }) => ({ req: req ?? connection.context }),
|
|
51
|
+
driver: apollo_1.ApolloDriver,
|
|
52
|
+
fieldResolverEnhancers: ['filters'],
|
|
53
|
+
formatError: error_handling_1.GraphQLErrorsFormatter.finalFormat,
|
|
54
|
+
sortSchema: true,
|
|
55
|
+
logger: new apollo_logger_adapter_1.ApolloLoggerAdapter(logging_1.LoggerFactory.create('Apollo')),
|
|
56
|
+
installSubscriptionHandlers: true,
|
|
57
|
+
introspection: config.playground,
|
|
58
|
+
playground: config.playground
|
|
59
|
+
? {
|
|
60
|
+
endpoint: this.path,
|
|
61
|
+
subscriptionEndpoint: this.path,
|
|
62
|
+
}
|
|
63
|
+
: false,
|
|
64
|
+
subscriptions: {
|
|
65
|
+
'graphql-ws': {
|
|
66
|
+
onConnect,
|
|
67
|
+
path: this.path,
|
|
68
|
+
},
|
|
69
|
+
// Этот вариант нужен (пока - на 23.02.2023) только для поддержки
|
|
70
|
+
// playground. Вероятно, при переходе на Apollo 4 надобность в
|
|
71
|
+
// этом отпадёты
|
|
72
|
+
...(config.playground && {
|
|
73
|
+
'subscriptions-transport-ws': {
|
|
74
|
+
onConnect,
|
|
75
|
+
path: this.path,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
useGlobalPrefix: true,
|
|
80
|
+
// https://github.com/nestjs/graphql/issues/295#issuecomment-511191060
|
|
81
|
+
// directiveResolvers: ['interceptors'],
|
|
82
|
+
}),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
configureMiddleware(consumer) {
|
|
86
|
+
for (const middleware of this.options.middleware || []) {
|
|
87
|
+
consumer.apply(middleware).forRoutes(this.path);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
errorFormatter() {
|
|
91
|
+
return new error_handling_1.GraphQLErrorsFormatter();
|
|
92
|
+
}
|
|
93
|
+
errorSender() {
|
|
94
|
+
return new error_handling_1.GraphQLErrorsSender();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.GraphQLPlugin = GraphQLPlugin;
|
|
98
|
+
//# sourceMappingURL=graphql.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAG5B,2CAA8C;AAE9C,6CAAgD;AAMhD,qCAAkD;AAClD,2CAA8C;AAE9C,mEAA8D;AAC9D,qDAA+E;AAC/E,qDAAiD;AAEjD,MAAM,SAAS,GAAG,CAAC,gBAAqB,EAAO,EAAE;IAC/C,MAAM,GAAG,GAAG,gBAAgB,IAAI,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;IAElC,4BAA4B;IAC5B,IAAI,gBAAgB,EAAE,aAAa,IAAI,gBAAgB,EAAE,aAAa,EAAE;QACtE,OAAO,CAAC,aAAa;YACnB,gBAAgB,EAAE,aAAa,IAAI,gBAAgB,EAAE,aAAa,CAAC;KACtE;IAED,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;AACtC,CAAC,CAAC;AAQF,MAAa,aAAa;IAGK;IAFZ,IAAI,CAAS;IAE9B,YAA6B,UAAgC,EAAE;QAAlC,YAAO,GAAP,OAAO,CAA2B;QAC7D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,UAAU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BAC9D,gBAAgB;oBAChB,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI;wBACvB,4BAA4B,EAAE;4BAC5B,SAAS;4BACT,IAAI,EAAE,IAAI,CAAC,IAAI;yBAChB;qBACF,CAAC;iBACH;gBACD,eAAe,EAAE,IAAI;gBACrB,sEAAsE;gBACtE,wCAAwC;aACzC,CAAC;SACH,CAAC;IACJ,CAAC;IAED,mBAAmB,CAAC,QAA4B;QAC9C,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE;YACtD,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACjD;IACH,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,uCAAsB,EAAE,CAAC;IACtC,CAAC;IAED,WAAW;QACT,OAAO,IAAI,oCAAmB,EAAE,CAAC;IACnC,CAAC;CACF;AApFD,sCAoFC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './graphql.plugin';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./graphql.plugin"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
|