@loopback/graphql 0.4.3 → 0.7.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/README.md +48 -1
- package/dist/booters/resolver.booter.js +10 -10
- package/dist/booters/resolver.booter.js.map +1 -1
- package/dist/graphql.component.js +5 -5
- package/dist/graphql.component.js.map +1 -1
- package/dist/graphql.container.js +5 -5
- package/dist/graphql.container.js.map +1 -1
- package/dist/graphql.server.d.ts +2 -0
- package/dist/graphql.server.js +36 -18
- package/dist/graphql.server.js.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/package.json +20 -19
- package/src/graphql.server.ts +24 -3
package/README.md
CHANGED
|
@@ -384,8 +384,11 @@ export class GraphqlDemoApplication extends BootMixin(
|
|
|
384
384
|
constructor(options: ApplicationConfig = {}) {
|
|
385
385
|
super(options);
|
|
386
386
|
|
|
387
|
+
const server = this.getSync(GraphQLBindings.GRAPHQL_SERVER);
|
|
388
|
+
this.expressMiddleware('middleware.express.GraphQL', server.expressApp);
|
|
389
|
+
|
|
387
390
|
// Register a GraphQL middleware
|
|
388
|
-
|
|
391
|
+
server.middleware((resolverData, next) => {
|
|
389
392
|
// It's invoked for each field resolver, query and mutation operations
|
|
390
393
|
return next();
|
|
391
394
|
});
|
|
@@ -393,6 +396,50 @@ export class GraphqlDemoApplication extends BootMixin(
|
|
|
393
396
|
}
|
|
394
397
|
```
|
|
395
398
|
|
|
399
|
+
## Export GraphQL Schema as a file
|
|
400
|
+
|
|
401
|
+
Exporting the generated GraphQL schema file can be done by calling
|
|
402
|
+
`exportGraphQLSchema` on the `GraphQLServer`:
|
|
403
|
+
|
|
404
|
+
```ts
|
|
405
|
+
import {Application} from '@loopback/core';
|
|
406
|
+
import {GraphQLServer} from '@loopback/graphql';
|
|
407
|
+
|
|
408
|
+
const app = new Application();
|
|
409
|
+
const serverBinding = app.server(GraphQLServer);
|
|
410
|
+
app.configure(serverBinding.key).to({host: '127.0.0.1', port: 0});
|
|
411
|
+
server = await app.getServer(GraphQLServer);
|
|
412
|
+
// set up your resolvers
|
|
413
|
+
await server.exportGraphQLSchema(pathToFile);
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
For applications using `GraphQLComponent` to discover resolvers, exporting the
|
|
417
|
+
schema file is similar to `exportOpenApiSpec` on `RestServer`:
|
|
418
|
+
|
|
419
|
+
```ts
|
|
420
|
+
// export-graphql-schema.ts, sibling to application.ts
|
|
421
|
+
import {MyApplication, MyApplicationConfig} from './application';
|
|
422
|
+
|
|
423
|
+
async function exportGraphQLSchema(): Promise<void> {
|
|
424
|
+
const config: MyApplicationConfig = {
|
|
425
|
+
rest: {
|
|
426
|
+
port: +(process.env.PORT ?? 3000),
|
|
427
|
+
host: process.env.HOST ?? 'localhost',
|
|
428
|
+
},
|
|
429
|
+
};
|
|
430
|
+
const outFile = process.argv[2] ?? '';
|
|
431
|
+
const app = new MyApplication(config);
|
|
432
|
+
await app.boot();
|
|
433
|
+
const server = await app.getServer(GraphQLServer);
|
|
434
|
+
await server.exportGraphQLSchema(outFile);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
exportGraphQLSchema().catch(err => {
|
|
438
|
+
console.error('Fail to export GraphQL spec from the application.', err);
|
|
439
|
+
process.exit(1);
|
|
440
|
+
});
|
|
441
|
+
```
|
|
442
|
+
|
|
396
443
|
## Try it out
|
|
397
444
|
|
|
398
445
|
Check out
|
|
@@ -8,10 +8,10 @@ exports.GraphQLResolverDefaults = exports.GraphQLResolverBooter = void 0;
|
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
const boot_1 = require("@loopback/boot");
|
|
10
10
|
const core_1 = require("@loopback/core");
|
|
11
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
11
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
12
12
|
const getMetadataStorage_1 = require("type-graphql/dist/metadata/getMetadataStorage");
|
|
13
13
|
const graphql_server_1 = require("../graphql.server");
|
|
14
|
-
const debug = debug_1.default('loopback:graphql:resolver-booter');
|
|
14
|
+
const debug = (0, debug_1.default)('loopback:graphql:resolver-booter');
|
|
15
15
|
/**
|
|
16
16
|
* A class that extends BaseArtifactBooter to boot the 'GraphQLResolver' artifact type.
|
|
17
17
|
*
|
|
@@ -37,23 +37,23 @@ let GraphQLResolverBooter = class GraphQLResolverBooter extends boot_1.BaseArtif
|
|
|
37
37
|
await super.load();
|
|
38
38
|
const resolverClasses =
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
getMetadataStorage_1.getMetadataStorage().resolverClasses;
|
|
40
|
+
(0, getMetadataStorage_1.getMetadataStorage)().resolverClasses;
|
|
41
41
|
this.resolvers = this.classes.filter(cls => {
|
|
42
42
|
return resolverClasses.some(r => !r.isAbstract && r.target === cls);
|
|
43
43
|
});
|
|
44
44
|
for (const resolver of this.resolvers) {
|
|
45
45
|
debug('Bind interceptor: %s', resolver.name);
|
|
46
|
-
const binding = graphql_server_1.registerResolver(this.app, resolver);
|
|
46
|
+
const binding = (0, graphql_server_1.registerResolver)(this.app, resolver);
|
|
47
47
|
debug('Binding created for interceptor: %j', binding);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
GraphQLResolverBooter = tslib_1.__decorate([
|
|
52
|
-
boot_1.booter('graphqlResolvers'),
|
|
53
|
-
tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
|
54
|
-
tslib_1.__param(1, core_1.inject(boot_1.BootBindings.PROJECT_ROOT)),
|
|
55
|
-
tslib_1.__param(2, core_1.config()),
|
|
56
|
-
tslib_1.__metadata("design:paramtypes", [core_1.Application, String, Object])
|
|
51
|
+
GraphQLResolverBooter = (0, tslib_1.__decorate)([
|
|
52
|
+
(0, boot_1.booter)('graphqlResolvers'),
|
|
53
|
+
(0, tslib_1.__param)(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
|
54
|
+
(0, tslib_1.__param)(1, (0, core_1.inject)(boot_1.BootBindings.PROJECT_ROOT)),
|
|
55
|
+
(0, tslib_1.__param)(2, (0, core_1.config)()),
|
|
56
|
+
(0, tslib_1.__metadata)("design:paramtypes", [core_1.Application, String, Object])
|
|
57
57
|
], GraphQLResolverBooter);
|
|
58
58
|
exports.GraphQLResolverBooter = GraphQLResolverBooter;
|
|
59
59
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.booter.js","sourceRoot":"","sources":["../../src/booters/resolver.booter.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAKwB;AACxB,yCAMwB;AACxB
|
|
1
|
+
{"version":3,"file":"resolver.booter.js","sourceRoot":"","sources":["../../src/booters/resolver.booter.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAKwB;AACxB,yCAMwB;AACxB,+DAAiC;AAEjC,sFAAiF;AACjF,sDAAmD;AAEnD,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,kCAAkC,CAAC,CAAC;AAI/D;;;;;;;;GAQG;AAEH,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,yBAAkB;IAG3D,YAES,GAAgB,EACY,WAAmB,EAE/C,oBAAqC,EAAE;QAE9C,KAAK,CACH,WAAW;QACX,iEAAiE;QACjE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,+BAAuB,EAAE,iBAAiB,CAAC,CAC9D,CAAC;QATK,QAAG,GAAH,GAAG,CAAa;QAGhB,sBAAiB,GAAjB,iBAAiB,CAAsB;IAOhD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAEnB,MAAM,eAAe;QACnB,8DAA8D;QAC7D,IAAA,uCAAkB,GAAU,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACzC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;QACH,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;YACrC,KAAK,CAAC,sBAAsB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAG,IAAA,iCAAgB,EAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACrD,KAAK,CAAC,qCAAqC,EAAE,OAAO,CAAC,CAAC;SACvD;IACH,CAAC;CACF,CAAA;AApCY,qBAAqB;IADjC,IAAA,aAAM,EAAC,kBAAkB,CAAC;IAKtB,wBAAA,IAAA,aAAM,EAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;IAEzC,wBAAA,IAAA,aAAM,EAAC,mBAAY,CAAC,YAAY,CAAC,CAAA;IACjC,wBAAA,IAAA,aAAM,GAAE,CAAA;kDAFG,kBAAW;GALd,qBAAqB,CAoCjC;AApCY,sDAAqB;AAsClC;;GAEG;AACU,QAAA,uBAAuB,GAAoB;IACtD,IAAI,EAAE,CAAC,mBAAmB,CAAC;IAC3B,UAAU,EAAE,CAAC,KAAK,CAAC;IACnB,MAAM,EAAE,IAAI;CACb,CAAC"}
|
|
@@ -16,17 +16,17 @@ const keys_1 = require("./keys");
|
|
|
16
16
|
let GraphQLComponent = class GraphQLComponent {
|
|
17
17
|
constructor(app) {
|
|
18
18
|
this.bindings = [
|
|
19
|
-
core_1.createBindingFromClass(graphql_server_1.GraphQLServer),
|
|
20
|
-
core_1.createBindingFromClass(resolver_booter_1.GraphQLResolverBooter),
|
|
19
|
+
(0, core_1.createBindingFromClass)(graphql_server_1.GraphQLServer),
|
|
20
|
+
(0, core_1.createBindingFromClass)(resolver_booter_1.GraphQLResolverBooter),
|
|
21
21
|
];
|
|
22
22
|
app
|
|
23
23
|
.configure(keys_1.GraphQLBindings.GRAPHQL_SERVER)
|
|
24
24
|
.toAlias(keys_1.GraphQLBindings.CONFIG);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
GraphQLComponent = tslib_1.__decorate([
|
|
28
|
-
tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
|
29
|
-
tslib_1.__metadata("design:paramtypes", [core_1.Application])
|
|
27
|
+
GraphQLComponent = (0, tslib_1.__decorate)([
|
|
28
|
+
(0, tslib_1.__param)(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
|
29
|
+
(0, tslib_1.__metadata)("design:paramtypes", [core_1.Application])
|
|
30
30
|
], GraphQLComponent);
|
|
31
31
|
exports.GraphQLComponent = GraphQLComponent;
|
|
32
32
|
//# sourceMappingURL=graphql.component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.component.js","sourceRoot":"","sources":["../src/graphql.component.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAOwB;AACxB,+DAAgE;AAChE,qDAA+C;AAC/C,iCAAuC;AAEvC;;GAEG;AACH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAM3B,YAAuD,GAAgB;QALvE,aAAQ,GAAc;YACpB,6BAAsB,
|
|
1
|
+
{"version":3,"file":"graphql.component.js","sourceRoot":"","sources":["../src/graphql.component.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAOwB;AACxB,+DAAgE;AAChE,qDAA+C;AAC/C,iCAAuC;AAEvC;;GAEG;AACH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAM3B,YAAuD,GAAgB;QALvE,aAAQ,GAAc;YACpB,IAAA,6BAAsB,EAAC,8BAAa,CAAC;YACrC,IAAA,6BAAsB,EAAC,uCAAqB,CAAC;SAC9C,CAAC;QAGA,GAAG;aACA,SAAS,CAAC,sBAAe,CAAC,cAAc,CAAC;aACzC,OAAO,CAAC,sBAAe,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AAXY,gBAAgB;IAMd,wBAAA,IAAA,aAAM,EAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;kDAAM,kBAAW;GAN5D,gBAAgB,CAW5B;AAXY,4CAAgB"}
|
|
@@ -7,9 +7,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.LoopBackContainer = exports.GraphQLResolutionContext = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
const core_1 = require("@loopback/core");
|
|
10
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
10
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
11
11
|
const keys_1 = require("./keys");
|
|
12
|
-
const debug = debug_1.default('loopback:graphql:container');
|
|
12
|
+
const debug = (0, debug_1.default)('loopback:graphql:container');
|
|
13
13
|
const MIDDLEWARE_CONTEXT = Symbol.for('loopback.middleware.context');
|
|
14
14
|
/**
|
|
15
15
|
* Context for graphql resolver resolution
|
|
@@ -44,13 +44,13 @@ class LoopBackContainer {
|
|
|
44
44
|
if (reqCtx == null) {
|
|
45
45
|
resolutionCtx.scope = core_1.BindingScope.REQUEST;
|
|
46
46
|
}
|
|
47
|
-
const resolverBinding = core_1.createBindingFromClass(resolverClass, {
|
|
47
|
+
const resolverBinding = (0, core_1.createBindingFromClass)(resolverClass, {
|
|
48
48
|
defaultNamespace: keys_1.GraphQLBindings.RESOLVERS,
|
|
49
49
|
});
|
|
50
50
|
// Find resolver bindings that match the class
|
|
51
51
|
const bindings = this.ctx
|
|
52
52
|
.findByTag(keys_1.GraphQLTags.RESOLVER)
|
|
53
|
-
.filter(core_1.filterByServiceInterface(resolverClass));
|
|
53
|
+
.filter((0, core_1.filterByServiceInterface)(resolverClass));
|
|
54
54
|
if (bindings.length === 0) {
|
|
55
55
|
// No explicit binding found
|
|
56
56
|
debug('Resolver %s not found in context %s', resolverClass.name, this.ctx.name);
|
|
@@ -65,7 +65,7 @@ class LoopBackContainer {
|
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
67
|
// Narrow down by key
|
|
68
|
-
found = bindings.find(core_1.filterByKey(resolverBinding.key));
|
|
68
|
+
found = bindings.find((0, core_1.filterByKey)(resolverBinding.key));
|
|
69
69
|
if (!found) {
|
|
70
70
|
found = bindings[0];
|
|
71
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.container.js","sourceRoot":"","sources":["../src/graphql.container.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAQwB;AAExB
|
|
1
|
+
{"version":3,"file":"graphql.container.js","sourceRoot":"","sources":["../src/graphql.container.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAQwB;AAExB,+DAAiC;AAEjC,iCAAoD;AAEpD,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,4BAA4B,CAAC,CAAC;AACzD,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAErE;;GAEG;AACH,MAAa,wBAAyB,SAAQ,cAAO;IACnD,YACE,MAAe,EACN,aAAmC,EACnC,YAAmC;QAE5C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHL,kBAAa,GAAb,aAAa,CAAsB;QACnC,iBAAY,GAAZ,YAAY,CAAuB;QAG5C,IAAI,CAAC,IAAI,CAAC,sBAAe,CAAC,aAAa,CAAC,CAAC,EAAE,CAA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AAI,CACd,CAAC;YACF,gEAAgE;YAChE,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YACnC,OAAO,aAAa,CAAC,iBAAiB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;SAC7D;QAED,IAAI,KAAoC,CAAC;QACzC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,yBAAyB;YACzB,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;SACrB;aAAM;YACL,qBAAqB;YACrB,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAA,kBAAW,EAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;YACxD,IAAI,CAAC,KAAK,EAAE;gBACV,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;aACrB;SACF;QAED,KAAK,CACH,iCAAiC,EACjC,aAAa,CAAC,IAAI,EAClB,aAAa,CAAC,IAAI,EAClB,KAAK,CACN,CAAC;QACF,OAAO,aAAa,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;CACF;AA7DD,8CA6DC"}
|
package/dist/graphql.server.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare class GraphQLServer extends Context implements Server {
|
|
|
31
31
|
* @param nameOrOptions - Resolver name or binding options
|
|
32
32
|
*/
|
|
33
33
|
resolver(resolverClass: Constructor<ResolverInterface<object>>, nameOrOptions?: string | BindingFromClassOptions): Binding<any>;
|
|
34
|
+
private _setupSchema;
|
|
34
35
|
start(): Promise<void>;
|
|
36
|
+
exportGraphQLSchema(outFile?: string, log?: (message?: any, ...optionalParams: any[]) => void): Promise<void>;
|
|
35
37
|
stop(): Promise<void>;
|
|
36
38
|
/**
|
|
37
39
|
* Is the GraphQL listening
|
package/dist/graphql.server.js
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.registerResolver = exports.GraphQLServer = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
9
10
|
const core_1 = require("@loopback/core");
|
|
10
11
|
const http_server_1 = require("@loopback/http-server");
|
|
11
12
|
const apollo_server_express_1 = require("apollo-server-express");
|
|
12
|
-
const express_1 = tslib_1.__importDefault(require("express"));
|
|
13
|
+
const express_1 = (0, tslib_1.__importDefault)(require("express"));
|
|
14
|
+
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
15
|
+
const graphql_1 = require("graphql");
|
|
13
16
|
const type_graphql_1 = require("type-graphql");
|
|
14
17
|
const graphql_container_1 = require("./graphql.container");
|
|
15
18
|
const keys_1 = require("./keys");
|
|
@@ -21,7 +24,7 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
21
24
|
super(parent, 'graphql-server');
|
|
22
25
|
this.options = options;
|
|
23
26
|
this.scope = core_1.BindingScope.SERVER;
|
|
24
|
-
this.expressApp = express_1.default();
|
|
27
|
+
this.expressApp = (0, express_1.default)();
|
|
25
28
|
if (options.expressSettings) {
|
|
26
29
|
for (const p in options.expressSettings) {
|
|
27
30
|
this.expressApp.set(p, options.expressSettings[p]);
|
|
@@ -37,7 +40,7 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
37
40
|
* Get a list of resolver classes
|
|
38
41
|
*/
|
|
39
42
|
getResolverClasses() {
|
|
40
|
-
const view = this.createView(core_1.filterByTag(keys_1.GraphQLTags.RESOLVER));
|
|
43
|
+
const view = this.createView((0, core_1.filterByTag)(keys_1.GraphQLTags.RESOLVER));
|
|
41
44
|
return view.bindings
|
|
42
45
|
.filter(b => b.valueConstructor != null)
|
|
43
46
|
.map(b => b.valueConstructor);
|
|
@@ -46,7 +49,7 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
46
49
|
* Get a list of middleware
|
|
47
50
|
*/
|
|
48
51
|
async getMiddlewareList() {
|
|
49
|
-
const view = this.createView(core_1.filterByTag(keys_1.GraphQLTags.MIDDLEWARE));
|
|
52
|
+
const view = this.createView((0, core_1.filterByTag)(keys_1.GraphQLTags.MIDDLEWARE));
|
|
50
53
|
return view.values();
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
@@ -66,8 +69,8 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
66
69
|
resolver(resolverClass, nameOrOptions) {
|
|
67
70
|
return registerResolver(this, resolverClass, nameOrOptions);
|
|
68
71
|
}
|
|
69
|
-
async
|
|
70
|
-
var _a, _b
|
|
72
|
+
async _setupSchema() {
|
|
73
|
+
var _a, _b;
|
|
71
74
|
const resolverClasses = this.getResolverClasses();
|
|
72
75
|
// Get the configured auth checker
|
|
73
76
|
const authChecker = (_a = (await this.get(keys_1.GraphQLBindings.GRAPHQL_AUTH_CHECKER, {
|
|
@@ -77,7 +80,7 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
77
80
|
optional: true,
|
|
78
81
|
}))) !== null && _b !== void 0 ? _b : new apollo_server_express_1.PubSub();
|
|
79
82
|
// build TypeGraphQL executable schema
|
|
80
|
-
const
|
|
83
|
+
const buildSchemaOptions = {
|
|
81
84
|
// See https://github.com/MichalLytek/type-graphql/issues/150#issuecomment-420181526
|
|
82
85
|
validate: false,
|
|
83
86
|
resolvers: resolverClasses,
|
|
@@ -87,11 +90,16 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
87
90
|
authChecker,
|
|
88
91
|
pubSub,
|
|
89
92
|
globalMiddlewares: await this.getMiddlewareList(),
|
|
90
|
-
}
|
|
93
|
+
};
|
|
94
|
+
return (0, type_graphql_1.buildSchema)(buildSchemaOptions);
|
|
95
|
+
}
|
|
96
|
+
async start() {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
const schema = await this._setupSchema();
|
|
91
99
|
// Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
|
|
92
|
-
const graphqlContextResolver = (
|
|
100
|
+
const graphqlContextResolver = (_a = (await this.get(keys_1.GraphQLBindings.GRAPHQL_CONTEXT_RESOLVER, {
|
|
93
101
|
optional: true,
|
|
94
|
-
}))) !== null &&
|
|
102
|
+
}))) !== null && _a !== void 0 ? _a : (context => context);
|
|
95
103
|
// Create ApolloServerExpress GraphQL server
|
|
96
104
|
const serverConfig = {
|
|
97
105
|
// enable GraphQL Playground
|
|
@@ -108,10 +116,20 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
108
116
|
});
|
|
109
117
|
// Set up subscription handlers
|
|
110
118
|
if (this.httpServer && serverConfig.subscriptions) {
|
|
111
|
-
graphQLServer.installSubscriptionHandlers((
|
|
119
|
+
graphQLServer.installSubscriptionHandlers((_b = this.httpServer) === null || _b === void 0 ? void 0 : _b.server);
|
|
112
120
|
}
|
|
113
121
|
// Start the http server if created
|
|
114
|
-
await ((
|
|
122
|
+
await ((_c = this.httpServer) === null || _c === void 0 ? void 0 : _c.start());
|
|
123
|
+
}
|
|
124
|
+
async exportGraphQLSchema(outFile = '', log = console.log) {
|
|
125
|
+
const schema = await this._setupSchema();
|
|
126
|
+
const schemaFileContent = (0, utils_1.printSchemaWithDirectives)((0, graphql_1.lexicographicSortSchema)(schema));
|
|
127
|
+
if (outFile === '-' || outFile === '') {
|
|
128
|
+
log('%s', schemaFileContent);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
fs_1.default.writeFileSync(outFile, schemaFileContent, 'utf-8');
|
|
132
|
+
}
|
|
115
133
|
}
|
|
116
134
|
async stop() {
|
|
117
135
|
var _a;
|
|
@@ -126,14 +144,14 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
126
144
|
return !!((_a = this.httpServer) === null || _a === void 0 ? void 0 : _a.listening);
|
|
127
145
|
}
|
|
128
146
|
};
|
|
129
|
-
GraphQLServer = tslib_1.__decorate([
|
|
130
|
-
core_1.lifeCycleObserver('server', {
|
|
147
|
+
GraphQLServer = (0, tslib_1.__decorate)([
|
|
148
|
+
(0, core_1.lifeCycleObserver)('server', {
|
|
131
149
|
scope: core_1.BindingScope.SINGLETON,
|
|
132
150
|
tags: { [core_1.ContextTags.KEY]: keys_1.GraphQLBindings.GRAPHQL_SERVER },
|
|
133
151
|
}),
|
|
134
|
-
tslib_1.__param(0, core_1.config()),
|
|
135
|
-
tslib_1.__param(1, core_1.inject.context()),
|
|
136
|
-
tslib_1.__metadata("design:paramtypes", [Object, core_1.Context])
|
|
152
|
+
(0, tslib_1.__param)(0, (0, core_1.config)()),
|
|
153
|
+
(0, tslib_1.__param)(1, core_1.inject.context()),
|
|
154
|
+
(0, tslib_1.__metadata)("design:paramtypes", [Object, core_1.Context])
|
|
137
155
|
], GraphQLServer);
|
|
138
156
|
exports.GraphQLServer = GraphQLServer;
|
|
139
157
|
/**
|
|
@@ -143,7 +161,7 @@ exports.GraphQLServer = GraphQLServer;
|
|
|
143
161
|
* @param nameOrOptions - Resolver name or binding options
|
|
144
162
|
*/
|
|
145
163
|
function registerResolver(ctx, resolverClass, nameOrOptions) {
|
|
146
|
-
const binding = core_1.createBindingFromClass(resolverClass, {
|
|
164
|
+
const binding = (0, core_1.createBindingFromClass)(resolverClass, {
|
|
147
165
|
namespace: keys_1.GraphQLBindings.RESOLVERS,
|
|
148
166
|
...toOptions(nameOrOptions),
|
|
149
167
|
}).tag(keys_1.GraphQLTags.RESOLVER);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.server.js","sourceRoot":"","sources":["../src/graphql.server.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAcwB;AACxB,uDAAiD;AAEjD,iEAK+B;AAE/B,
|
|
1
|
+
{"version":3,"file":"graphql.server.js","sourceRoot":"","sources":["../src/graphql.server.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,gDAA+D;AAC/D,yCAcwB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,EAAE;QACrC,OAAO,EAAC,IAAI,EAAE,aAAa,EAAC,CAAC;KAC9B;IACD,OAAO,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const tslib_1 = require("tslib");
|
|
8
|
-
tslib_1.__exportStar(require("type-graphql"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./decorators"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./graphql.component"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./graphql.container"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./graphql.server"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./keys"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("type-graphql"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./decorators"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./graphql.component"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./graphql.container"), exports);
|
|
12
|
+
(0, tslib_1.__exportStar)(require("./graphql.server"), exports);
|
|
13
|
+
(0, tslib_1.__exportStar)(require("./keys"), exports);
|
|
14
|
+
(0, tslib_1.__exportStar)(require("./types"), exports);
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,4DAA6B;AAC7B,4DAA6B;AAC7B,mEAAoC;AACpC,mEAAoC;AACpC,gEAAiC;AACjC,sDAAuB;AACvB,uDAAwB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/graphql",
|
|
3
3
|
"description": "LoopBack's graphql integration",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"LoopBack",
|
|
7
7
|
"GraphQL"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"directory": "extensions/graphql"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": "
|
|
20
|
+
"node": "12 || 14 || 16 || 17"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
|
|
@@ -39,28 +39,29 @@
|
|
|
39
39
|
"!*/__tests__"
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@loopback/boot": "^
|
|
43
|
-
"@loopback/core": "^
|
|
42
|
+
"@loopback/boot": "^4.1.0",
|
|
43
|
+
"@loopback/core": "^3.1.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
46
|
+
"@graphql-tools/utils": "^8.6.1",
|
|
47
|
+
"@loopback/http-server": "^3.1.0",
|
|
48
|
+
"apollo-server-express": "^2.25.3",
|
|
49
|
+
"debug": "^4.3.3",
|
|
50
|
+
"express": "^4.17.2",
|
|
51
|
+
"graphql": "^15.8.0",
|
|
51
52
|
"type-graphql": "^1.1.1"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@loopback/boot": "^
|
|
55
|
-
"@loopback/build": "^
|
|
56
|
-
"@loopback/core": "^
|
|
57
|
-
"@loopback/eslint-config": "^
|
|
58
|
-
"@loopback/repository": "^
|
|
59
|
-
"@loopback/rest": "^
|
|
60
|
-
"@loopback/testlab": "^
|
|
55
|
+
"@loopback/boot": "^4.1.0",
|
|
56
|
+
"@loopback/build": "^8.1.0",
|
|
57
|
+
"@loopback/core": "^3.1.0",
|
|
58
|
+
"@loopback/eslint-config": "^12.0.2",
|
|
59
|
+
"@loopback/repository": "^4.1.0",
|
|
60
|
+
"@loopback/rest": "^11.1.0",
|
|
61
|
+
"@loopback/testlab": "^4.1.0",
|
|
61
62
|
"@types/debug": "^4.1.7",
|
|
62
|
-
"@types/node": "^
|
|
63
|
-
"class-transformer": "^0.
|
|
63
|
+
"@types/node": "^12.20.43",
|
|
64
|
+
"class-transformer": "^0.5.1"
|
|
64
65
|
},
|
|
65
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "e16818ccb01edc0269ef6c45b022c5f1b67f852c"
|
|
66
67
|
}
|
package/src/graphql.server.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
+
import {printSchemaWithDirectives} from '@graphql-tools/utils';
|
|
6
7
|
import {
|
|
7
8
|
Binding,
|
|
8
9
|
BindingFromClassOptions,
|
|
@@ -28,9 +29,12 @@ import {
|
|
|
28
29
|
} from 'apollo-server-express';
|
|
29
30
|
import {ExpressContext} from 'apollo-server-express/dist/ApolloServer';
|
|
30
31
|
import express from 'express';
|
|
32
|
+
import fs from 'fs';
|
|
33
|
+
import {lexicographicSortSchema} from 'graphql';
|
|
31
34
|
import {
|
|
32
35
|
AuthChecker,
|
|
33
36
|
buildSchema,
|
|
37
|
+
BuildSchemaOptions as TypeGrahpQLBuildSchemaOptions,
|
|
34
38
|
NonEmptyArray,
|
|
35
39
|
ResolverInterface,
|
|
36
40
|
} from 'type-graphql';
|
|
@@ -113,7 +117,7 @@ export class GraphQLServer extends Context implements Server {
|
|
|
113
117
|
return registerResolver(this, resolverClass, nameOrOptions);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
async
|
|
120
|
+
private async _setupSchema() {
|
|
117
121
|
const resolverClasses =
|
|
118
122
|
this.getResolverClasses() as unknown as NonEmptyArray<Function>;
|
|
119
123
|
|
|
@@ -129,7 +133,7 @@ export class GraphQLServer extends Context implements Server {
|
|
|
129
133
|
})) ?? new PubSub();
|
|
130
134
|
|
|
131
135
|
// build TypeGraphQL executable schema
|
|
132
|
-
const
|
|
136
|
+
const buildSchemaOptions: TypeGrahpQLBuildSchemaOptions = {
|
|
133
137
|
// See https://github.com/MichalLytek/type-graphql/issues/150#issuecomment-420181526
|
|
134
138
|
validate: false,
|
|
135
139
|
resolvers: resolverClasses,
|
|
@@ -139,7 +143,12 @@ export class GraphQLServer extends Context implements Server {
|
|
|
139
143
|
authChecker,
|
|
140
144
|
pubSub,
|
|
141
145
|
globalMiddlewares: await this.getMiddlewareList(),
|
|
142
|
-
}
|
|
146
|
+
};
|
|
147
|
+
return buildSchema(buildSchemaOptions);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async start() {
|
|
151
|
+
const schema = await this._setupSchema();
|
|
143
152
|
|
|
144
153
|
// Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
|
|
145
154
|
const graphqlContextResolver: ContextFunction<ExpressContext> =
|
|
@@ -171,6 +180,18 @@ export class GraphQLServer extends Context implements Server {
|
|
|
171
180
|
await this.httpServer?.start();
|
|
172
181
|
}
|
|
173
182
|
|
|
183
|
+
async exportGraphQLSchema(outFile = '', log = console.log) {
|
|
184
|
+
const schema = await this._setupSchema();
|
|
185
|
+
const schemaFileContent = printSchemaWithDirectives(
|
|
186
|
+
lexicographicSortSchema(schema),
|
|
187
|
+
);
|
|
188
|
+
if (outFile === '-' || outFile === '') {
|
|
189
|
+
log('%s', schemaFileContent);
|
|
190
|
+
} else {
|
|
191
|
+
fs.writeFileSync(outFile, schemaFileContent, 'utf-8');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
174
195
|
async stop() {
|
|
175
196
|
// Stop the http server if created
|
|
176
197
|
await this.httpServer?.stop();
|