@rsdk/graphql 1.0.3 → 1.0.5
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/CHANGELOG.md +8 -0
- package/dist/graphql.plugin.d.ts +12 -2
- package/dist/graphql.plugin.js +52 -44
- package/dist/graphql.plugin.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/graphql.plugin.ts +85 -51
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.0.5 (2023-05-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rsdk/graphql
|
|
9
|
+
|
|
10
|
+
## 1.0.4 (2023-05-10)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @rsdk/graphql
|
|
13
|
+
|
|
6
14
|
## 1.0.3 (2023-05-10)
|
|
7
15
|
|
|
8
16
|
### Bug Fixes
|
package/dist/graphql.plugin.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
2
|
import type { IErrorsFormatter, IErrorsSender, PlatformAppPlugin } from '@rsdk/core';
|
|
3
|
-
export
|
|
3
|
+
export type Approach = 'schema-first' | 'code-first';
|
|
4
|
+
export interface GraphQLPluginOptions<T extends Approach> {
|
|
5
|
+
approach: T;
|
|
4
6
|
path?: string;
|
|
5
7
|
middleware?: Function[];
|
|
6
8
|
}
|
|
9
|
+
export interface GraphQLPluginSchemaFirstOptions extends GraphQLPluginOptions<'schema-first'> {
|
|
10
|
+
typePaths: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const isSchemaFirst: (options: GraphQLPluginOptions<Approach>) => options is GraphQLPluginSchemaFirstOptions;
|
|
13
|
+
export interface GraphQLPluginCodeFirstOptions extends GraphQLPluginOptions<'code-first'> {
|
|
14
|
+
autoSchemaFile: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const isCodeFirst: (options: GraphQLPluginOptions<Approach>) => options is GraphQLPluginCodeFirstOptions;
|
|
7
17
|
export declare class GraphQLPlugin implements PlatformAppPlugin {
|
|
8
18
|
private readonly options;
|
|
9
19
|
private readonly path;
|
|
10
|
-
constructor(options
|
|
20
|
+
constructor(options: GraphQLPluginCodeFirstOptions | GraphQLPluginSchemaFirstOptions);
|
|
11
21
|
forTransports(): Readonly<string[]>;
|
|
12
22
|
modules(): any[];
|
|
13
23
|
configureMiddleware(consumer: MiddlewareConsumer): void;
|
package/dist/graphql.plugin.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GraphQLPlugin = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
3
|
+
exports.GraphQLPlugin = exports.isCodeFirst = exports.isSchemaFirst = void 0;
|
|
5
4
|
const apollo_1 = require("@nestjs/apollo");
|
|
6
5
|
const graphql_1 = require("@nestjs/graphql");
|
|
7
6
|
const core_1 = require("@rsdk/core");
|
|
@@ -19,10 +18,14 @@ const onConnect = (connectionParams) => {
|
|
|
19
18
|
}
|
|
20
19
|
return { req: { ...out, headers } };
|
|
21
20
|
};
|
|
21
|
+
const isSchemaFirst = (options) => options.approach === 'schema-first';
|
|
22
|
+
exports.isSchemaFirst = isSchemaFirst;
|
|
23
|
+
const isCodeFirst = (options) => options.approach === 'code-first';
|
|
24
|
+
exports.isCodeFirst = isCodeFirst;
|
|
22
25
|
class GraphQLPlugin {
|
|
23
26
|
options;
|
|
24
27
|
path;
|
|
25
|
-
constructor(options
|
|
28
|
+
constructor(options) {
|
|
26
29
|
this.options = options;
|
|
27
30
|
this.path = options.path || '/graphql';
|
|
28
31
|
if (!this.path.startsWith('/')) {
|
|
@@ -33,52 +36,57 @@ class GraphQLPlugin {
|
|
|
33
36
|
return ['http'];
|
|
34
37
|
}
|
|
35
38
|
modules() {
|
|
36
|
-
const config = core_1.PlatformConfigModule.resolve(graphql_config_1.GraphQLConfig);
|
|
37
|
-
/**
|
|
38
|
-
* FIXME: В целом объект настроек взят из TDP с небольшими изменениями.
|
|
39
|
-
* Смысл некоторых настроек ен совсем понятен. Нужно разобраться, когда
|
|
40
|
-
* будем делать schema-first
|
|
41
|
-
*/
|
|
42
39
|
return [
|
|
43
|
-
graphql_1.GraphQLModule.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
buildSchemaOptions: {
|
|
47
|
-
numberScalarMode: 'integer',
|
|
48
|
-
},
|
|
49
|
-
// Что это?
|
|
50
|
-
context: ({ req, connection }) => ({ req: req ?? connection.context }),
|
|
40
|
+
graphql_1.GraphQLModule.forRootAsync({
|
|
41
|
+
imports: [core_1.PlatformConfigModule.forFeature(graphql_config_1.GraphQLConfig)],
|
|
42
|
+
inject: [graphql_config_1.GraphQLConfig],
|
|
51
43
|
driver: apollo_1.ApolloDriver,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
44
|
+
useFactory: (config) => ({
|
|
45
|
+
path: this.path,
|
|
46
|
+
...((0, exports.isCodeFirst)(this.options) && {
|
|
47
|
+
autoSchemaFile: this.options.autoSchemaFile ?? 'schema.graqhql',
|
|
48
|
+
buildSchemaOptions: {
|
|
49
|
+
numberScalarMode: 'integer',
|
|
50
|
+
},
|
|
51
|
+
sortSchema: true,
|
|
52
|
+
}),
|
|
53
|
+
...((0, exports.isSchemaFirst)(this.options) && {
|
|
54
|
+
typePaths: this.options.typePaths,
|
|
55
|
+
}),
|
|
56
|
+
// Что это?
|
|
57
|
+
context: ({ req, connection }) => ({
|
|
58
|
+
req: req ?? connection.context,
|
|
59
|
+
}),
|
|
60
|
+
fieldResolverEnhancers: ['filters'],
|
|
61
|
+
formatError: error_handling_1.GraphQLErrorsFormatter.finalFormat,
|
|
62
|
+
logger: new apollo_logger_adapter_1.ApolloLoggerAdapter(logging_1.LoggerFactory.create('Apollo')),
|
|
63
|
+
installSubscriptionHandlers: true,
|
|
64
|
+
introspection: config.playground,
|
|
65
|
+
playground: config.playground
|
|
66
|
+
? {
|
|
67
|
+
endpoint: this.path,
|
|
68
|
+
subscriptionEndpoint: this.path,
|
|
69
|
+
}
|
|
70
|
+
: false,
|
|
71
|
+
subscriptions: {
|
|
72
|
+
'graphql-ws': {
|
|
74
73
|
onConnect,
|
|
75
74
|
path: this.path,
|
|
76
75
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
// Этот вариант нужен (пока - на 23.02.2023) только для поддержки
|
|
77
|
+
// playground. Вероятно, при переходе на Apollo 4 надобность в
|
|
78
|
+
// этом отпадёты
|
|
79
|
+
...(config.playground && {
|
|
80
|
+
'subscriptions-transport-ws': {
|
|
81
|
+
onConnect,
|
|
82
|
+
path: this.path,
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
useGlobalPrefix: true,
|
|
87
|
+
// https://github.com/nestjs/graphql/issues/295#issuecomment-511191060
|
|
88
|
+
// directiveResolvers: ['interceptors'],
|
|
89
|
+
}),
|
|
82
90
|
}),
|
|
83
91
|
];
|
|
84
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;AACA,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