@nestjs/apollo 9.2.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/CHANGELOG.md +22 -0
- package/LICENSE +22 -0
- package/README.md +57 -0
- package/dist/apollo.constants.d.ts +2 -0
- package/dist/apollo.constants.d.ts.map +1 -0
- package/dist/apollo.constants.js +4 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +4 -0
- package/dist/decorators/plugin.decorator.d.ts +5 -0
- package/dist/decorators/plugin.decorator.d.ts.map +1 -0
- package/dist/decorators/plugin.decorator.js +14 -0
- package/dist/drivers/apollo-base.driver.d.ts +21 -0
- package/dist/drivers/apollo-base.driver.d.ts.map +1 -0
- package/dist/drivers/apollo-base.driver.js +169 -0
- package/dist/drivers/apollo-federation.driver.d.ts +12 -0
- package/dist/drivers/apollo-federation.driver.d.ts.map +1 -0
- package/dist/drivers/apollo-federation.driver.js +45 -0
- package/dist/drivers/apollo-gateway.driver.d.ts +6 -0
- package/dist/drivers/apollo-gateway.driver.d.ts.map +1 -0
- package/dist/drivers/apollo-gateway.driver.js +22 -0
- package/dist/drivers/apollo.driver.d.ts +12 -0
- package/dist/drivers/apollo.driver.d.ts.map +1 -0
- package/dist/drivers/apollo.driver.js +58 -0
- package/dist/drivers/index.d.ts +4 -0
- package/dist/drivers/index.d.ts.map +1 -0
- package/dist/drivers/index.js +6 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/interfaces/apollo-driver-config.interface.d.ts +52 -0
- package/dist/interfaces/apollo-driver-config.interface.d.ts.map +1 -0
- package/dist/interfaces/apollo-driver-config.interface.js +2 -0
- package/dist/interfaces/apollo-gateway-driver-config.interface.d.ts +9 -0
- package/dist/interfaces/apollo-gateway-driver-config.interface.d.ts.map +1 -0
- package/dist/interfaces/apollo-gateway-driver-config.interface.js +2 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +5 -0
- package/dist/services/plugins-explorer.service.d.ts +11 -0
- package/dist/services/plugins-explorer.service.d.ts.map +1 -0
- package/dist/services/plugins-explorer.service.js +24 -0
- package/dist/utils/get-apollo-server.d.ts +9 -0
- package/dist/utils/get-apollo-server.d.ts.map +1 -0
- package/dist/utils/get-apollo-server.js +19 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/package.json +64 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 9.2.0 (2022-01-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* apollo graphql base adapter is now abstract ([9eab0e9](https://github.com/nestjs/graphql/commit/9eab0e920f16bfca920193c436f1458516869478))
|
|
12
|
+
* fix context auto-wrapping ([66ede7a](https://github.com/nestjs/graphql/commit/66ede7a4c9c97290bd9ad600064c0fd5abceb2ff))
|
|
13
|
+
* **mercurius:** fix subscriptions ([a075ad5](https://github.com/nestjs/graphql/commit/a075ad51907f99d45862b08ec7503380ca2c4379))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* adapters to drivers ([2012ade](https://github.com/nestjs/graphql/commit/2012adec272f463082c60f7c588e49a63bc3f259))
|
|
19
|
+
* add dedicated gateway and federation adapters ([bdc5818](https://github.com/nestjs/graphql/commit/bdc5818cbed303523701e9ba2f1e26442c3ca428))
|
|
20
|
+
* extract configurations ([7e53ce2](https://github.com/nestjs/graphql/commit/7e53ce25929a07a0cc809aa78490d882cd1accdd))
|
|
21
|
+
* minor tweaks, normalize path by default ([033ea87](https://github.com/nestjs/graphql/commit/033ea873c5ab0e7bd3c447da82c720500b6cab3e))
|
|
22
|
+
* remove directives, update graphql tools monorepo ([6ec229e](https://github.com/nestjs/graphql/commit/6ec229e5c46d7100cc04bbd536906116c299770a))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Kamil Mysliwiec
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
|
8
|
+
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
|
|
10
|
+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
|
11
|
+
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
|
|
12
|
+
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
|
13
|
+
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
|
14
|
+
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
|
15
|
+
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
|
|
16
|
+
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
|
17
|
+
</p>
|
|
18
|
+
<!--[](https://opencollective.com/nest#backer)
|
|
19
|
+
[](https://opencollective.com/nest#sponsor)-->
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
[GraphQL](https://graphql.org/) is a powerful query language for APIs and a runtime for fulfilling those queries with your existing data. It's an elegant approach that solves many problems typically found with REST APIs. For background, we suggest reading this [comparison](https://dev-blog.apollodata.com/graphql-vs-rest-5d425123e34b) between GraphQL and REST. GraphQL combined with [TypeScript](https://www.typescriptlang.org/) helps you develop better type safety with your GraphQL queries, giving you end-to-end typing.
|
|
24
|
+
|
|
25
|
+
`@nestjs/apollo` is a package that provides adapters to use [Apollo](https://github.com/apollographql/apollo-server) in combination with `@nestjs/graphql`.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
If you are using `express` HTTP engine, install the following packages:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
$ npm i --save @nestjs/graphql @nestjs/apollo apollo-server-express graphql
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
In case of `fastify`, you should install `apollo-server-fastify` instead.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
$ npm i --save @nestjs/graphql @nestjs/apollo apollo-server-fastify graphql
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
[Overview & Tutorial](https://docs.nestjs.com/graphql/quick-start)
|
|
44
|
+
|
|
45
|
+
## Support
|
|
46
|
+
|
|
47
|
+
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
|
48
|
+
|
|
49
|
+
## Stay in touch
|
|
50
|
+
|
|
51
|
+
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
|
|
52
|
+
- Website - [https://nestjs.com](https://nestjs.com/)
|
|
53
|
+
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
Nest is [MIT licensed](LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo.constants.d.ts","sourceRoot":"","sources":["../lib/apollo.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.decorator.d.ts","sourceRoot":"","sources":["../../lib/decorators/plugin.decorator.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,MAAM,IAAI,cAAc,CAIvC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Plugin = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const apollo_constants_1 = require("../apollo.constants");
|
|
6
|
+
/**
|
|
7
|
+
* Decorator that marks a class as an Apollo plugin.
|
|
8
|
+
*/
|
|
9
|
+
function Plugin() {
|
|
10
|
+
return (target) => {
|
|
11
|
+
(0, common_1.SetMetadata)(apollo_constants_1.PLUGIN_METADATA, true)(target);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.Plugin = Plugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AbstractGraphQLDriver } from '@nestjs/graphql/drivers/abstract-graphql.driver';
|
|
2
|
+
import { ApolloServerBase } from 'apollo-server-core';
|
|
3
|
+
import { ApolloDriverConfig } from '../interfaces';
|
|
4
|
+
export declare abstract class ApolloBaseDriver<T extends Record<string, any> = ApolloDriverConfig> extends AbstractGraphQLDriver<T> {
|
|
5
|
+
protected _apolloServer: ApolloServerBase;
|
|
6
|
+
get instance(): ApolloServerBase;
|
|
7
|
+
start(apolloOptions: T): Promise<void>;
|
|
8
|
+
stop(): Promise<void>;
|
|
9
|
+
mergeDefaultOptions(options: T): Promise<T>;
|
|
10
|
+
protected registerExpress(apolloOptions: T, { preStartHook }?: {
|
|
11
|
+
preStartHook?: () => void;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
protected registerFastify(apolloOptions: T, { preStartHook }?: {
|
|
14
|
+
preStartHook?: () => void;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
private wrapFormatErrorFn;
|
|
17
|
+
private createTransformHttpErrorFn;
|
|
18
|
+
private wrapContextResolver;
|
|
19
|
+
private assignReqProperty;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=apollo-base.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-base.driver.d.ts","sourceRoot":"","sources":["../../lib/drivers/apollo-base.driver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACxF,OAAO,EAEL,gBAAgB,EAOjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAUnD,8BAAsB,gBAAgB,CACpC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,kBAAkB,CAClD,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IAChC,SAAS,CAAC,aAAa,EAAE,gBAAgB,CAAC;IAE1C,IAAI,QAAQ,IAAI,gBAAgB,CAE/B;IAEY,KAAK,CAAC,aAAa,EAAE,CAAC;IAa5B,IAAI;IAIE,mBAAmB,CAAC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;cA+CxC,eAAe,CAC7B,aAAa,EAAE,CAAC,EAChB,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;KAAO;cA8BtC,eAAe,CAC7B,aAAa,EAAE,CAAC,EAChB,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;KAAO;IA8BtD,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,0BAA0B;IA0BlC,OAAO,CAAC,mBAAmB;IAsB3B,OAAO,CAAC,iBAAiB;CAgB1B"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApolloBaseDriver = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
6
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
|
+
const abstract_graphql_driver_1 = require("@nestjs/graphql/drivers/abstract-graphql.driver");
|
|
8
|
+
const apollo_server_core_1 = require("apollo-server-core");
|
|
9
|
+
const omit = require("lodash.omit");
|
|
10
|
+
const apolloPredefinedExceptions = {
|
|
11
|
+
[common_1.HttpStatus.BAD_REQUEST]: apollo_server_core_1.UserInputError,
|
|
12
|
+
[common_1.HttpStatus.UNAUTHORIZED]: apollo_server_core_1.AuthenticationError,
|
|
13
|
+
[common_1.HttpStatus.FORBIDDEN]: apollo_server_core_1.ForbiddenError,
|
|
14
|
+
};
|
|
15
|
+
class ApolloBaseDriver extends abstract_graphql_driver_1.AbstractGraphQLDriver {
|
|
16
|
+
get instance() {
|
|
17
|
+
return this._apolloServer;
|
|
18
|
+
}
|
|
19
|
+
async start(apolloOptions) {
|
|
20
|
+
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
21
|
+
const platformName = httpAdapter.getType();
|
|
22
|
+
if (platformName === 'express') {
|
|
23
|
+
await this.registerExpress(apolloOptions);
|
|
24
|
+
}
|
|
25
|
+
else if (platformName === 'fastify') {
|
|
26
|
+
await this.registerFastify(apolloOptions);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new Error(`No support for current HttpAdapter: ${platformName}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
stop() {
|
|
33
|
+
var _a;
|
|
34
|
+
return (_a = this._apolloServer) === null || _a === void 0 ? void 0 : _a.stop();
|
|
35
|
+
}
|
|
36
|
+
async mergeDefaultOptions(options) {
|
|
37
|
+
let defaults = {
|
|
38
|
+
path: '/graphql',
|
|
39
|
+
fieldResolverEnhancers: [],
|
|
40
|
+
stopOnTerminationSignals: false,
|
|
41
|
+
};
|
|
42
|
+
if ((options.playground === undefined &&
|
|
43
|
+
process.env.NODE_ENV !== 'production') ||
|
|
44
|
+
options.playground) {
|
|
45
|
+
const playgroundOptions = typeof options.playground === 'object' ? options.playground : undefined;
|
|
46
|
+
defaults = {
|
|
47
|
+
...defaults,
|
|
48
|
+
plugins: [
|
|
49
|
+
(0, apollo_server_core_1.ApolloServerPluginLandingPageGraphQLPlayground)(playgroundOptions),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if ((options.playground === undefined &&
|
|
54
|
+
process.env.NODE_ENV === 'production') ||
|
|
55
|
+
options.playground === false) {
|
|
56
|
+
defaults = {
|
|
57
|
+
...defaults,
|
|
58
|
+
plugins: [(0, apollo_server_core_1.ApolloServerPluginLandingPageDisabled)()],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
options = await super.mergeDefaultOptions(options, omit(defaults, 'plugins'));
|
|
62
|
+
options.plugins = (options.plugins || []).concat(defaults.plugins || []);
|
|
63
|
+
this.wrapContextResolver(options);
|
|
64
|
+
this.wrapFormatErrorFn(options);
|
|
65
|
+
return options;
|
|
66
|
+
}
|
|
67
|
+
async registerExpress(apolloOptions, { preStartHook } = {}) {
|
|
68
|
+
const { ApolloServer } = (0, load_package_util_1.loadPackage)('apollo-server-express', 'GraphQLModule', () => require('apollo-server-express'));
|
|
69
|
+
const { disableHealthCheck, path, onHealthCheck, cors, bodyParserConfig } = apolloOptions;
|
|
70
|
+
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
71
|
+
const app = httpAdapter.getInstance();
|
|
72
|
+
preStartHook === null || preStartHook === void 0 ? void 0 : preStartHook();
|
|
73
|
+
const apolloServer = new ApolloServer(apolloOptions);
|
|
74
|
+
await apolloServer.start();
|
|
75
|
+
apolloServer.applyMiddleware({
|
|
76
|
+
app,
|
|
77
|
+
path,
|
|
78
|
+
disableHealthCheck,
|
|
79
|
+
onHealthCheck,
|
|
80
|
+
cors,
|
|
81
|
+
bodyParserConfig,
|
|
82
|
+
});
|
|
83
|
+
this._apolloServer = apolloServer;
|
|
84
|
+
}
|
|
85
|
+
async registerFastify(apolloOptions, { preStartHook } = {}) {
|
|
86
|
+
const { ApolloServer } = (0, load_package_util_1.loadPackage)('apollo-server-fastify', 'GraphQLModule', () => require('apollo-server-fastify'));
|
|
87
|
+
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
88
|
+
const app = httpAdapter.getInstance();
|
|
89
|
+
preStartHook === null || preStartHook === void 0 ? void 0 : preStartHook();
|
|
90
|
+
const apolloServer = new ApolloServer(apolloOptions);
|
|
91
|
+
await apolloServer.start();
|
|
92
|
+
const { disableHealthCheck, onHealthCheck, cors, bodyParserConfig, path } = apolloOptions;
|
|
93
|
+
await app.register(apolloServer.createHandler({
|
|
94
|
+
disableHealthCheck,
|
|
95
|
+
onHealthCheck,
|
|
96
|
+
cors,
|
|
97
|
+
bodyParserConfig,
|
|
98
|
+
path,
|
|
99
|
+
}));
|
|
100
|
+
this._apolloServer = apolloServer;
|
|
101
|
+
}
|
|
102
|
+
wrapFormatErrorFn(options) {
|
|
103
|
+
if (options.autoTransformHttpErrors === false) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (options.formatError) {
|
|
107
|
+
const origFormatError = options.formatError;
|
|
108
|
+
const transformHttpErrorFn = this.createTransformHttpErrorFn();
|
|
109
|
+
options.formatError = (err) => {
|
|
110
|
+
err = transformHttpErrorFn(err);
|
|
111
|
+
return origFormatError(err);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
options.formatError =
|
|
116
|
+
this.createTransformHttpErrorFn();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
createTransformHttpErrorFn() {
|
|
120
|
+
return (originalError) => {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
const exceptionRef = (_a = originalError === null || originalError === void 0 ? void 0 : originalError.extensions) === null || _a === void 0 ? void 0 : _a.exception;
|
|
123
|
+
const isHttpException = ((_b = exceptionRef === null || exceptionRef === void 0 ? void 0 : exceptionRef.response) === null || _b === void 0 ? void 0 : _b.statusCode) && (exceptionRef === null || exceptionRef === void 0 ? void 0 : exceptionRef.status);
|
|
124
|
+
if (!isHttpException) {
|
|
125
|
+
return originalError;
|
|
126
|
+
}
|
|
127
|
+
let error;
|
|
128
|
+
const httpStatus = exceptionRef === null || exceptionRef === void 0 ? void 0 : exceptionRef.status;
|
|
129
|
+
if (httpStatus in apolloPredefinedExceptions) {
|
|
130
|
+
error = new apolloPredefinedExceptions[httpStatus](exceptionRef === null || exceptionRef === void 0 ? void 0 : exceptionRef.message);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
error = new apollo_server_core_1.ApolloError(exceptionRef.message, httpStatus === null || httpStatus === void 0 ? void 0 : httpStatus.toString());
|
|
134
|
+
}
|
|
135
|
+
error.stack = exceptionRef === null || exceptionRef === void 0 ? void 0 : exceptionRef.stacktrace;
|
|
136
|
+
error.extensions['response'] = exceptionRef === null || exceptionRef === void 0 ? void 0 : exceptionRef.response;
|
|
137
|
+
return error;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
wrapContextResolver(targetOptions, originalOptions = { ...targetOptions }) {
|
|
141
|
+
if (!targetOptions.context) {
|
|
142
|
+
targetOptions.context = ({ req, request }) => ({ req: req !== null && req !== void 0 ? req : request });
|
|
143
|
+
}
|
|
144
|
+
else if ((0, shared_utils_1.isFunction)(targetOptions.context)) {
|
|
145
|
+
targetOptions.context = async (...args) => {
|
|
146
|
+
const ctx = await originalOptions.context(...args);
|
|
147
|
+
const { req, request } = args[0];
|
|
148
|
+
return this.assignReqProperty(ctx, req !== null && req !== void 0 ? req : request);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
targetOptions.context = ({ req, request }) => {
|
|
153
|
+
return this.assignReqProperty(originalOptions.context, req !== null && req !== void 0 ? req : request);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
assignReqProperty(ctx, req) {
|
|
158
|
+
if (!ctx) {
|
|
159
|
+
return { req };
|
|
160
|
+
}
|
|
161
|
+
if (typeof ctx !== 'object' ||
|
|
162
|
+
(ctx && ctx.req && typeof ctx.req === 'object')) {
|
|
163
|
+
return ctx;
|
|
164
|
+
}
|
|
165
|
+
ctx.req = req;
|
|
166
|
+
return ctx;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.ApolloBaseDriver = ApolloBaseDriver;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModulesContainer } from '@nestjs/core';
|
|
2
|
+
import { GraphQLFederationFactory } from '@nestjs/graphql/federation/graphql-federation.factory';
|
|
3
|
+
import { ApolloDriverConfig } from '../interfaces';
|
|
4
|
+
import { ApolloBaseDriver } from './apollo-base.driver';
|
|
5
|
+
export declare class ApolloFederationDriver extends ApolloBaseDriver {
|
|
6
|
+
private readonly graphqlFederationFactory;
|
|
7
|
+
private readonly pluginsExplorerService;
|
|
8
|
+
constructor(graphqlFederationFactory: GraphQLFederationFactory, modulesContainer: ModulesContainer);
|
|
9
|
+
start(options: ApolloDriverConfig): Promise<void>;
|
|
10
|
+
private runExecutorFactoryIfPresent;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=apollo-federation.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-federation.driver.d.ts","sourceRoot":"","sources":["../../lib/drivers/apollo-federation.driver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AAEjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,qBACa,sBAAuB,SAAQ,gBAAgB;IAIxD,OAAO,CAAC,QAAQ,CAAC,wBAAwB;IAH3C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAyB;gBAG7C,wBAAwB,EAAE,wBAAwB,EACnE,gBAAgB,EAAE,gBAAgB;IAMvB,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;YAiChD,2BAA2B;CAO1C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApolloFederationDriver = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
7
|
+
const core_1 = require("@nestjs/core");
|
|
8
|
+
const graphql_federation_factory_1 = require("@nestjs/graphql/federation/graphql-federation.factory");
|
|
9
|
+
const extend_util_1 = require("@nestjs/graphql/utils/extend.util");
|
|
10
|
+
const plugins_explorer_service_1 = require("../services/plugins-explorer.service");
|
|
11
|
+
const apollo_base_driver_1 = require("./apollo-base.driver");
|
|
12
|
+
let ApolloFederationDriver = class ApolloFederationDriver extends apollo_base_driver_1.ApolloBaseDriver {
|
|
13
|
+
constructor(graphqlFederationFactory, modulesContainer) {
|
|
14
|
+
super();
|
|
15
|
+
this.graphqlFederationFactory = graphqlFederationFactory;
|
|
16
|
+
this.pluginsExplorerService = new plugins_explorer_service_1.PluginsExplorerService(modulesContainer);
|
|
17
|
+
}
|
|
18
|
+
async start(options) {
|
|
19
|
+
options.plugins = (0, extend_util_1.extend)(options.plugins || [], this.pluginsExplorerService.explore(options));
|
|
20
|
+
const adapterOptions = await this.graphqlFederationFactory.mergeWithSchema(options);
|
|
21
|
+
await this.runExecutorFactoryIfPresent(adapterOptions);
|
|
22
|
+
if (options.definitions && options.definitions.path) {
|
|
23
|
+
const { printSubgraphSchema } = (0, load_package_util_1.loadPackage)('@apollo/subgraph', 'ApolloFederation', () => require('@apollo/subgraph'));
|
|
24
|
+
await this.graphQlFactory.generateDefinitions(printSubgraphSchema(adapterOptions.schema), options);
|
|
25
|
+
}
|
|
26
|
+
await super.start(adapterOptions);
|
|
27
|
+
if (options.installSubscriptionHandlers || options.subscriptions) {
|
|
28
|
+
// TL;DR <https://github.com/apollographql/apollo-server/issues/2776>
|
|
29
|
+
throw new Error('No support for subscriptions yet when using Apollo Federation');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async runExecutorFactoryIfPresent(apolloOptions) {
|
|
33
|
+
if (!apolloOptions.executorFactory) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const executor = await apolloOptions.executorFactory(apolloOptions.schema);
|
|
37
|
+
apolloOptions.executor = executor;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
ApolloFederationDriver = (0, tslib_1.__decorate)([
|
|
41
|
+
(0, common_1.Injectable)(),
|
|
42
|
+
(0, tslib_1.__metadata)("design:paramtypes", [graphql_federation_factory_1.GraphQLFederationFactory,
|
|
43
|
+
core_1.ModulesContainer])
|
|
44
|
+
], ApolloFederationDriver);
|
|
45
|
+
exports.ApolloFederationDriver = ApolloFederationDriver;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApolloGatewayDriverConfig } from '../interfaces';
|
|
2
|
+
import { ApolloBaseDriver } from './apollo-base.driver';
|
|
3
|
+
export declare class ApolloGatewayDriver extends ApolloBaseDriver<ApolloGatewayDriverConfig> {
|
|
4
|
+
start(options: ApolloGatewayDriverConfig): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=apollo-gateway.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-gateway.driver.d.ts","sourceRoot":"","sources":["../../lib/drivers/apollo-gateway.driver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,qBACa,mBAAoB,SAAQ,gBAAgB,CAAC,yBAAyB,CAAC;IACrE,KAAK,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;CActE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApolloGatewayDriver = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
7
|
+
const apollo_base_driver_1 = require("./apollo-base.driver");
|
|
8
|
+
let ApolloGatewayDriver = class ApolloGatewayDriver extends apollo_base_driver_1.ApolloBaseDriver {
|
|
9
|
+
async start(options) {
|
|
10
|
+
const { ApolloGateway } = (0, load_package_util_1.loadPackage)('@apollo/gateway', 'ApolloGateway', () => require('@apollo/gateway'));
|
|
11
|
+
const { server: serverOpts = {}, gateway: gatewayOpts = {} } = options;
|
|
12
|
+
const gateway = new ApolloGateway(gatewayOpts);
|
|
13
|
+
await super.start({
|
|
14
|
+
...serverOpts,
|
|
15
|
+
gateway,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
ApolloGatewayDriver = (0, tslib_1.__decorate)([
|
|
20
|
+
(0, common_1.Injectable)()
|
|
21
|
+
], ApolloGatewayDriver);
|
|
22
|
+
exports.ApolloGatewayDriver = ApolloGatewayDriver;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModulesContainer } from '@nestjs/core';
|
|
2
|
+
import { ApolloDriverConfig } from '../interfaces';
|
|
3
|
+
import { ApolloBaseDriver } from './apollo-base.driver';
|
|
4
|
+
export declare class ApolloDriver extends ApolloBaseDriver {
|
|
5
|
+
private _subscriptionService?;
|
|
6
|
+
private readonly pluginsExplorerService;
|
|
7
|
+
constructor(modulesContainer: ModulesContainer);
|
|
8
|
+
start(apolloOptions: ApolloDriverConfig): Promise<void>;
|
|
9
|
+
registerServer(apolloOptions: ApolloDriverConfig): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=apollo.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo.driver.d.ts","sourceRoot":"","sources":["../../lib/drivers/apollo.driver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,qBACa,YAAa,SAAQ,gBAAgB;IAChD,OAAO,CAAC,oBAAoB,CAAC,CAAyB;IACtD,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAyB;gBAEpD,gBAAgB,EAAE,gBAAgB;IAKjC,KAAK,CAAC,aAAa,EAAE,kBAAkB;IAmCvC,cAAc,CAAC,aAAa,EAAE,kBAAkB;IAahD,IAAI;CAIlB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApolloDriver = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const core_1 = require("@nestjs/core");
|
|
7
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
8
|
+
const utils_1 = require("@nestjs/graphql/utils");
|
|
9
|
+
const graphql_2 = require("graphql");
|
|
10
|
+
const plugins_explorer_service_1 = require("../services/plugins-explorer.service");
|
|
11
|
+
const apollo_base_driver_1 = require("./apollo-base.driver");
|
|
12
|
+
let ApolloDriver = class ApolloDriver extends apollo_base_driver_1.ApolloBaseDriver {
|
|
13
|
+
constructor(modulesContainer) {
|
|
14
|
+
super();
|
|
15
|
+
this.pluginsExplorerService = new plugins_explorer_service_1.PluginsExplorerService(modulesContainer);
|
|
16
|
+
}
|
|
17
|
+
async start(apolloOptions) {
|
|
18
|
+
var _a;
|
|
19
|
+
apolloOptions.plugins = (0, utils_1.extend)(apolloOptions.plugins || [], this.pluginsExplorerService.explore(apolloOptions));
|
|
20
|
+
const options = await this.graphQlFactory.mergeWithSchema(apolloOptions);
|
|
21
|
+
if (options.definitions && options.definitions.path) {
|
|
22
|
+
await this.graphQlFactory.generateDefinitions((0, graphql_2.printSchema)(options.schema), options);
|
|
23
|
+
}
|
|
24
|
+
await this.registerServer(options);
|
|
25
|
+
if (options.installSubscriptionHandlers || options.subscriptions) {
|
|
26
|
+
const subscriptionsOptions = options.subscriptions || { 'subscriptions-transport-ws': {} };
|
|
27
|
+
this._subscriptionService = new graphql_1.GqlSubscriptionService({
|
|
28
|
+
schema: options.schema,
|
|
29
|
+
path: options.path,
|
|
30
|
+
context: options.context,
|
|
31
|
+
...subscriptionsOptions,
|
|
32
|
+
}, (_a = this.httpAdapterHost.httpAdapter) === null || _a === void 0 ? void 0 : _a.getHttpServer());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async registerServer(apolloOptions) {
|
|
36
|
+
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
37
|
+
const platformName = httpAdapter.getType();
|
|
38
|
+
if (platformName === 'express') {
|
|
39
|
+
await this.registerExpress(apolloOptions);
|
|
40
|
+
}
|
|
41
|
+
else if (platformName === 'fastify') {
|
|
42
|
+
await this.registerFastify(apolloOptions);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error(`No support for current HttpAdapter: ${platformName}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async stop() {
|
|
49
|
+
var _a;
|
|
50
|
+
await ((_a = this._subscriptionService) === null || _a === void 0 ? void 0 : _a.stop());
|
|
51
|
+
await super.stop();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
ApolloDriver = (0, tslib_1.__decorate)([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
(0, tslib_1.__metadata)("design:paramtypes", [core_1.ModulesContainer])
|
|
57
|
+
], ApolloDriver);
|
|
58
|
+
exports.ApolloDriver = ApolloDriver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/drivers/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./apollo-federation.driver"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./apollo-gateway.driver"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./apollo.driver"), exports);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./decorators"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./drivers"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./interfaces"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./utils"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GqlModuleAsyncOptions, GqlModuleOptions, GqlOptionsFactory, SubscriptionConfig } from '@nestjs/graphql';
|
|
2
|
+
import { ApolloServerPluginLandingPageGraphQLPlaygroundOptions, Config, GraphQLExecutor } from 'apollo-server-core';
|
|
3
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
|
+
export interface ServerRegistration {
|
|
5
|
+
/**
|
|
6
|
+
* Path to mount GraphQL API
|
|
7
|
+
*/
|
|
8
|
+
path?: string;
|
|
9
|
+
/**
|
|
10
|
+
* CORS configuration
|
|
11
|
+
*/
|
|
12
|
+
cors?: any | boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Body-parser configuration
|
|
15
|
+
*/
|
|
16
|
+
bodyParserConfig?: any | boolean;
|
|
17
|
+
/**
|
|
18
|
+
* On health check hook
|
|
19
|
+
*/
|
|
20
|
+
onHealthCheck?: (req: any) => Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to enable health check
|
|
23
|
+
*/
|
|
24
|
+
disableHealthCheck?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface ApolloDriverConfig extends Omit<Config, 'typeDefs'>, ServerRegistration, Omit<GqlModuleOptions, 'context'> {
|
|
27
|
+
/**
|
|
28
|
+
* Executor factory function
|
|
29
|
+
*/
|
|
30
|
+
executorFactory?: (schema: GraphQLSchema) => GraphQLExecutor | Promise<GraphQLExecutor>;
|
|
31
|
+
/**
|
|
32
|
+
* If enabled, "subscriptions-transport-ws" will be automatically registered.
|
|
33
|
+
*/
|
|
34
|
+
installSubscriptionHandlers?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Subscriptions configuration.
|
|
37
|
+
*/
|
|
38
|
+
subscriptions?: SubscriptionConfig;
|
|
39
|
+
/**
|
|
40
|
+
* GraphQL playground options.
|
|
41
|
+
*/
|
|
42
|
+
playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
|
|
43
|
+
/**
|
|
44
|
+
* If enabled, will register a global interceptor that automatically maps
|
|
45
|
+
* "HttpException" class instances to corresponding Apollo errors.
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
autoTransformHttpErrors?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare type ApolloDriverConfigFactory = GqlOptionsFactory<ApolloDriverConfig>;
|
|
51
|
+
export declare type ApolloDriverAsyncConfig = GqlModuleAsyncOptions<ApolloDriverConfig>;
|
|
52
|
+
//# sourceMappingURL=apollo-driver-config.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-driver-config.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/apollo-driver-config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qDAAqD,EACrD,MAAM,EACN,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC;IAEjC;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAE3C;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,kBACf,SAAQ,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,EAC9B,kBAAkB,EAClB,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,CAChB,MAAM,EAAE,aAAa,KAClB,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEhD;;OAEG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IAEnC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,qDAAqD,CAAC;IAE7E;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,oBAAY,yBAAyB,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAC9E,oBAAY,uBAAuB,GAAG,qBAAqB,CAAC,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GatewayConfig } from '@apollo/gateway';
|
|
2
|
+
import { GqlModuleAsyncOptions, GqlModuleOptions, GqlOptionsFactory } from '@nestjs/graphql';
|
|
3
|
+
export interface ApolloGatewayDriverConfig {
|
|
4
|
+
gateway?: GatewayConfig;
|
|
5
|
+
server?: Omit<GqlModuleOptions, 'typeDefs' | 'typePaths' | 'include' | 'resolvers' | 'resolverValidationOptions' | 'directiveResolvers' | 'autoSchemaFile' | 'transformSchema' | 'definitions' | 'schema' | 'subscriptions' | 'buildSchemaOptions' | 'fieldResolverEnhancers' | 'driver'>;
|
|
6
|
+
}
|
|
7
|
+
export declare type ApolloGatewayDriverConfigFactory = GqlOptionsFactory<ApolloGatewayDriverConfig>;
|
|
8
|
+
export declare type ApolloGatewayDriverAsyncConfig = GqlModuleAsyncOptions<ApolloGatewayDriverConfig>;
|
|
9
|
+
//# sourceMappingURL=apollo-gateway-driver-config.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-gateway-driver-config.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/apollo-gateway-driver-config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,MAAM,CAAC,EAAE,IAAI,CACX,gBAAgB,EACd,UAAU,GACV,WAAW,GACX,SAAS,GACT,WAAW,GACX,2BAA2B,GAC3B,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,QAAQ,GACR,eAAe,GACf,oBAAoB,GACpB,wBAAwB,GACxB,QAAQ,CACX,CAAC;CACH;AAED,oBAAY,gCAAgC,GAC1C,iBAAiB,CAAC,yBAAyB,CAAC,CAAC;AAC/C,oBAAY,8BAA8B,GACxC,qBAAqB,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./apollo-driver-config.interface"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./apollo-gateway-driver-config.interface"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
2
|
+
import { ModulesContainer } from '@nestjs/core/injector/modules-container';
|
|
3
|
+
import { GqlModuleOptions } from '@nestjs/graphql/interfaces/gql-module-options.interface';
|
|
4
|
+
import { BaseExplorerService } from '@nestjs/graphql/services/base-explorer.service';
|
|
5
|
+
export declare class PluginsExplorerService extends BaseExplorerService {
|
|
6
|
+
private readonly modulesContainer;
|
|
7
|
+
constructor(modulesContainer: ModulesContainer);
|
|
8
|
+
explore(options: GqlModuleOptions): any[];
|
|
9
|
+
filterPlugins<T = any>(wrapper: InstanceWrapper<T>): T;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=plugins-explorer.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins-explorer.service.d.ts","sourceRoot":"","sources":["../../lib/services/plugins-explorer.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAGrF,qBAAa,sBAAuB,SAAQ,mBAAmB;IACjD,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAAhB,gBAAgB,EAAE,gBAAgB;IAI/D,OAAO,CAAC,OAAO,EAAE,gBAAgB;IAQjC,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;CAQnD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginsExplorerService = void 0;
|
|
4
|
+
const base_explorer_service_1 = require("@nestjs/graphql/services/base-explorer.service");
|
|
5
|
+
const apollo_constants_1 = require("../apollo.constants");
|
|
6
|
+
class PluginsExplorerService extends base_explorer_service_1.BaseExplorerService {
|
|
7
|
+
constructor(modulesContainer) {
|
|
8
|
+
super();
|
|
9
|
+
this.modulesContainer = modulesContainer;
|
|
10
|
+
}
|
|
11
|
+
explore(options) {
|
|
12
|
+
const modules = this.getModules(this.modulesContainer, options.include || []);
|
|
13
|
+
return this.flatMap(modules, (instance) => this.filterPlugins(instance));
|
|
14
|
+
}
|
|
15
|
+
filterPlugins(wrapper) {
|
|
16
|
+
const { instance } = wrapper;
|
|
17
|
+
if (!instance) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const metadata = Reflect.getMetadata(apollo_constants_1.PLUGIN_METADATA, instance.constructor);
|
|
21
|
+
return metadata ? instance : undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PluginsExplorerService = PluginsExplorerService;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { INestApplicationContext } from '@nestjs/common';
|
|
2
|
+
import { ApolloServerBase } from 'apollo-server-core';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the underlying ApolloServer instance for a given application.
|
|
5
|
+
* @param app Nest application reference
|
|
6
|
+
* @returns Apollo Server instance used by the host application
|
|
7
|
+
*/
|
|
8
|
+
export declare function getApolloServer(app: INestApplicationContext): ApolloServerBase;
|
|
9
|
+
//# sourceMappingURL=get-apollo-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-apollo-server.d.ts","sourceRoot":"","sources":["../../lib/utils/get-apollo-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,uBAAuB,GAC3B,gBAAgB,CAQlB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getApolloServer = void 0;
|
|
4
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the underlying ApolloServer instance for a given application.
|
|
7
|
+
* @param app Nest application reference
|
|
8
|
+
* @returns Apollo Server instance used by the host application
|
|
9
|
+
*/
|
|
10
|
+
function getApolloServer(app) {
|
|
11
|
+
var _a;
|
|
12
|
+
try {
|
|
13
|
+
const graphqlModule = app.get(graphql_1.GraphQLModule);
|
|
14
|
+
return (_a = graphqlModule.graphQlAdapter) === null || _a === void 0 ? void 0 : _a.instance;
|
|
15
|
+
}
|
|
16
|
+
catch (error) { }
|
|
17
|
+
throw new Error(`Nest could not find the "GraphQLModule" in your application's container. Please, double-check if it's registered in the given application.`);
|
|
18
|
+
}
|
|
19
|
+
exports.getApolloServer = getApolloServer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestjs/apollo",
|
|
3
|
+
"version": "9.2.0",
|
|
4
|
+
"description": "Nest - modern, fast, powerful node.js web framework (@apollo)",
|
|
5
|
+
"author": "Kamil Mysliwiec",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/nestjs/graphql#readme",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/nestjs/graphql.git"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test:e2e": "jest --config ./tests/jest-e2e.ts --runInBand",
|
|
19
|
+
"test:e2e:dev": "jest --config ./tests/jest-e2e.ts --runInBand --watch"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/nestjs/graphql/issues"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@apollo/gateway": "0.46.0",
|
|
26
|
+
"@nestjs/common": "8.2.3",
|
|
27
|
+
"@nestjs/core": "8.2.3",
|
|
28
|
+
"@nestjs/platform-express": "8.2.3",
|
|
29
|
+
"@nestjs/platform-fastify": "8.2.3",
|
|
30
|
+
"@nestjs/testing": "8.2.3",
|
|
31
|
+
"apollo-cache-inmemory": "1.6.6",
|
|
32
|
+
"apollo-client": "2.6.10",
|
|
33
|
+
"apollo-link-ws": "1.0.20",
|
|
34
|
+
"apollo-server-core": "3.6.2",
|
|
35
|
+
"apollo-server-express": "3.6.2",
|
|
36
|
+
"apollo-server-fastify": "3.6.2"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@graphql-tools/utils": "8.5.5",
|
|
40
|
+
"lodash.omit": "4.5.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@apollo/gateway": "^0.44.1 || ^0.46.0",
|
|
44
|
+
"@nestjs/common": "^8.2.3",
|
|
45
|
+
"@nestjs/core": "^8.2.3",
|
|
46
|
+
"apollo-server-core": "^3.5.0",
|
|
47
|
+
"apollo-server-express": "^3.5.0",
|
|
48
|
+
"apollo-server-fastify": "^3.5.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@apollo/gateway": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"apollo-server-core": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"apollo-server-express": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"apollo-server-fastify": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|