@loopback/graphql 0.11.13 → 0.12.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/dist/booters/resolver.booter.d.ts +1 -1
- package/dist/booters/resolver.booter.js +3 -3
- package/dist/booters/resolver.booter.js.map +1 -1
- package/dist/graphql.container.d.ts +3 -3
- package/dist/graphql.container.js.map +1 -1
- package/dist/graphql.server.d.ts +10 -6
- package/dist/graphql.server.js +83 -13
- package/dist/graphql.server.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +8 -4
- package/dist/keys.js +1 -0
- package/dist/keys.js.map +1 -1
- package/dist/types.d.ts +11 -6
- package/dist/types.js.map +1 -1
- package/package.json +23 -16
- package/src/booters/resolver.booter.ts +8 -8
- package/src/graphql.container.ts +5 -8
- package/src/graphql.server.ts +109 -25
- package/src/index.ts +1 -0
- package/src/keys.ts +9 -4
- package/src/types.ts +18 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Application, Constructor } from '@loopback/core';
|
|
2
1
|
import { ArtifactOptions, BaseArtifactBooter } from '@loopback/boot';
|
|
2
|
+
import { Application, Constructor } from '@loopback/core';
|
|
3
3
|
type GraphQLResolverClass = Constructor<object>;
|
|
4
4
|
/**
|
|
5
5
|
* A class that extends BaseArtifactBooter to boot the 'GraphQLResolver' artifact type.
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.GraphQLResolverDefaults = exports.GraphQLResolverBooter = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
|
-
const core_1 = require("@loopback/core");
|
|
10
9
|
const boot_1 = require("@loopback/boot");
|
|
11
|
-
const
|
|
10
|
+
const core_1 = require("@loopback/core");
|
|
12
11
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
12
|
+
const type_graphql_1 = require("type-graphql");
|
|
13
13
|
const graphql_server_1 = require("../graphql.server");
|
|
14
14
|
const debug = (0, debug_1.default)('loopback:graphql:resolver-booter');
|
|
15
15
|
/**
|
|
@@ -39,7 +39,7 @@ let GraphQLResolverBooter = class GraphQLResolverBooter extends boot_1.BaseArtif
|
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
40
|
(0, type_graphql_1.getMetadataStorage)().resolverClasses;
|
|
41
41
|
this.resolvers = this.classes.filter(cls => {
|
|
42
|
-
return resolverClasses.some(r =>
|
|
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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.booter.js","sourceRoot":"","sources":["../../src/booters/resolver.booter.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAMwB;AACxB,
|
|
1
|
+
{"version":3,"file":"resolver.booter.js","sourceRoot":"","sources":["../../src/booters/resolver.booter.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAKwB;AACxB,yCAMwB;AACxB,0DAAiC;AACjC,+CAAgD;AAEhD,sDAAmD;AAEnD,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,kCAAkC,CAAC,CAAC;AAI/D;;;;;;;;GAQG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,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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GraphQLResolutionContext extends Context {
|
|
7
7
|
readonly resolverClass: Constructor<unknown>;
|
|
8
|
-
readonly resolverData: ResolverData<
|
|
9
|
-
constructor(parent: Context, resolverClass: Constructor<unknown>, resolverData: ResolverData<
|
|
8
|
+
readonly resolverData: ResolverData<object>;
|
|
9
|
+
constructor(parent: Context, resolverClass: Constructor<unknown>, resolverData: ResolverData<object>);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Implementation of `ContainerType` to plug into `type-graphql` as the IoC
|
|
@@ -15,5 +15,5 @@ export declare class GraphQLResolutionContext extends Context {
|
|
|
15
15
|
export declare class LoopBackContainer implements ContainerType {
|
|
16
16
|
readonly ctx: Context;
|
|
17
17
|
constructor(ctx: Context);
|
|
18
|
-
get(resolverClass: Constructor<unknown>, resolverData: ResolverData<
|
|
18
|
+
get(resolverClass: Constructor<unknown>, resolverData: ResolverData<object>): unknown;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.container.js","sourceRoot":"","sources":["../src/graphql.container.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;
|
|
1
|
+
{"version":3,"file":"graphql.container.js","sourceRoot":"","sources":["../src/graphql.container.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAGhE,yCAQwB;AACxB,0DAAiC;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,YAAkC;QAE3C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHL,kBAAa,GAAb,aAAa,CAAsB;QACnC,iBA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YACzB,4BAA4B;YAC5B,KAAK,CACH,qCAAqC,EACrC,aAAa,CAAC,IAAI,EAClB,IAAI,CAAC,GAAG,CAAC,IAAI,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;AA1DD,8CA0DC"}
|
package/dist/graphql.server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Binding, BindingFromClassOptions, Constructor, Context, Server } from '@loopback/core';
|
|
2
2
|
import { HttpServer } from '@loopback/http-server';
|
|
3
3
|
import express from 'express';
|
|
4
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
5
|
import { ResolverInterface } from 'type-graphql';
|
|
5
6
|
import { Middleware } from 'type-graphql/dist/interfaces/Middleware';
|
|
6
7
|
import { GraphQLServerOptions } from './types';
|
|
@@ -11,6 +12,9 @@ export declare class GraphQLServer extends Context implements Server {
|
|
|
11
12
|
private options;
|
|
12
13
|
readonly httpServer?: HttpServer;
|
|
13
14
|
readonly expressApp: express.Application;
|
|
15
|
+
private schema?;
|
|
16
|
+
private wsServer?;
|
|
17
|
+
private wsHttpServer?;
|
|
14
18
|
constructor(options?: GraphQLServerOptions, parent?: Context);
|
|
15
19
|
/**
|
|
16
20
|
* Get a list of resolver classes
|
|
@@ -19,12 +23,12 @@ export declare class GraphQLServer extends Context implements Server {
|
|
|
19
23
|
/**
|
|
20
24
|
* Get a list of middleware
|
|
21
25
|
*/
|
|
22
|
-
getMiddlewareList(): Promise<Middleware<
|
|
26
|
+
getMiddlewareList(): Promise<Middleware<object>[]>;
|
|
23
27
|
/**
|
|
24
28
|
* Register a GraphQL middleware
|
|
25
29
|
* @param middleware - GraphQL middleware
|
|
26
30
|
*/
|
|
27
|
-
middleware<T =
|
|
31
|
+
middleware<T extends object = object>(middleware: Middleware<T>): Binding<Middleware<T>>;
|
|
28
32
|
/**
|
|
29
33
|
* Register a GraphQL resolver class
|
|
30
34
|
* @param resolverClass -GraphQL resolver class
|
|
@@ -33,15 +37,15 @@ export declare class GraphQLServer extends Context implements Server {
|
|
|
33
37
|
resolver(resolverClass: Constructor<ResolverInterface<object>>, nameOrOptions?: string | BindingFromClassOptions): Binding<any>;
|
|
34
38
|
private _setupSchema;
|
|
35
39
|
start(): Promise<void>;
|
|
36
|
-
exportGraphQLSchema(outFile?: string, log?:
|
|
37
|
-
(...data: any[]): void;
|
|
38
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
39
|
-
}): Promise<void>;
|
|
40
|
+
exportGraphQLSchema(outFile?: string, log?: (message?: any, ...optionalParams: any[]) => void): Promise<void>;
|
|
40
41
|
stop(): Promise<void>;
|
|
41
42
|
/**
|
|
42
43
|
* Is the GraphQL listening
|
|
43
44
|
*/
|
|
44
45
|
get listening(): boolean;
|
|
46
|
+
getSchema(): GraphQLSchema;
|
|
47
|
+
private closeWsHttpServer;
|
|
48
|
+
private closeWsServer;
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Register a GraphQL resolver class
|
package/dist/graphql.server.js
CHANGED
|
@@ -6,17 +6,24 @@
|
|
|
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 server_1 = require("@apollo/server");
|
|
10
|
+
const express4_1 = require("@apollo/server/express4");
|
|
9
11
|
const utils_1 = require("@graphql-tools/utils");
|
|
10
12
|
const core_1 = require("@loopback/core");
|
|
11
13
|
const http_server_1 = require("@loopback/http-server");
|
|
14
|
+
const rest_1 = require("@loopback/rest");
|
|
15
|
+
const body_parser_1 = tslib_1.__importDefault(require("body-parser"));
|
|
16
|
+
const cors_1 = tslib_1.__importDefault(require("cors"));
|
|
17
|
+
const express_1 = tslib_1.__importDefault(require("express"));
|
|
12
18
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
13
|
-
const apollo_server_express_1 = require("apollo-server-express");
|
|
14
|
-
const graphql_subscriptions_1 = require("graphql-subscriptions");
|
|
15
19
|
const graphql_1 = require("graphql");
|
|
16
|
-
const
|
|
20
|
+
const graphql_subscriptions_1 = require("graphql-subscriptions");
|
|
21
|
+
const ws_1 = require("graphql-ws/lib/use/ws");
|
|
17
22
|
const type_graphql_1 = require("type-graphql");
|
|
23
|
+
const ws_2 = require("ws");
|
|
18
24
|
const graphql_container_1 = require("./graphql.container");
|
|
19
25
|
const keys_1 = require("./keys");
|
|
26
|
+
const { json } = body_parser_1.default;
|
|
20
27
|
/**
|
|
21
28
|
* GraphQL Server
|
|
22
29
|
*/
|
|
@@ -82,8 +89,7 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
82
89
|
}))) !== null && _b !== void 0 ? _b : new graphql_subscriptions_1.PubSub();
|
|
83
90
|
// build TypeGraphQL executable schema
|
|
84
91
|
const buildSchemaOptions = {
|
|
85
|
-
|
|
86
|
-
validate: false,
|
|
92
|
+
validate: !!this.options.validate,
|
|
87
93
|
resolvers: resolverClasses,
|
|
88
94
|
// automatically create `schema.gql` file with schema definition in current folder
|
|
89
95
|
// emitSchemaFile: path.resolve(__dirname, 'schema.gql'),
|
|
@@ -95,26 +101,51 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
95
101
|
return (0, type_graphql_1.buildSchema)(buildSchemaOptions);
|
|
96
102
|
}
|
|
97
103
|
async start() {
|
|
98
|
-
var _a, _b;
|
|
104
|
+
var _a, _b, _c, _d, _e, _f;
|
|
99
105
|
const schema = await this._setupSchema();
|
|
106
|
+
this.schema = schema;
|
|
100
107
|
// Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
|
|
101
108
|
const graphqlContextResolver = (_a = (await this.get(keys_1.GraphQLBindings.GRAPHQL_CONTEXT_RESOLVER, {
|
|
102
109
|
optional: true,
|
|
103
|
-
}))) !== null && _a !== void 0 ? _a : (context => context);
|
|
110
|
+
}))) !== null && _a !== void 0 ? _a : (async (context) => context);
|
|
111
|
+
// Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
|
|
112
|
+
const graphqlWsContextResolver = (_b = (await this.get(keys_1.GraphQLBindings.GRAPHQL_WS_CONTEXT_RESOLVER, {
|
|
113
|
+
optional: true,
|
|
114
|
+
}))) !== null && _b !== void 0 ? _b : (async (context) => {
|
|
115
|
+
return context;
|
|
116
|
+
});
|
|
104
117
|
// Create ApolloServerExpress GraphQL server
|
|
105
118
|
const serverConfig = {
|
|
106
|
-
context: graphqlContextResolver,
|
|
107
119
|
...this.options.apollo,
|
|
108
120
|
schema,
|
|
121
|
+
status400ForVariableCoercionErrors: true,
|
|
122
|
+
// plugins: [ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer })],
|
|
109
123
|
};
|
|
110
|
-
const graphQLServer = new
|
|
124
|
+
const graphQLServer = new server_1.ApolloServer(serverConfig);
|
|
111
125
|
await graphQLServer.start();
|
|
112
|
-
|
|
113
|
-
|
|
126
|
+
this.expressApp.use((_c = this.options.graphQLPath) !== null && _c !== void 0 ? _c : '/', (0, cors_1.default)(), json(), (0, express4_1.expressMiddleware)(graphQLServer, {
|
|
127
|
+
context: graphqlContextResolver,
|
|
114
128
|
...this.options.middlewareOptions,
|
|
115
|
-
});
|
|
129
|
+
}));
|
|
116
130
|
// Start the http server if created
|
|
117
|
-
await ((
|
|
131
|
+
await ((_d = this.httpServer) === null || _d === void 0 ? void 0 : _d.start());
|
|
132
|
+
let server;
|
|
133
|
+
if (this.options.asMiddlewareOnly) {
|
|
134
|
+
const rest = await this.get(rest_1.RestBindings.SERVER);
|
|
135
|
+
server = (_e = rest.httpServer) === null || _e === void 0 ? void 0 : _e.server;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
server = (_f = this.httpServer) === null || _f === void 0 ? void 0 : _f.server;
|
|
139
|
+
}
|
|
140
|
+
const wsServer = new ws_2.WebSocketServer({
|
|
141
|
+
server: server,
|
|
142
|
+
path: this.options.path,
|
|
143
|
+
});
|
|
144
|
+
this.wsServer = wsServer;
|
|
145
|
+
(0, ws_1.useServer)({
|
|
146
|
+
schema,
|
|
147
|
+
context: graphqlWsContextResolver,
|
|
148
|
+
}, wsServer);
|
|
118
149
|
}
|
|
119
150
|
async exportGraphQLSchema(outFile = '', log = console.log) {
|
|
120
151
|
const schema = await this._setupSchema();
|
|
@@ -130,6 +161,10 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
130
161
|
var _a;
|
|
131
162
|
// Stop the http server if created
|
|
132
163
|
await ((_a = this.httpServer) === null || _a === void 0 ? void 0 : _a.stop());
|
|
164
|
+
// Stop ws http server
|
|
165
|
+
await this.closeWsHttpServer();
|
|
166
|
+
// Stop the websocket server if created
|
|
167
|
+
await this.closeWsServer();
|
|
133
168
|
}
|
|
134
169
|
/**
|
|
135
170
|
* Is the GraphQL listening
|
|
@@ -138,6 +173,41 @@ let GraphQLServer = class GraphQLServer extends core_1.Context {
|
|
|
138
173
|
var _a;
|
|
139
174
|
return !!((_a = this.httpServer) === null || _a === void 0 ? void 0 : _a.listening);
|
|
140
175
|
}
|
|
176
|
+
getSchema() {
|
|
177
|
+
return this.schema;
|
|
178
|
+
}
|
|
179
|
+
closeWsHttpServer() {
|
|
180
|
+
if (!this.wsHttpServer) {
|
|
181
|
+
return Promise.resolve();
|
|
182
|
+
}
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
var _a;
|
|
185
|
+
(_a = this.wsHttpServer) === null || _a === void 0 ? void 0 : _a.close(err => {
|
|
186
|
+
if (err) {
|
|
187
|
+
reject(err);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
resolve();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
closeWsServer() {
|
|
196
|
+
if (!this.wsServer) {
|
|
197
|
+
return Promise.resolve();
|
|
198
|
+
}
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
var _a;
|
|
201
|
+
(_a = this.wsServer) === null || _a === void 0 ? void 0 : _a.close(err => {
|
|
202
|
+
if (err) {
|
|
203
|
+
reject(err);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
resolve();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
141
211
|
};
|
|
142
212
|
exports.GraphQLServer = GraphQLServer;
|
|
143
213
|
exports.GraphQLServer = GraphQLServer = tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.server.js","sourceRoot":"","sources":["../src/graphql.server.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,gDAA+D;AAC/D,yCAcwB;AACxB,uDAAiD;AACjD,oDAAoB;
|
|
1
|
+
{"version":3,"file":"graphql.server.js","sourceRoot":"","sources":["../src/graphql.server.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,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AAC;IACL,CAAC;CACF,CAAA;AA7NY,sCAAa;wBAAb,aAAa;IAJzB,IAAA,wBAAiB,EAAC,QAAQ,EAAE;QAC3B,KAAK,EAAE,mBAAY,CAAC,SAAS;QAC7B,IAAI,EAAE,EAAC,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,sBAAe,CAAC,cAAc,EAAC;KAC1D,CAAC;IASG,mBAAA,IAAA,aAAM,GAAE,CAAA;IACR,mBAAA,aAAM,CAAC,OAAO,EAAE,CAAA;qDACR,cAAO;GAVP,aAAa,CA6NzB;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,GAAY,EACZ,aAAkC,EAClC,aAAgD;IAEhD,MAAM,OAAO,GAAG,IAAA,6BAAsB,EAAC,aAAa,EAAE;QACpD,SAAS,EAAE,sBAAe,CAAC,SAAS;QACpC,GAAG,SAAS,CAAC,aAAa,CAAC;KAC5B,CAAC,CAAC,GAAG,CAAC,kBAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACjB,OAAO,OAAO,CAAC;AACjB,CAAC;AAXD,4CAWC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAC,aAAgD;IACjE,IAAI,OAAO,aAAa,KAAK,QAAQ,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.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const tslib_1 = require("tslib");
|
|
8
8
|
tslib_1.__exportStar(require("type-graphql"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("type-graphql/dist/interfaces"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./decorators"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./graphql.component"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./graphql.container"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,uDAA6B;AAC7B,uDAA6B;AAC7B,8DAAoC;AACpC,8DAAoC;AACpC,2DAAiC;AACjC,iDAAuB;AACvB,kDAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,uDAA6B;AAC7B,uEAA6C;AAC7C,uDAA6B;AAC7B,8DAAoC;AACpC,8DAAoC;AACpC,2DAAiC;AACjC,iDAAuB;AACvB,kDAAwB"}
|
package/dist/keys.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BindingKey, Constructor } from '@loopback/core';
|
|
2
|
-
import {
|
|
2
|
+
import { PubSubEngine } from 'graphql-subscriptions';
|
|
3
|
+
import { AuthChecker, ResolverData } from 'type-graphql';
|
|
3
4
|
import { GraphQLComponent } from './graphql.component';
|
|
4
5
|
import { GraphQLServer } from './graphql.server';
|
|
5
|
-
import {
|
|
6
|
+
import { GraphQLServerOptions, GraphQLWsContextResolver } from './types';
|
|
6
7
|
/**
|
|
7
8
|
* Namespace for GraphQL related bindings
|
|
8
9
|
*/
|
|
@@ -22,7 +23,10 @@ export declare namespace GraphQLBindings {
|
|
|
22
23
|
/**
|
|
23
24
|
* Binding key for the GraphQL context resolver
|
|
24
25
|
*/
|
|
25
|
-
const GRAPHQL_CONTEXT_RESOLVER: BindingKey<ContextFunction<
|
|
26
|
+
const GRAPHQL_CONTEXT_RESOLVER: BindingKey<import("@apollo/server").ContextFunction<[import("@apollo/server/dist/esm/express4").ExpressContextFunctionArgument], {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}> | undefined>;
|
|
29
|
+
const GRAPHQL_WS_CONTEXT_RESOLVER: BindingKey<GraphQLWsContextResolver>;
|
|
26
30
|
/**
|
|
27
31
|
* Binding key for the GraphQL auth checker
|
|
28
32
|
*/
|
|
@@ -34,7 +38,7 @@ export declare namespace GraphQLBindings {
|
|
|
34
38
|
/**
|
|
35
39
|
* Binding key for the GraphQL resolver data - which is bound per request
|
|
36
40
|
*/
|
|
37
|
-
const RESOLVER_DATA: BindingKey<ResolverData<
|
|
41
|
+
const RESOLVER_DATA: BindingKey<ResolverData<object>>;
|
|
38
42
|
/**
|
|
39
43
|
* Binding key for the current resolver class
|
|
40
44
|
*/
|
package/dist/keys.js
CHANGED
|
@@ -27,6 +27,7 @@ var GraphQLBindings;
|
|
|
27
27
|
* Binding key for the GraphQL context resolver
|
|
28
28
|
*/
|
|
29
29
|
GraphQLBindings.GRAPHQL_CONTEXT_RESOLVER = core_1.BindingKey.create('graphql.contextResolver');
|
|
30
|
+
GraphQLBindings.GRAPHQL_WS_CONTEXT_RESOLVER = core_1.BindingKey.create('graphql.wsContextResolver');
|
|
30
31
|
/**
|
|
31
32
|
* Binding key for the GraphQL auth checker
|
|
32
33
|
*/
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAGhE,yCAAqE;AAOrE;;GAEG;AACH,IAAiB,eAAe,CA+D/B;AA/DD,WAAiB,eAAe;IAC9B;;OAEG;IACU,sBAAM,GACjB,mBAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAE1D;;OAEG;IACU,8BAAc,GAAG,iBAAU,CAAC,MAAM,CAC7C,uBAAuB,CACxB,CAAC;IAEF;;OAEG;IACU,yBAAS,GAAG,iBAAU,CAAC,MAAM,CACxC,6BAA6B,CAC9B,CAAC;IAEF;;OAEG;IACU,wCAAwB,GAAG,iBAAU,CAAC,MAAM,CAEvD,yBAAyB,CAAC,CAAC;IAEhB,2CAA2B,GACtC,iBAAU,CAAC,MAAM,CAA2B,2BAA2B,CAAC,CAAC;IAE3E;;OAEG;IACU,oCAAoB,GAAG,iBAAU,CAAC,MAAM,CACnD,qBAAqB,CACtB,CAAC;IAEF;;OAEG;IACU,8BAAc,GAAG,iBAAU,CAAC,MAAM,CAC7C,sBAAsB,CACvB,CAAC;IAEF;;OAEG;IACU,6BAAa,GAAG,iBAAU,CAAC,MAAM,CAC5C,sBAAsB,CACvB,CAAC;IAEF;;OAEG;IACU,8BAAc,GAAG,iBAAU,CAAC,MAAM,CAC7C,uBAAuB,CACxB,CAAC;IAEF;;OAEG;IACU,yBAAS,GAAG,mBAAmB,CAAC;AAC/C,CAAC,EA/DgB,eAAe,+BAAf,eAAe,QA+D/B;AAED;;GAEG;AACH,IAAiB,WAAW,CAe3B;AAfD,WAAiB,WAAW;IAC1B;;OAEG;IACU,mBAAO,GAAG,SAAS,CAAC;IAEjC;;OAEG;IACU,oBAAQ,GAAG,kBAAkB,CAAC;IAE3C;;OAEG;IACU,sBAAU,GAAG,oBAAoB,CAAC;AACjD,CAAC,EAfgB,WAAW,2BAAX,WAAW,QAe3B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { ApolloServerOptionsWithStaticSchema, BaseContext } from '@apollo/server';
|
|
1
2
|
import { HttpOptions } from '@loopback/http-server';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export { ApolloServerExpressConfig, ExpressContext } from 'apollo-server-express';
|
|
3
|
+
import { ExecutionArgs } from 'graphql';
|
|
4
|
+
import { GraphQLExecutionContextValue, SubscribeMessage } from 'graphql-ws';
|
|
5
5
|
export { Float, ID, Int, ResolverInterface } from 'type-graphql';
|
|
6
6
|
export { Middleware as GraphQLMiddleware } from 'type-graphql/dist/interfaces/Middleware';
|
|
7
7
|
/**
|
|
@@ -12,15 +12,15 @@ export interface GraphQLComponentOptions {
|
|
|
12
12
|
/**
|
|
13
13
|
* Options for GraphQL server
|
|
14
14
|
*/
|
|
15
|
-
export interface GraphQLServerOptions extends HttpOptions {
|
|
15
|
+
export interface GraphQLServerOptions<TContext extends BaseContext = BaseContext> extends HttpOptions {
|
|
16
16
|
/**
|
|
17
17
|
* ApolloServerExpress related configuration
|
|
18
18
|
*/
|
|
19
|
-
apollo?:
|
|
19
|
+
apollo?: Partial<ApolloServerOptionsWithStaticSchema<TContext>>;
|
|
20
20
|
/**
|
|
21
21
|
* Middleware options for GraphQL
|
|
22
22
|
*/
|
|
23
|
-
middlewareOptions?:
|
|
23
|
+
middlewareOptions?: Record<string, unknown>;
|
|
24
24
|
/**
|
|
25
25
|
* Express settings
|
|
26
26
|
*/
|
|
@@ -29,4 +29,9 @@ export interface GraphQLServerOptions extends HttpOptions {
|
|
|
29
29
|
* Use as a middleware for RestServer instead of a standalone server
|
|
30
30
|
*/
|
|
31
31
|
asMiddlewareOnly?: boolean;
|
|
32
|
+
graphQLPath?: string;
|
|
33
|
+
validate?: boolean;
|
|
32
34
|
}
|
|
35
|
+
export type GraphQLWsContextResolver = (ctx: {
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}, message: SubscribeMessage, args: ExecutionArgs) => Promise<GraphQLExecutionContextValue> | GraphQLExecutionContextValue;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAOhE,6CAA+D;AAAvD,qGAAA,KAAK,OAAA;AAAE,kGAAA,EAAE,OAAA;AAAE,mGAAA,GAAG,OAAA"}
|
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.12.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": "20 || 22 || 24"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
|
|
@@ -40,29 +40,36 @@
|
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@loopback/boot": "^7.0.0",
|
|
43
|
-
"@loopback/core": "^6.0.0"
|
|
43
|
+
"@loopback/core": "^6.0.0",
|
|
44
|
+
"@loopback/rest": "^14.0.0"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
47
|
+
"@apollo/server": "^4.12.2",
|
|
46
48
|
"@graphql-tools/utils": "^10.8.6",
|
|
47
|
-
"@loopback/http-server": "^
|
|
48
|
-
"
|
|
49
|
-
"
|
|
49
|
+
"@loopback/http-server": "^7.0.0",
|
|
50
|
+
"body-parser": "^2.2.0",
|
|
51
|
+
"cors": "^2.8.5",
|
|
52
|
+
"debug": "^4.4.1",
|
|
50
53
|
"express": "^4.21.2",
|
|
51
|
-
"graphql": "^
|
|
54
|
+
"graphql": "^16.11.0",
|
|
52
55
|
"graphql-subscriptions": "^2.0.0",
|
|
53
|
-
"
|
|
56
|
+
"graphql-ws": "^5.16.2",
|
|
57
|
+
"type-graphql": "^2.0.0-beta.2",
|
|
58
|
+
"ws": "^8.18.2"
|
|
54
59
|
},
|
|
55
60
|
"devDependencies": {
|
|
56
|
-
"@loopback/boot": "^
|
|
57
|
-
"@loopback/build": "^
|
|
58
|
-
"@loopback/core": "^
|
|
59
|
-
"@loopback/eslint-config": "^
|
|
60
|
-
"@loopback/repository": "^
|
|
61
|
-
"@loopback/rest": "^
|
|
62
|
-
"@loopback/testlab": "^
|
|
61
|
+
"@loopback/boot": "^8.0.0",
|
|
62
|
+
"@loopback/build": "^12.0.0",
|
|
63
|
+
"@loopback/core": "^7.0.0",
|
|
64
|
+
"@loopback/eslint-config": "^16.0.0",
|
|
65
|
+
"@loopback/repository": "^8.0.0",
|
|
66
|
+
"@loopback/rest": "^15.0.0",
|
|
67
|
+
"@loopback/testlab": "^8.0.0",
|
|
68
|
+
"@types/cors": "^2.8.19",
|
|
63
69
|
"@types/debug": "^4.1.12",
|
|
64
70
|
"@types/node": "^16.18.126",
|
|
71
|
+
"@types/ws": "^8.18.1",
|
|
65
72
|
"class-transformer": "^0.5.1"
|
|
66
73
|
},
|
|
67
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "be9e7324fca771c50502bdbd312821be8f94347e"
|
|
68
75
|
}
|
|
@@ -3,6 +3,12 @@
|
|
|
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 {
|
|
7
|
+
ArtifactOptions,
|
|
8
|
+
BaseArtifactBooter,
|
|
9
|
+
BootBindings,
|
|
10
|
+
booter,
|
|
11
|
+
} from '@loopback/boot';
|
|
6
12
|
import {
|
|
7
13
|
Application,
|
|
8
14
|
config,
|
|
@@ -10,15 +16,9 @@ import {
|
|
|
10
16
|
CoreBindings,
|
|
11
17
|
inject,
|
|
12
18
|
} from '@loopback/core';
|
|
13
|
-
import
|
|
14
|
-
ArtifactOptions,
|
|
15
|
-
BaseArtifactBooter,
|
|
16
|
-
BootBindings,
|
|
17
|
-
booter,
|
|
18
|
-
} from '@loopback/boot';
|
|
19
|
+
import debugFactory from 'debug';
|
|
19
20
|
import {getMetadataStorage} from 'type-graphql';
|
|
20
21
|
import {ResolverClassMetadata} from 'type-graphql/dist/metadata/definitions';
|
|
21
|
-
import debugFactory from 'debug';
|
|
22
22
|
import {registerResolver} from '../graphql.server';
|
|
23
23
|
|
|
24
24
|
const debug = debugFactory('loopback:graphql:resolver-booter');
|
|
@@ -63,7 +63,7 @@ export class GraphQLResolverBooter extends BaseArtifactBooter {
|
|
|
63
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
64
|
(getMetadataStorage() as any).resolverClasses;
|
|
65
65
|
this.resolvers = this.classes.filter(cls => {
|
|
66
|
-
return resolverClasses.some(r =>
|
|
66
|
+
return resolverClasses.some(r => /*!r.isAbstract && */ r.target === cls);
|
|
67
67
|
});
|
|
68
68
|
for (const resolver of this.resolvers) {
|
|
69
69
|
debug('Bind interceptor: %s', resolver.name);
|
package/src/graphql.container.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 {ExpressContextFunctionArgument} from '@apollo/server/dist/esm/express4';
|
|
6
7
|
import {
|
|
7
8
|
Binding,
|
|
8
9
|
BindingScope,
|
|
@@ -12,9 +13,8 @@ import {
|
|
|
12
13
|
filterByKey,
|
|
13
14
|
filterByServiceInterface,
|
|
14
15
|
} from '@loopback/core';
|
|
15
|
-
import {ExpressContext} from 'apollo-server-express';
|
|
16
|
-
import {ContainerType, ResolverData} from 'type-graphql';
|
|
17
16
|
import debugFactory from 'debug';
|
|
17
|
+
import {ContainerType, ResolverData} from 'type-graphql';
|
|
18
18
|
import {GraphQLBindings, GraphQLTags} from './keys';
|
|
19
19
|
|
|
20
20
|
const debug = debugFactory('loopback:graphql:container');
|
|
@@ -27,7 +27,7 @@ export class GraphQLResolutionContext extends Context {
|
|
|
27
27
|
constructor(
|
|
28
28
|
parent: Context,
|
|
29
29
|
readonly resolverClass: Constructor<unknown>,
|
|
30
|
-
readonly resolverData: ResolverData<
|
|
30
|
+
readonly resolverData: ResolverData<object>,
|
|
31
31
|
) {
|
|
32
32
|
super(parent);
|
|
33
33
|
this.bind(GraphQLBindings.RESOLVER_DATA).to(resolverData);
|
|
@@ -41,14 +41,11 @@ export class GraphQLResolutionContext extends Context {
|
|
|
41
41
|
*/
|
|
42
42
|
export class LoopBackContainer implements ContainerType {
|
|
43
43
|
constructor(readonly ctx: Context) {}
|
|
44
|
-
get(
|
|
45
|
-
resolverClass: Constructor<unknown>,
|
|
46
|
-
resolverData: ResolverData<unknown>,
|
|
47
|
-
) {
|
|
44
|
+
get(resolverClass: Constructor<unknown>, resolverData: ResolverData<object>) {
|
|
48
45
|
debug('Resolving a resolver %s', resolverClass.name, resolverData);
|
|
49
46
|
|
|
50
47
|
// Check if the resolverData has the LoopBack RequestContext
|
|
51
|
-
const graphQLCtx = resolverData.context as
|
|
48
|
+
const graphQLCtx = resolverData.context as ExpressContextFunctionArgument;
|
|
52
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
50
|
const reqCtx = (graphQLCtx?.req as any)?.[MIDDLEWARE_CONTEXT];
|
|
54
51
|
const parent = reqCtx ?? this.ctx;
|
package/src/graphql.server.ts
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
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 {
|
|
7
|
+
ApolloServer,
|
|
8
|
+
ApolloServerOptionsWithSchema,
|
|
9
|
+
BaseContext,
|
|
10
|
+
} from '@apollo/server';
|
|
11
|
+
import {ExpressMiddlewareOptions} from '@apollo/server/dist/esm/express4';
|
|
12
|
+
import {expressMiddleware} from '@apollo/server/express4';
|
|
6
13
|
import {printSchemaWithDirectives} from '@graphql-tools/utils';
|
|
7
14
|
import {
|
|
8
15
|
Binding,
|
|
@@ -20,27 +27,29 @@ import {
|
|
|
20
27
|
Server,
|
|
21
28
|
} from '@loopback/core';
|
|
22
29
|
import {HttpServer} from '@loopback/http-server';
|
|
30
|
+
import {RestBindings, RestServer} from '@loopback/rest';
|
|
31
|
+
import pkg from 'body-parser';
|
|
32
|
+
import cors from 'cors';
|
|
33
|
+
import express from 'express';
|
|
23
34
|
import fs from 'fs';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
ApolloServer,
|
|
27
|
-
ApolloServerExpressConfig,
|
|
28
|
-
ExpressContext,
|
|
29
|
-
} from 'apollo-server-express';
|
|
35
|
+
import {GraphQLSchema, lexicographicSortSchema} from 'graphql';
|
|
30
36
|
import {PubSub, PubSubEngine} from 'graphql-subscriptions';
|
|
31
|
-
import {
|
|
32
|
-
import
|
|
37
|
+
import {useServer} from 'graphql-ws/lib/use/ws';
|
|
38
|
+
import * as http from 'http';
|
|
39
|
+
import * as https from 'https';
|
|
33
40
|
import {
|
|
34
41
|
AuthChecker,
|
|
35
42
|
buildSchema,
|
|
36
|
-
BuildSchemaOptions as TypeGrahpQLBuildSchemaOptions,
|
|
37
43
|
NonEmptyArray,
|
|
38
44
|
ResolverInterface,
|
|
45
|
+
BuildSchemaOptions as TypeGrahpQLBuildSchemaOptions,
|
|
39
46
|
} from 'type-graphql';
|
|
40
47
|
import {Middleware} from 'type-graphql/dist/interfaces/Middleware';
|
|
48
|
+
import {WebSocketServer} from 'ws';
|
|
41
49
|
import {LoopBackContainer} from './graphql.container';
|
|
42
50
|
import {GraphQLBindings, GraphQLTags} from './keys';
|
|
43
51
|
import {GraphQLServerOptions} from './types';
|
|
52
|
+
const {json} = pkg;
|
|
44
53
|
|
|
45
54
|
/**
|
|
46
55
|
* GraphQL Server
|
|
@@ -52,6 +61,9 @@ import {GraphQLServerOptions} from './types';
|
|
|
52
61
|
export class GraphQLServer extends Context implements Server {
|
|
53
62
|
readonly httpServer?: HttpServer;
|
|
54
63
|
readonly expressApp: express.Application;
|
|
64
|
+
private schema?: GraphQLSchema;
|
|
65
|
+
private wsServer?: WebSocketServer;
|
|
66
|
+
private wsHttpServer?: http.Server | https.Server;
|
|
55
67
|
|
|
56
68
|
constructor(
|
|
57
69
|
@config() private options: GraphQLServerOptions = {},
|
|
@@ -87,8 +99,8 @@ export class GraphQLServer extends Context implements Server {
|
|
|
87
99
|
/**
|
|
88
100
|
* Get a list of middleware
|
|
89
101
|
*/
|
|
90
|
-
async getMiddlewareList(): Promise<Middleware<
|
|
91
|
-
const view = this.createView<Middleware<
|
|
102
|
+
async getMiddlewareList(): Promise<Middleware<object>[]> {
|
|
103
|
+
const view = this.createView<Middleware<object>>(
|
|
92
104
|
filterByTag(GraphQLTags.MIDDLEWARE),
|
|
93
105
|
);
|
|
94
106
|
return view.values();
|
|
@@ -98,7 +110,9 @@ export class GraphQLServer extends Context implements Server {
|
|
|
98
110
|
* Register a GraphQL middleware
|
|
99
111
|
* @param middleware - GraphQL middleware
|
|
100
112
|
*/
|
|
101
|
-
middleware<T =
|
|
113
|
+
middleware<T extends object = object>(
|
|
114
|
+
middleware: Middleware<T>,
|
|
115
|
+
): Binding<Middleware<T>> {
|
|
102
116
|
return this.bind<Middleware<T>>(BindingKey.generate(`graphql.middleware`))
|
|
103
117
|
.to(middleware)
|
|
104
118
|
.tag(GraphQLTags.MIDDLEWARE);
|
|
@@ -133,8 +147,7 @@ export class GraphQLServer extends Context implements Server {
|
|
|
133
147
|
|
|
134
148
|
// build TypeGraphQL executable schema
|
|
135
149
|
const buildSchemaOptions: TypeGrahpQLBuildSchemaOptions = {
|
|
136
|
-
|
|
137
|
-
validate: false,
|
|
150
|
+
validate: !!this.options.validate,
|
|
138
151
|
resolvers: resolverClasses,
|
|
139
152
|
// automatically create `schema.gql` file with schema definition in current folder
|
|
140
153
|
// emitSchemaFile: path.resolve(__dirname, 'schema.gql'),
|
|
@@ -148,28 +161,61 @@ export class GraphQLServer extends Context implements Server {
|
|
|
148
161
|
|
|
149
162
|
async start() {
|
|
150
163
|
const schema = await this._setupSchema();
|
|
151
|
-
|
|
164
|
+
this.schema = schema;
|
|
152
165
|
// Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
|
|
153
|
-
const graphqlContextResolver:
|
|
166
|
+
const graphqlContextResolver: ExpressMiddlewareOptions<BaseContext>['context'] =
|
|
154
167
|
(await this.get(GraphQLBindings.GRAPHQL_CONTEXT_RESOLVER, {
|
|
155
168
|
optional: true,
|
|
156
|
-
})) ?? (context => context);
|
|
169
|
+
})) ?? (async context => context);
|
|
170
|
+
// Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
|
|
171
|
+
const graphqlWsContextResolver =
|
|
172
|
+
(await this.get(GraphQLBindings.GRAPHQL_WS_CONTEXT_RESOLVER, {
|
|
173
|
+
optional: true,
|
|
174
|
+
})) ??
|
|
175
|
+
(async (context: object) => {
|
|
176
|
+
return context;
|
|
177
|
+
});
|
|
157
178
|
|
|
158
179
|
// Create ApolloServerExpress GraphQL server
|
|
159
|
-
const serverConfig
|
|
160
|
-
context: graphqlContextResolver,
|
|
180
|
+
const serverConfig = {
|
|
161
181
|
...this.options.apollo,
|
|
162
182
|
schema,
|
|
163
|
-
|
|
183
|
+
status400ForVariableCoercionErrors: true,
|
|
184
|
+
// plugins: [ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer })],
|
|
185
|
+
} as ApolloServerOptionsWithSchema<BaseContext>;
|
|
164
186
|
const graphQLServer = new ApolloServer(serverConfig);
|
|
165
187
|
await graphQLServer.start();
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
188
|
+
this.expressApp.use(
|
|
189
|
+
this.options.graphQLPath ?? '/',
|
|
190
|
+
cors<cors.CorsRequest>(),
|
|
191
|
+
json(),
|
|
192
|
+
expressMiddleware(graphQLServer, {
|
|
193
|
+
context: graphqlContextResolver,
|
|
194
|
+
...this.options.middlewareOptions,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
171
197
|
// Start the http server if created
|
|
172
198
|
await this.httpServer?.start();
|
|
199
|
+
|
|
200
|
+
let server;
|
|
201
|
+
if (this.options.asMiddlewareOnly) {
|
|
202
|
+
const rest: RestServer = await this.get(RestBindings.SERVER);
|
|
203
|
+
server = rest.httpServer?.server;
|
|
204
|
+
} else {
|
|
205
|
+
server = this.httpServer?.server;
|
|
206
|
+
}
|
|
207
|
+
const wsServer = new WebSocketServer({
|
|
208
|
+
server: server,
|
|
209
|
+
path: this.options.path,
|
|
210
|
+
});
|
|
211
|
+
this.wsServer = wsServer;
|
|
212
|
+
useServer(
|
|
213
|
+
{
|
|
214
|
+
schema,
|
|
215
|
+
context: graphqlWsContextResolver,
|
|
216
|
+
},
|
|
217
|
+
wsServer,
|
|
218
|
+
);
|
|
173
219
|
}
|
|
174
220
|
|
|
175
221
|
async exportGraphQLSchema(outFile = '', log = console.log) {
|
|
@@ -187,6 +233,10 @@ export class GraphQLServer extends Context implements Server {
|
|
|
187
233
|
async stop() {
|
|
188
234
|
// Stop the http server if created
|
|
189
235
|
await this.httpServer?.stop();
|
|
236
|
+
// Stop ws http server
|
|
237
|
+
await this.closeWsHttpServer();
|
|
238
|
+
// Stop the websocket server if created
|
|
239
|
+
await this.closeWsServer();
|
|
190
240
|
}
|
|
191
241
|
|
|
192
242
|
/**
|
|
@@ -195,6 +245,40 @@ export class GraphQLServer extends Context implements Server {
|
|
|
195
245
|
get listening() {
|
|
196
246
|
return !!this.httpServer?.listening;
|
|
197
247
|
}
|
|
248
|
+
|
|
249
|
+
getSchema(): GraphQLSchema {
|
|
250
|
+
return this.schema!;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private closeWsHttpServer(): Promise<void> {
|
|
254
|
+
if (!this.wsHttpServer) {
|
|
255
|
+
return Promise.resolve();
|
|
256
|
+
}
|
|
257
|
+
return new Promise((resolve, reject) => {
|
|
258
|
+
this.wsHttpServer?.close(err => {
|
|
259
|
+
if (err) {
|
|
260
|
+
reject(err);
|
|
261
|
+
} else {
|
|
262
|
+
resolve();
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private closeWsServer(): Promise<void> {
|
|
269
|
+
if (!this.wsServer) {
|
|
270
|
+
return Promise.resolve();
|
|
271
|
+
}
|
|
272
|
+
return new Promise((resolve, reject) => {
|
|
273
|
+
this.wsServer?.close(err => {
|
|
274
|
+
if (err) {
|
|
275
|
+
reject(err);
|
|
276
|
+
} else {
|
|
277
|
+
resolve();
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
198
282
|
}
|
|
199
283
|
|
|
200
284
|
/**
|
package/src/index.ts
CHANGED
package/src/keys.ts
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
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 {ExpressMiddlewareOptions} from '@apollo/server/dist/esm/express4';
|
|
6
7
|
import {BindingKey, Constructor, CoreBindings} from '@loopback/core';
|
|
7
|
-
import {
|
|
8
|
+
import {PubSubEngine} from 'graphql-subscriptions';
|
|
9
|
+
import {AuthChecker, ResolverData} from 'type-graphql';
|
|
8
10
|
import {GraphQLComponent} from './graphql.component';
|
|
9
11
|
import {GraphQLServer} from './graphql.server';
|
|
10
|
-
import {
|
|
12
|
+
import {GraphQLServerOptions, GraphQLWsContextResolver} from './types';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Namespace for GraphQL related bindings
|
|
@@ -37,9 +39,12 @@ export namespace GraphQLBindings {
|
|
|
37
39
|
* Binding key for the GraphQL context resolver
|
|
38
40
|
*/
|
|
39
41
|
export const GRAPHQL_CONTEXT_RESOLVER = BindingKey.create<
|
|
40
|
-
|
|
42
|
+
ExpressMiddlewareOptions<{[key: string]: unknown}>['context']
|
|
41
43
|
>('graphql.contextResolver');
|
|
42
44
|
|
|
45
|
+
export const GRAPHQL_WS_CONTEXT_RESOLVER =
|
|
46
|
+
BindingKey.create<GraphQLWsContextResolver>('graphql.wsContextResolver');
|
|
47
|
+
|
|
43
48
|
/**
|
|
44
49
|
* Binding key for the GraphQL auth checker
|
|
45
50
|
*/
|
|
@@ -57,7 +62,7 @@ export namespace GraphQLBindings {
|
|
|
57
62
|
/**
|
|
58
63
|
* Binding key for the GraphQL resolver data - which is bound per request
|
|
59
64
|
*/
|
|
60
|
-
export const RESOLVER_DATA = BindingKey.create<ResolverData<
|
|
65
|
+
export const RESOLVER_DATA = BindingKey.create<ResolverData<object>>(
|
|
61
66
|
'graphql.resolverData',
|
|
62
67
|
);
|
|
63
68
|
|
package/src/types.ts
CHANGED
|
@@ -3,14 +3,11 @@
|
|
|
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 {ApolloServerOptionsWithStaticSchema, BaseContext} from '@apollo/server';
|
|
6
7
|
import {HttpOptions} from '@loopback/http-server';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
GetMiddlewareOptions,
|
|
10
|
-
} from 'apollo-server-express';
|
|
8
|
+
import {ExecutionArgs} from 'graphql';
|
|
9
|
+
import {GraphQLExecutionContextValue, SubscribeMessage} from 'graphql-ws';
|
|
11
10
|
|
|
12
|
-
export {ContextFunction} from 'apollo-server-core';
|
|
13
|
-
export {ApolloServerExpressConfig, ExpressContext} from 'apollo-server-express';
|
|
14
11
|
export {Float, ID, Int, ResolverInterface} from 'type-graphql';
|
|
15
12
|
export {Middleware as GraphQLMiddleware} from 'type-graphql/dist/interfaces/Middleware';
|
|
16
13
|
|
|
@@ -24,16 +21,18 @@ export interface GraphQLComponentOptions {
|
|
|
24
21
|
/**
|
|
25
22
|
* Options for GraphQL server
|
|
26
23
|
*/
|
|
27
|
-
export interface GraphQLServerOptions
|
|
24
|
+
export interface GraphQLServerOptions<
|
|
25
|
+
TContext extends BaseContext = BaseContext,
|
|
26
|
+
> extends HttpOptions {
|
|
28
27
|
/**
|
|
29
28
|
* ApolloServerExpress related configuration
|
|
30
29
|
*/
|
|
31
|
-
apollo?:
|
|
30
|
+
apollo?: Partial<ApolloServerOptionsWithStaticSchema<TContext>>;
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Middleware options for GraphQL
|
|
35
34
|
*/
|
|
36
|
-
middlewareOptions?:
|
|
35
|
+
middlewareOptions?: Record<string, unknown>;
|
|
37
36
|
|
|
38
37
|
/**
|
|
39
38
|
* Express settings
|
|
@@ -43,4 +42,14 @@ export interface GraphQLServerOptions extends HttpOptions {
|
|
|
43
42
|
* Use as a middleware for RestServer instead of a standalone server
|
|
44
43
|
*/
|
|
45
44
|
asMiddlewareOnly?: boolean;
|
|
45
|
+
|
|
46
|
+
graphQLPath?: string;
|
|
47
|
+
|
|
48
|
+
validate?: boolean;
|
|
46
49
|
}
|
|
50
|
+
|
|
51
|
+
export type GraphQLWsContextResolver = (
|
|
52
|
+
ctx: {[key: string]: unknown},
|
|
53
|
+
message: SubscribeMessage,
|
|
54
|
+
args: ExecutionArgs,
|
|
55
|
+
) => Promise<GraphQLExecutionContextValue> | GraphQLExecutionContextValue;
|