@orion-js/graphql 3.11.15 → 4.0.0-alpha.2
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/index.cjs +107839 -0
- package/dist/index.d.ts +570 -0
- package/dist/index.js +107812 -0
- package/package.json +30 -21
- package/LICENSE +0 -21
- package/jest.config.js +0 -8
- package/lib/buildSchema/getArgs/getField.d.ts +0 -1
- package/lib/buildSchema/getArgs/getField.js +0 -49
- package/lib/buildSchema/getArgs/index.d.ts +0 -1
- package/lib/buildSchema/getArgs/index.js +0 -24
- package/lib/buildSchema/getMutation.d.ts +0 -3
- package/lib/buildSchema/getMutation.js +0 -18
- package/lib/buildSchema/getQuery.d.ts +0 -3
- package/lib/buildSchema/getQuery.js +0 -18
- package/lib/buildSchema/getResolvers/index.d.ts +0 -3
- package/lib/buildSchema/getResolvers/index.js +0 -43
- package/lib/buildSchema/getResolvers/index.test.d.ts +0 -1
- package/lib/buildSchema/getResolvers/index.test.js +0 -65
- package/lib/buildSchema/getResolvers/resolversStore.d.ts +0 -3
- package/lib/buildSchema/getResolvers/resolversStore.js +0 -5
- package/lib/buildSchema/getSubscription.d.ts +0 -3
- package/lib/buildSchema/getSubscription.js +0 -17
- package/lib/buildSchema/getSubscriptions/index.d.ts +0 -2
- package/lib/buildSchema/getSubscriptions/index.js +0 -26
- package/lib/buildSchema/getSubscriptions/index.test.d.ts +0 -1
- package/lib/buildSchema/getSubscriptions/index.test.js +0 -52
- package/lib/buildSchema/getType/BigIntScalar.d.ts +0 -3
- package/lib/buildSchema/getType/BigIntScalar.js +0 -35
- package/lib/buildSchema/getType/DateScalar.d.ts +0 -3
- package/lib/buildSchema/getType/DateScalar.js +0 -10
- package/lib/buildSchema/getType/JSONScalar.d.ts +0 -3
- package/lib/buildSchema/getType/JSONScalar.js +0 -42
- package/lib/buildSchema/getType/enum.test.d.ts +0 -1
- package/lib/buildSchema/getType/enum.test.js +0 -80
- package/lib/buildSchema/getType/getScalar.d.ts +0 -1
- package/lib/buildSchema/getType/getScalar.js +0 -58
- package/lib/buildSchema/getType/getTypeAsResolver.d.ts +0 -10
- package/lib/buildSchema/getType/getTypeAsResolver.js +0 -26
- package/lib/buildSchema/getType/index.d.ts +0 -2
- package/lib/buildSchema/getType/index.js +0 -86
- package/lib/buildSchema/index.d.ts +0 -3
- package/lib/buildSchema/index.js +0 -17
- package/lib/cleanResolvers.d.ts +0 -1
- package/lib/cleanResolvers.js +0 -8
- package/lib/errorHandler.d.ts +0 -1
- package/lib/errorHandler.js +0 -42
- package/lib/getApolloOptions/formatError.d.ts +0 -1
- package/lib/getApolloOptions/formatError.js +0 -14
- package/lib/getApolloOptions/index.d.ts +0 -3
- package/lib/getApolloOptions/index.js +0 -26
- package/lib/index.d.ts +0 -12
- package/lib/index.js +0 -51
- package/lib/pubsub.d.ts +0 -3
- package/lib/pubsub.js +0 -12
- package/lib/resolversSchemas/ResolverParamsInfo.d.ts +0 -9
- package/lib/resolversSchemas/ResolverParamsInfo.js +0 -47
- package/lib/resolversSchemas/getBasicResultQuery.d.ts +0 -1
- package/lib/resolversSchemas/getBasicResultQuery.js +0 -24
- package/lib/resolversSchemas/getDynamicFields.d.ts +0 -2
- package/lib/resolversSchemas/getDynamicFields.js +0 -19
- package/lib/resolversSchemas/getField.d.ts +0 -1
- package/lib/resolversSchemas/getField.js +0 -50
- package/lib/resolversSchemas/getField.test.d.ts +0 -1
- package/lib/resolversSchemas/getField.test.js +0 -56
- package/lib/resolversSchemas/getModelLoadedResolvers.d.ts +0 -3
- package/lib/resolversSchemas/getModelLoadedResolvers.js +0 -21
- package/lib/resolversSchemas/getStaticFields.d.ts +0 -3
- package/lib/resolversSchemas/getStaticFields.js +0 -20
- package/lib/resolversSchemas/index.d.ts +0 -7
- package/lib/resolversSchemas/index.js +0 -9
- package/lib/resolversSchemas/params.d.ts +0 -5
- package/lib/resolversSchemas/params.js +0 -31
- package/lib/resolversSchemas/params.test.d.ts +0 -1
- package/lib/resolversSchemas/params.test.js +0 -131
- package/lib/resolversSchemas/serializeSchema.d.ts +0 -2
- package/lib/resolversSchemas/serializeSchema.js +0 -22
- package/lib/resolversSchemas/serializeSchema.test.d.ts +0 -1
- package/lib/resolversSchemas/serializeSchema.test.js +0 -56
- package/lib/service/global.d.ts +0 -10
- package/lib/service/global.js +0 -60
- package/lib/service/index.d.ts +0 -4
- package/lib/service/index.js +0 -20
- package/lib/service/index.test.d.ts +0 -1
- package/lib/service/index.test.js +0 -63
- package/lib/service/middlewares.test.d.ts +0 -1
- package/lib/service/middlewares.test.js +0 -125
- package/lib/service/model.d.ts +0 -14
- package/lib/service/model.js +0 -48
- package/lib/service/model.test.d.ts +0 -1
- package/lib/service/model.test.js +0 -126
- package/lib/service/otherParams.d.ts +0 -7
- package/lib/service/otherParams.js +0 -28
- package/lib/service/subscription.d.ts +0 -6
- package/lib/service/subscription.js +0 -43
- package/lib/service/subscription.test.d.ts +0 -1
- package/lib/service/subscription.test.js +0 -55
- package/lib/startGraphQL.d.ts +0 -2
- package/lib/startGraphQL.js +0 -43
- package/lib/startGraphQL.test.d.ts +0 -1
- package/lib/startGraphQL.test.js +0 -414
- package/lib/startGraphiQL.d.ts +0 -3
- package/lib/startGraphiQL.js +0 -207
- package/lib/startWebsocket.d.ts +0 -11
- package/lib/startWebsocket.js +0 -48
- package/lib/startWebsocket.test.d.ts +0 -1
- package/lib/startWebsocket.test.js +0 -303
- package/lib/subscription/getChannelName.d.ts +0 -1
- package/lib/subscription/getChannelName.js +0 -9
- package/lib/subscription/getChannelName.test.d.ts +0 -1
- package/lib/subscription/getChannelName.test.js +0 -26
- package/lib/subscription/index.d.ts +0 -3
- package/lib/subscription/index.js +0 -34
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -19
- package/lib/types/startGraphQL.d.ts +0 -41
- package/lib/types/startGraphQL.js +0 -2
- package/lib/types/subscription.d.ts +0 -15
- package/lib/types/subscription.js +0 -2
- package/lib/websockerViewer.d.ts +0 -2
- package/lib/websockerViewer.js +0 -20
- package/tsconfig.json +0 -20
- package/yarn-error.log +0 -3949
package/lib/startGraphQL.test.js
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const _1 = require(".");
|
|
16
|
-
const resolvers_1 = require("@orion-js/resolvers");
|
|
17
|
-
const http_1 = require("@orion-js/http");
|
|
18
|
-
const supertest_1 = __importDefault(require("supertest"));
|
|
19
|
-
const typed_model_1 = require("@orion-js/typed-model");
|
|
20
|
-
const cleanResolvers_1 = require("./cleanResolvers");
|
|
21
|
-
const models_1 = require("@orion-js/models");
|
|
22
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
23
|
-
describe('Test GraphQL Server', () => {
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
(0, cleanResolvers_1.cleanResolvers)();
|
|
26
|
-
});
|
|
27
|
-
it('should startGraphQL with only resolvers', async () => {
|
|
28
|
-
const resolvers = {
|
|
29
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
30
|
-
params: {
|
|
31
|
-
name: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
returns: 'string',
|
|
36
|
-
async resolve({ name }) {
|
|
37
|
-
return `Hello ${name}`;
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
};
|
|
41
|
-
const app = (0, http_1.express)();
|
|
42
|
-
await (0, _1.startGraphQL)({
|
|
43
|
-
resolvers,
|
|
44
|
-
app,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it('should startGraphQL and make a request', async () => {
|
|
48
|
-
const resolvers = {
|
|
49
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
50
|
-
params: {
|
|
51
|
-
name: {
|
|
52
|
-
type: 'string',
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
returns: 'string',
|
|
56
|
-
async resolve({ name }) {
|
|
57
|
-
return `Hello ${name}`;
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
const app = (0, http_1.express)();
|
|
62
|
-
await (0, _1.startGraphQL)({
|
|
63
|
-
resolvers,
|
|
64
|
-
app,
|
|
65
|
-
});
|
|
66
|
-
const response = await (0, supertest_1.default)(app)
|
|
67
|
-
.post('/graphql')
|
|
68
|
-
.send({
|
|
69
|
-
operationName: 'testOperation',
|
|
70
|
-
variables: {
|
|
71
|
-
name: 'Nico',
|
|
72
|
-
},
|
|
73
|
-
query: `query testOperation($name: String) {
|
|
74
|
-
helloWorld(name: $name)
|
|
75
|
-
}`,
|
|
76
|
-
});
|
|
77
|
-
expect(response.body.data).toEqual({ helloWorld: 'Hello Nico' });
|
|
78
|
-
});
|
|
79
|
-
it('should return errors correctly', async () => {
|
|
80
|
-
const resolvers = {
|
|
81
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
82
|
-
params: {
|
|
83
|
-
name: {
|
|
84
|
-
type: 'string',
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
returns: 'string',
|
|
88
|
-
async resolve({ name }) {
|
|
89
|
-
return `Hello ${name}`;
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
};
|
|
93
|
-
const app = (0, http_1.express)();
|
|
94
|
-
await (0, _1.startGraphQL)({
|
|
95
|
-
resolvers,
|
|
96
|
-
app,
|
|
97
|
-
});
|
|
98
|
-
const response = await (0, supertest_1.default)(app)
|
|
99
|
-
.post('/graphql')
|
|
100
|
-
.send({
|
|
101
|
-
operationName: 'testOperation',
|
|
102
|
-
variables: {
|
|
103
|
-
name: 'Nico',
|
|
104
|
-
},
|
|
105
|
-
query: `query testOperation($name: String) {
|
|
106
|
-
helloWorld_doesntExists(name: $name)
|
|
107
|
-
}`,
|
|
108
|
-
});
|
|
109
|
-
expect(response.statusCode).toBe(400);
|
|
110
|
-
expect(response.body.errors[0].message).toEqual('Cannot query field "helloWorld_doesntExists" on type "Query".');
|
|
111
|
-
});
|
|
112
|
-
it('should return validation errors correctly', async () => {
|
|
113
|
-
const resolvers = {
|
|
114
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
115
|
-
params: {
|
|
116
|
-
name: {
|
|
117
|
-
type: 'string',
|
|
118
|
-
validate: () => {
|
|
119
|
-
return 'notUnique';
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
returns: 'string',
|
|
124
|
-
async resolve({ name }) {
|
|
125
|
-
return `Hello ${name}`;
|
|
126
|
-
},
|
|
127
|
-
}),
|
|
128
|
-
};
|
|
129
|
-
const app = (0, http_1.express)();
|
|
130
|
-
await (0, _1.startGraphQL)({
|
|
131
|
-
resolvers,
|
|
132
|
-
app,
|
|
133
|
-
});
|
|
134
|
-
const response = await (0, supertest_1.default)(app)
|
|
135
|
-
.post('/graphql')
|
|
136
|
-
.send({
|
|
137
|
-
operationName: 'testOperation',
|
|
138
|
-
variables: {
|
|
139
|
-
name: 'Nico',
|
|
140
|
-
},
|
|
141
|
-
query: `query testOperation($name: String) {
|
|
142
|
-
helloWorld(name: $name)
|
|
143
|
-
}`,
|
|
144
|
-
});
|
|
145
|
-
expect(response.statusCode).toBe(200);
|
|
146
|
-
expect(response.body).toEqual({
|
|
147
|
-
errors: [
|
|
148
|
-
{
|
|
149
|
-
message: 'Validation Error: {name: notUnique}',
|
|
150
|
-
locations: [
|
|
151
|
-
{
|
|
152
|
-
line: 2,
|
|
153
|
-
column: 11,
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
path: ['helloWorld'],
|
|
157
|
-
extensions: {
|
|
158
|
-
isOrionError: true,
|
|
159
|
-
isValidationError: true,
|
|
160
|
-
hash: 'f3c9a8e163',
|
|
161
|
-
code: 'validationError',
|
|
162
|
-
info: {
|
|
163
|
-
error: 'validationError',
|
|
164
|
-
message: 'Validation Error',
|
|
165
|
-
validationErrors: {
|
|
166
|
-
name: 'notUnique',
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
data: {
|
|
173
|
-
helloWorld: null,
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
it('should return user errors correctly', async () => {
|
|
178
|
-
const resolvers = {
|
|
179
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
180
|
-
params: {
|
|
181
|
-
name: {
|
|
182
|
-
type: 'string',
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
returns: 'string',
|
|
186
|
-
async resolve({ name }) {
|
|
187
|
-
throw new helpers_1.UserError('code', 'message');
|
|
188
|
-
return `Hello ${name}`;
|
|
189
|
-
},
|
|
190
|
-
}),
|
|
191
|
-
};
|
|
192
|
-
const app = (0, http_1.express)();
|
|
193
|
-
await (0, _1.startGraphQL)({
|
|
194
|
-
resolvers,
|
|
195
|
-
app,
|
|
196
|
-
});
|
|
197
|
-
const response = await (0, supertest_1.default)(app)
|
|
198
|
-
.post('/graphql')
|
|
199
|
-
.send({
|
|
200
|
-
operationName: 'testOperation',
|
|
201
|
-
variables: {
|
|
202
|
-
name: 'Nico',
|
|
203
|
-
},
|
|
204
|
-
query: `query testOperation($name: String) {
|
|
205
|
-
helloWorld(name: $name)
|
|
206
|
-
}`,
|
|
207
|
-
});
|
|
208
|
-
expect(response.statusCode).toBe(200);
|
|
209
|
-
expect(response.body).toEqual({
|
|
210
|
-
errors: [
|
|
211
|
-
{
|
|
212
|
-
message: 'message',
|
|
213
|
-
locations: [
|
|
214
|
-
{
|
|
215
|
-
line: 2,
|
|
216
|
-
column: 11,
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
path: ['helloWorld'],
|
|
220
|
-
extensions: {
|
|
221
|
-
isOrionError: true,
|
|
222
|
-
isValidationError: false,
|
|
223
|
-
code: 'code',
|
|
224
|
-
hash: '6f9b9af3cd',
|
|
225
|
-
info: {
|
|
226
|
-
error: 'code',
|
|
227
|
-
message: 'message',
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
],
|
|
232
|
-
data: {
|
|
233
|
-
helloWorld: null,
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
it('should return server errors correctly', async () => {
|
|
238
|
-
const resolvers = {
|
|
239
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
240
|
-
params: {
|
|
241
|
-
name: {
|
|
242
|
-
type: 'string',
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
returns: 'string',
|
|
246
|
-
async resolve({ name }) {
|
|
247
|
-
throw new Error('message');
|
|
248
|
-
return `Hello ${name}`;
|
|
249
|
-
},
|
|
250
|
-
}),
|
|
251
|
-
};
|
|
252
|
-
const app = (0, http_1.express)();
|
|
253
|
-
await (0, _1.startGraphQL)({
|
|
254
|
-
resolvers,
|
|
255
|
-
app,
|
|
256
|
-
});
|
|
257
|
-
const response = await (0, supertest_1.default)(app)
|
|
258
|
-
.post('/graphql')
|
|
259
|
-
.send({
|
|
260
|
-
operationName: 'testOperation',
|
|
261
|
-
variables: {
|
|
262
|
-
name: 'Nico',
|
|
263
|
-
},
|
|
264
|
-
query: `query testOperation($name: String) {
|
|
265
|
-
helloWorld(name: $name)
|
|
266
|
-
}`,
|
|
267
|
-
});
|
|
268
|
-
expect(response.statusCode).toBe(200);
|
|
269
|
-
const hash = '6f9b9af3cd';
|
|
270
|
-
expect(response.body).toEqual({
|
|
271
|
-
errors: [
|
|
272
|
-
{
|
|
273
|
-
message: `message [${hash}]`,
|
|
274
|
-
locations: [
|
|
275
|
-
{
|
|
276
|
-
line: 2,
|
|
277
|
-
column: 11,
|
|
278
|
-
},
|
|
279
|
-
],
|
|
280
|
-
path: ['helloWorld'],
|
|
281
|
-
extensions: {
|
|
282
|
-
isOrionError: false,
|
|
283
|
-
isValidationError: false,
|
|
284
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
285
|
-
hash: hash,
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
data: {
|
|
290
|
-
helloWorld: null,
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
it('Should make requests to schemas with typed models', async () => {
|
|
295
|
-
let Params = class Params {
|
|
296
|
-
};
|
|
297
|
-
__decorate([
|
|
298
|
-
(0, typed_model_1.Prop)(),
|
|
299
|
-
__metadata("design:type", String)
|
|
300
|
-
], Params.prototype, "userId", void 0);
|
|
301
|
-
Params = __decorate([
|
|
302
|
-
(0, typed_model_1.TypedSchema)()
|
|
303
|
-
], Params);
|
|
304
|
-
let User = class User {
|
|
305
|
-
};
|
|
306
|
-
__decorate([
|
|
307
|
-
(0, typed_model_1.Prop)(),
|
|
308
|
-
__metadata("design:type", String)
|
|
309
|
-
], User.prototype, "name", void 0);
|
|
310
|
-
__decorate([
|
|
311
|
-
(0, typed_model_1.Prop)(),
|
|
312
|
-
__metadata("design:type", Number)
|
|
313
|
-
], User.prototype, "age", void 0);
|
|
314
|
-
User = __decorate([
|
|
315
|
-
(0, typed_model_1.TypedSchema)()
|
|
316
|
-
], User);
|
|
317
|
-
const resolve = async ({ userId }) => {
|
|
318
|
-
if (userId !== '1')
|
|
319
|
-
return null;
|
|
320
|
-
return {
|
|
321
|
-
name: 'Nico',
|
|
322
|
-
age: 20,
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
const user = (0, resolvers_1.resolver)({
|
|
326
|
-
params: Params,
|
|
327
|
-
returns: User,
|
|
328
|
-
resolve,
|
|
329
|
-
});
|
|
330
|
-
const model = (0, models_1.createModel)({
|
|
331
|
-
name: 'Model',
|
|
332
|
-
schema: {
|
|
333
|
-
user: { type: User },
|
|
334
|
-
},
|
|
335
|
-
});
|
|
336
|
-
const modelMutation = (0, resolvers_1.resolver)({
|
|
337
|
-
params: Params,
|
|
338
|
-
returns: [model],
|
|
339
|
-
mutation: true,
|
|
340
|
-
resolve,
|
|
341
|
-
});
|
|
342
|
-
const resolvers = { user, modelMutation };
|
|
343
|
-
const app = (0, http_1.express)();
|
|
344
|
-
await (0, _1.startGraphQL)({
|
|
345
|
-
resolvers,
|
|
346
|
-
app,
|
|
347
|
-
});
|
|
348
|
-
const response = await (0, supertest_1.default)(app)
|
|
349
|
-
.post('/graphql')
|
|
350
|
-
.send({
|
|
351
|
-
variables: {
|
|
352
|
-
userId: '1',
|
|
353
|
-
},
|
|
354
|
-
query: `query ($userId: String) {
|
|
355
|
-
user(userId: $userId) {
|
|
356
|
-
name
|
|
357
|
-
age
|
|
358
|
-
}
|
|
359
|
-
}`,
|
|
360
|
-
});
|
|
361
|
-
expect(response.statusCode).toBe(200);
|
|
362
|
-
expect(response.body.data).toEqual({
|
|
363
|
-
user: {
|
|
364
|
-
name: 'Nico',
|
|
365
|
-
age: 20,
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
it('Should pass graphql request info in fourth param', async () => {
|
|
370
|
-
let User = class User {
|
|
371
|
-
};
|
|
372
|
-
__decorate([
|
|
373
|
-
(0, typed_model_1.Prop)(),
|
|
374
|
-
__metadata("design:type", String)
|
|
375
|
-
], User.prototype, "name", void 0);
|
|
376
|
-
__decorate([
|
|
377
|
-
(0, typed_model_1.Prop)(),
|
|
378
|
-
__metadata("design:type", Number)
|
|
379
|
-
], User.prototype, "age", void 0);
|
|
380
|
-
User = __decorate([
|
|
381
|
-
(0, typed_model_1.TypedSchema)()
|
|
382
|
-
], User);
|
|
383
|
-
let resolveInfo;
|
|
384
|
-
const user = (0, resolvers_1.resolver)({
|
|
385
|
-
params: {},
|
|
386
|
-
returns: User,
|
|
387
|
-
async resolve(_params, _viewer, info) {
|
|
388
|
-
resolveInfo = info;
|
|
389
|
-
return {
|
|
390
|
-
name: 'Nico',
|
|
391
|
-
age: 20,
|
|
392
|
-
};
|
|
393
|
-
},
|
|
394
|
-
});
|
|
395
|
-
const resolvers = { user };
|
|
396
|
-
const app = (0, http_1.express)();
|
|
397
|
-
await (0, _1.startGraphQL)({
|
|
398
|
-
resolvers,
|
|
399
|
-
app,
|
|
400
|
-
});
|
|
401
|
-
const response = await (0, supertest_1.default)(app)
|
|
402
|
-
.post('/graphql')
|
|
403
|
-
.send({
|
|
404
|
-
query: `query {
|
|
405
|
-
user {
|
|
406
|
-
name
|
|
407
|
-
age
|
|
408
|
-
}
|
|
409
|
-
}`,
|
|
410
|
-
});
|
|
411
|
-
expect(response.statusCode).toBe(200);
|
|
412
|
-
expect(resolveInfo.fieldName).toEqual('user');
|
|
413
|
-
});
|
|
414
|
-
});
|
package/lib/startGraphiQL.d.ts
DELETED
package/lib/startGraphiQL.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const http_1 = require("@orion-js/http");
|
|
4
|
-
// Ensures string values are safe to be used within a <script> tag.
|
|
5
|
-
// TODO: I don't think that's the right escape function
|
|
6
|
-
function safeSerialize(data) {
|
|
7
|
-
return data ? JSON.stringify(data).replace(/\//g, '\\/') : null;
|
|
8
|
-
}
|
|
9
|
-
const getHTML = function (apolloOptions, options, data) {
|
|
10
|
-
// Current latest version of GraphiQL.
|
|
11
|
-
const GRAPHIQL_VERSION = '0.11.11';
|
|
12
|
-
const endpointURL = '/graphql';
|
|
13
|
-
const subscriptionsEndpoint = '/subscriptions';
|
|
14
|
-
const queryString = data.query;
|
|
15
|
-
const variablesString = data.variables ? JSON.stringify(data.variables, null, 2) : null;
|
|
16
|
-
const operationName = data.operationName;
|
|
17
|
-
const useSubs = !!options.subscriptions;
|
|
18
|
-
return `
|
|
19
|
-
<!DOCTYPE html>
|
|
20
|
-
<html>
|
|
21
|
-
<head>
|
|
22
|
-
<meta charset="utf-8" />
|
|
23
|
-
<title>GraphiQL</title>
|
|
24
|
-
<meta name="robots" content="noindex" />
|
|
25
|
-
<style>
|
|
26
|
-
html, body {
|
|
27
|
-
height: 100%;
|
|
28
|
-
margin: 0;
|
|
29
|
-
overflow: hidden;
|
|
30
|
-
width: 100%;
|
|
31
|
-
}
|
|
32
|
-
</style>
|
|
33
|
-
<link href="//unpkg.com/graphiql@${GRAPHIQL_VERSION}/graphiql.css" rel="stylesheet" />
|
|
34
|
-
<script src="//unpkg.com/react@15.6.1/dist/react.min.js"></script>
|
|
35
|
-
<script src="//unpkg.com/jssha@2.3.1/src/sha512.js"></script>
|
|
36
|
-
<script src="//unpkg.com/react-dom@15.6.1/dist/react-dom.min.js"></script>
|
|
37
|
-
<script src="//unpkg.com/graphiql@${GRAPHIQL_VERSION}/graphiql.min.js"></script>
|
|
38
|
-
<script src="//cdn.jsdelivr.net/fetch/2.0.1/fetch.min.js"></script>
|
|
39
|
-
${useSubs
|
|
40
|
-
? `<script src="//unpkg.com/subscriptions-transport-ws@0.5.4/browser/client.js"></script>
|
|
41
|
-
<script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"></script>`
|
|
42
|
-
: ''}
|
|
43
|
-
</head>
|
|
44
|
-
<body>
|
|
45
|
-
<script>
|
|
46
|
-
// Collect the URL parameters
|
|
47
|
-
var parameters = {};
|
|
48
|
-
window.location.search.substr(1).split('&').forEach(function (entry) {
|
|
49
|
-
var eq = entry.indexOf('=');
|
|
50
|
-
if (eq >= 0) {
|
|
51
|
-
parameters[decodeURIComponent(entry.slice(0, eq))] =
|
|
52
|
-
decodeURIComponent(entry.slice(eq + 1));
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
// Produce a Location query string from a parameter object.
|
|
56
|
-
function locationQuery(params, location) {
|
|
57
|
-
return (location ? location: '') + '?' + Object.keys(params).map(function (key) {
|
|
58
|
-
return encodeURIComponent(key) + '=' +
|
|
59
|
-
encodeURIComponent(params[key]);
|
|
60
|
-
}).join('&');
|
|
61
|
-
}
|
|
62
|
-
// Derive a fetch URL from the current URL, sans the GraphQL parameters.
|
|
63
|
-
var graphqlParamNames = {
|
|
64
|
-
query: true,
|
|
65
|
-
variables: true,
|
|
66
|
-
operationName: true
|
|
67
|
-
};
|
|
68
|
-
var otherParams = {};
|
|
69
|
-
for (var k in parameters) {
|
|
70
|
-
if (parameters.hasOwnProperty(k) && graphqlParamNames[k] !== true) {
|
|
71
|
-
otherParams[k] = parameters[k];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// We don't use safe-serialize for location, because it's not client input.
|
|
75
|
-
var fetchURL = '${endpointURL}'
|
|
76
|
-
// Defines a GraphQL fetcher using the fetch API.
|
|
77
|
-
function graphQLHttpFetcher(graphQLParams) {
|
|
78
|
-
const body = JSON.stringify(graphQLParams)
|
|
79
|
-
const headers = {
|
|
80
|
-
'Accept': 'application/json',
|
|
81
|
-
'Content-Type': 'application/json',
|
|
82
|
-
}
|
|
83
|
-
const publicKey = localStorage.getItem('GraphiQL:publicKey')
|
|
84
|
-
const secretKey = localStorage.getItem('GraphiQL:secretKey')
|
|
85
|
-
if (publicKey && secretKey) {
|
|
86
|
-
const nonce = new Date().getTime()
|
|
87
|
-
const shaObj = new jsSHA('SHA-512', 'TEXT')
|
|
88
|
-
shaObj.setHMACKey(secretKey, 'TEXT')
|
|
89
|
-
shaObj.update(nonce + body)
|
|
90
|
-
const signature = shaObj.getHMAC('HEX')
|
|
91
|
-
headers['X-ORION-NONCE'] = nonce
|
|
92
|
-
headers['X-ORION-PUBLICKEY'] = publicKey
|
|
93
|
-
headers['X-ORION-SIGNATURE'] = signature
|
|
94
|
-
}
|
|
95
|
-
return fetch(fetchURL, {
|
|
96
|
-
method: 'post',
|
|
97
|
-
headers,
|
|
98
|
-
body,
|
|
99
|
-
credentials: 'same-origin',
|
|
100
|
-
}).then(function (response) {
|
|
101
|
-
return response.text();
|
|
102
|
-
}).then(function (responseBody) {
|
|
103
|
-
try {
|
|
104
|
-
const json = JSON.parse(responseBody);
|
|
105
|
-
if (json.data && json.data.loginWithPassword) {
|
|
106
|
-
const publicKey = json.data.loginWithPassword.publicKey
|
|
107
|
-
const secretKey = json.data.loginWithPassword.secretKey
|
|
108
|
-
if (publicKey && secretKey) {
|
|
109
|
-
localStorage.setItem('GraphiQL:publicKey', publicKey)
|
|
110
|
-
localStorage.setItem('GraphiQL:secretKey', secretKey)
|
|
111
|
-
alert('Session saved in localStorage')
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (json.error && json.error === 'AuthError') {
|
|
115
|
-
localStorage.setItem('GraphiQL:publicKey', '')
|
|
116
|
-
localStorage.setItem('GraphiQL:secretKey', '')
|
|
117
|
-
alert('Logged out after receiving AuthError')
|
|
118
|
-
}
|
|
119
|
-
return json
|
|
120
|
-
} catch (error) {
|
|
121
|
-
return responseBody;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
${useSubs
|
|
126
|
-
? `
|
|
127
|
-
let params = {}
|
|
128
|
-
const publicKey = localStorage.getItem('GraphiQL:publicKey')
|
|
129
|
-
const secretKey = localStorage.getItem('GraphiQL:secretKey')
|
|
130
|
-
if (publicKey && secretKey) {
|
|
131
|
-
const nonce = new Date().getTime() + 500
|
|
132
|
-
const shaObj = new jsSHA('SHA-512', 'TEXT')
|
|
133
|
-
shaObj.setHMACKey(secretKey, 'TEXT')
|
|
134
|
-
shaObj.update(nonce + 'websockethandshake')
|
|
135
|
-
const signature = shaObj.getHMAC('HEX')
|
|
136
|
-
params = {
|
|
137
|
-
nonce,
|
|
138
|
-
publicKey,
|
|
139
|
-
signature
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'
|
|
144
|
-
let subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(protocol + window.location.host + '${subscriptionsEndpoint}', {
|
|
145
|
-
reconnect: true,
|
|
146
|
-
connectionParams: params
|
|
147
|
-
});
|
|
148
|
-
let myCustomFetcher = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLHttpFetcher);
|
|
149
|
-
var fetcher = myCustomFetcher
|
|
150
|
-
`
|
|
151
|
-
: `
|
|
152
|
-
var fetcher = graphQLHttpFetcher
|
|
153
|
-
`}
|
|
154
|
-
|
|
155
|
-
// When the query and variables string is edited, update the URL bar so
|
|
156
|
-
// that it can be easily shared.
|
|
157
|
-
function onEditQuery(newQuery) {
|
|
158
|
-
parameters.query = newQuery;
|
|
159
|
-
updateURL();
|
|
160
|
-
}
|
|
161
|
-
function onEditVariables(newVariables) {
|
|
162
|
-
parameters.variables = newVariables;
|
|
163
|
-
updateURL();
|
|
164
|
-
}
|
|
165
|
-
function onEditOperationName(newOperationName) {
|
|
166
|
-
parameters.operationName = newOperationName;
|
|
167
|
-
updateURL();
|
|
168
|
-
}
|
|
169
|
-
function updateURL() {
|
|
170
|
-
var cleanParams = Object.keys(parameters).filter(function(v) {
|
|
171
|
-
return parameters[v];
|
|
172
|
-
}).reduce(function(old, v) {
|
|
173
|
-
old[v] = parameters[v];
|
|
174
|
-
return old;
|
|
175
|
-
}, {});
|
|
176
|
-
history.replaceState(null, null, locationQuery(cleanParams) + window.location.hash);
|
|
177
|
-
}
|
|
178
|
-
// Render <GraphiQL /> into the body.
|
|
179
|
-
ReactDOM.render(
|
|
180
|
-
React.createElement(GraphiQL, {
|
|
181
|
-
fetcher: fetcher,
|
|
182
|
-
onEditQuery: onEditQuery,
|
|
183
|
-
onEditVariables: onEditVariables,
|
|
184
|
-
onEditOperationName: onEditOperationName,
|
|
185
|
-
query: ${safeSerialize(queryString)},
|
|
186
|
-
response: null,
|
|
187
|
-
variables: ${safeSerialize(variablesString)},
|
|
188
|
-
operationName: ${safeSerialize(operationName)},
|
|
189
|
-
}),
|
|
190
|
-
document.body
|
|
191
|
-
);
|
|
192
|
-
</script>
|
|
193
|
-
</body>
|
|
194
|
-
</html>`;
|
|
195
|
-
};
|
|
196
|
-
function default_1(apolloOptions, options) {
|
|
197
|
-
(0, http_1.registerRoute)((0, http_1.route)({
|
|
198
|
-
path: '/graphiql',
|
|
199
|
-
method: 'get',
|
|
200
|
-
async resolve(req) {
|
|
201
|
-
return {
|
|
202
|
-
body: getHTML(apolloOptions, options, req.query)
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
exports.default = default_1;
|
package/lib/startWebsocket.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StartGraphQLOptions } from './types/startGraphQL';
|
|
2
|
-
import { ApolloServerOptions } from '@apollo/server';
|
|
3
|
-
export default function (apolloOptions: ApolloServerOptions<any>, options: StartGraphQLOptions,
|
|
4
|
-
/**
|
|
5
|
-
* For testing purposes
|
|
6
|
-
*/
|
|
7
|
-
wsServer?: any): {
|
|
8
|
-
serverWillStart(): Promise<{
|
|
9
|
-
drainServer(): Promise<void>;
|
|
10
|
-
}>;
|
|
11
|
-
}[];
|
package/lib/startWebsocket.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const graphql_subscriptions_1 = require("graphql-subscriptions");
|
|
4
|
-
const pubsub_1 = require("./pubsub");
|
|
5
|
-
const ws_1 = require("ws");
|
|
6
|
-
const ws_2 = require("graphql-ws/lib/use/ws");
|
|
7
|
-
const websockerViewer_1 = require("./websockerViewer");
|
|
8
|
-
const http_1 = require("@orion-js/http");
|
|
9
|
-
function default_1(apolloOptions, options,
|
|
10
|
-
/**
|
|
11
|
-
* For testing purposes
|
|
12
|
-
*/
|
|
13
|
-
wsServer) {
|
|
14
|
-
if (!options.subscriptions) {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
const pubsub = options.pubsub || new graphql_subscriptions_1.PubSub();
|
|
18
|
-
(0, pubsub_1.setPubsub)(pubsub);
|
|
19
|
-
// Creating the WebSocket server
|
|
20
|
-
if (!wsServer) {
|
|
21
|
-
wsServer = new ws_1.WebSocketServer({
|
|
22
|
-
server: (0, http_1.getServer)(),
|
|
23
|
-
path: '/subscriptions'
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
// Hand in the schema we just created and have the
|
|
27
|
-
// WebSocketServer start listening.
|
|
28
|
-
const serverCleanup = (0, ws_2.useServer)({
|
|
29
|
-
schema: apolloOptions.schema,
|
|
30
|
-
context: async (ctx, msg, args) => {
|
|
31
|
-
// This will be run every time the client sends a subscription request
|
|
32
|
-
return (0, websockerViewer_1.getWebsockerViewer)(ctx.connectionParams);
|
|
33
|
-
}
|
|
34
|
-
}, wsServer);
|
|
35
|
-
return [
|
|
36
|
-
// Proper shutdown for the WebSocket server.
|
|
37
|
-
{
|
|
38
|
-
async serverWillStart() {
|
|
39
|
-
return {
|
|
40
|
-
async drainServer() {
|
|
41
|
-
await serverCleanup.dispose();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
exports.default = default_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|