@restorecommerce/facade 0.3.5 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/gql/protos/graphql.d.ts +4 -2
- package/dist/gql/protos/graphql.js +93 -167
- package/dist/gql/protos/registry.d.ts +1 -0
- package/dist/gql/protos/registry.js +52 -7
- package/dist/gql/protos/utils.d.ts +1 -1
- package/dist/gql/protos/utils.js +1 -1
- package/dist/modules/access-control/gql/schema.generated.d.ts +7 -41
- package/dist/modules/catalog/gql/schema.generated.d.ts +7 -51
- package/dist/modules/fulfillment/gql/schema.generated.d.ts +9 -70
- package/dist/modules/identity/gql/schema.generated.d.ts +9 -88
- package/dist/modules/indexing/gql/schema.generated.d.ts +8 -10
- package/dist/modules/invoicing/gql/schema.generated.d.ts +7 -29
- package/dist/modules/notification/gql/schema.generated.d.ts +7 -29
- package/dist/modules/ordering/gql/schema.generated.d.ts +7 -39
- package/dist/modules/ostorage/gql/schema.generated.d.ts +10 -31
- package/dist/modules/payment/gql/schema.generated.d.ts +0 -8
- package/dist/modules/resource/gql/schema.generated.d.ts +9 -72
- package/dist/modules/scheduling/gql/schema.generated.d.ts +9 -38
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,40 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [0.3.8](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.7...@restorecommerce/facade@0.3.8) (2022-03-14)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* **facade:** check if buffer field is actually a buffer ([d0930dc](https://github.com/restorecommerce/libs/commit/d0930dcd979d0a2acc101890517e43c7f7d6e2df))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## [0.3.7](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.6...@restorecommerce/facade@0.3.7) (2022-03-14)
|
18
|
+
|
19
|
+
|
20
|
+
### Bug Fixes
|
21
|
+
|
22
|
+
* **facade:** encode any type to buffered json ([9dbb5cb](https://github.com/restorecommerce/libs/commit/9dbb5cb9985f1bdcfd8ac4a9b1ab8bde050be8b2))
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
## [0.3.6](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.5...@restorecommerce/facade@0.3.6) (2022-03-09)
|
29
|
+
|
30
|
+
|
31
|
+
### Bug Fixes
|
32
|
+
|
33
|
+
* **facade:** merge query and mutation resolvers ([c2481b0](https://github.com/restorecommerce/libs/commit/c2481b05c46a5992d2a05017f9c4d279f3055613))
|
34
|
+
* **facade:** to add scope only to root mutation / query instead of all input types and updated suject scope to read from request scope ([9bbc8da](https://github.com/restorecommerce/libs/commit/9bbc8daba19d1ce5ef16b54f9353b9c2df39258e))
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
6
40
|
## [0.3.5](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.4...@restorecommerce/facade@0.3.5) (2022-03-04)
|
7
41
|
|
8
42
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { GraphQLInputField, GraphQLResolveInfo, GraphQLSchema, ThunkObjMap } from "graphql";
|
1
|
+
import { GraphQLInputField, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, ThunkObjMap } from "graphql";
|
2
2
|
import { GraphQLEnumType, GraphQLFieldConfig, GraphQLFieldConfigMap, GraphQLInputObjectType, GraphQLInputType } from "graphql/type/definition";
|
3
3
|
import { ServiceConfig, SubService, SubSpaceServiceConfig } from "./types";
|
4
4
|
import { MethodDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
@@ -6,6 +6,7 @@ import { GrpcClientConfig } from "@restorecommerce/grpc-client";
|
|
6
6
|
export declare const getGQLSchema: <TSource, TContext>(method: MethodDescriptorProto) => GraphQLFieldConfig<TSource, TContext, any>;
|
7
7
|
export declare const getGQLSchemas: <TSource, TContext>(service: ServiceDescriptorProto) => GraphQLFieldConfigMap<TSource, TContext>;
|
8
8
|
export declare const recursiveUploadToBuffer: (data: any, model: GraphQLInputObjectType | GraphQLEnumType | GraphQLInputField | GraphQLInputType) => Promise<any>;
|
9
|
+
export declare const recursiveBufferToValue: (data: any, model: GraphQLOutputType) => any;
|
9
10
|
export declare type ResolverFn<TResult, TParent, TContext, TArgs> = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise<TResult> | TResult;
|
10
11
|
declare type ServiceClient<Context extends Pick<Context, Key>, Key extends keyof Context, T extends Record<string, any>> = {
|
11
12
|
[V in Key]: {
|
@@ -15,7 +16,8 @@ declare type ServiceClient<Context extends Pick<Context, Key>, Key extends keyof
|
|
15
16
|
export declare const getGQLResolverFunctions: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>, SRV = any, R = ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, B extends keyof T = any, NS extends keyof CTX = any>(service: ServiceDescriptorProto, key: NS, serviceKey: B, grpcClientConfig: GrpcClientConfig) => { [key in keyof SRV]: R; };
|
16
17
|
export declare const registerResolverFunction: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>>(namespace: string, name: string, func: ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, mutation?: boolean, subspace?: string | undefined, service?: ServiceDescriptorProto | undefined) => void;
|
17
18
|
export declare const generateResolver: (...namespaces: string[]) => any;
|
18
|
-
|
19
|
+
declare type SchemaBaseOrSub = ThunkObjMap<GraphQLFieldConfig<any, any>> | Map<string, ThunkObjMap<GraphQLFieldConfig<any, any>>>;
|
20
|
+
export declare const registerResolverSchema: (namespace: string, name: string, schema: SchemaBaseOrSub, mutation?: boolean, subspace?: string | undefined) => void;
|
19
21
|
export declare const generateSchema: (setup: {
|
20
22
|
prefix: string;
|
21
23
|
namespace: string;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.generateSubServiceResolvers = exports.generateSubServiceSchemas = exports.getAndGenerateResolvers = exports.getAndGenerateSchema = exports.getWhitelistBlacklistConfig = exports.generateSchema = exports.registerResolverSchema = exports.generateResolver = exports.registerResolverFunction = exports.getGQLResolverFunctions = exports.recursiveUploadToBuffer = exports.getGQLSchemas = exports.getGQLSchema = void 0;
|
3
|
+
exports.generateSubServiceResolvers = exports.generateSubServiceSchemas = exports.getAndGenerateResolvers = exports.getAndGenerateSchema = exports.getWhitelistBlacklistConfig = exports.generateSchema = exports.registerResolverSchema = exports.generateResolver = exports.registerResolverFunction = exports.getGQLResolverFunctions = exports.recursiveBufferToValue = exports.recursiveUploadToBuffer = exports.getGQLSchemas = exports.getGQLSchema = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
5
|
const definition_1 = require("graphql/type/definition");
|
6
6
|
const types_1 = require("./types");
|
@@ -62,10 +62,26 @@ const recursiveUploadToBuffer = async (data, model) => {
|
|
62
62
|
return data;
|
63
63
|
}
|
64
64
|
if (model instanceof definition_1.GraphQLInputObjectType) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
if (model.name === 'IGoogleProtobufAny') {
|
66
|
+
// TODO Use encoded once resource base supports it
|
67
|
+
// const typing = getTyping(data.typeUrl);
|
68
|
+
// if (!typing) {
|
69
|
+
// throw Error(`GoogleProtobufAny could not find input type: ${data.typeUrl}`);
|
70
|
+
// }
|
71
|
+
//
|
72
|
+
// const encoded = typing.processor.encode(typing.processor.fromPartial(data.value)).finish();
|
73
|
+
const encoded = Buffer.from(JSON.stringify(data.value));
|
74
|
+
return {
|
75
|
+
...data,
|
76
|
+
value: encoded
|
77
|
+
};
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
const fields = model.getFields();
|
81
|
+
for (let key of Object.keys(fields)) {
|
82
|
+
if (data && key in data) {
|
83
|
+
data[key] = await (0, exports.recursiveUploadToBuffer)(data[key], fields[key].type);
|
84
|
+
}
|
69
85
|
}
|
70
86
|
}
|
71
87
|
}
|
@@ -96,19 +112,55 @@ const recursiveUploadToBuffer = async (data, model) => {
|
|
96
112
|
return data;
|
97
113
|
};
|
98
114
|
exports.recursiveUploadToBuffer = recursiveUploadToBuffer;
|
115
|
+
const recursiveBufferToValue = (data, model) => {
|
116
|
+
if (model instanceof definition_1.GraphQLEnumType) {
|
117
|
+
return data;
|
118
|
+
}
|
119
|
+
if (model instanceof graphql_1.GraphQLObjectType) {
|
120
|
+
if (model.name === 'GoogleProtobufAny') {
|
121
|
+
// TODO Use encoded once resource base supports it
|
122
|
+
const decoded = JSON.parse(data.value.toString());
|
123
|
+
return {
|
124
|
+
...data,
|
125
|
+
value: decoded
|
126
|
+
};
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
const fields = model.getFields();
|
130
|
+
for (let key of Object.keys(fields)) {
|
131
|
+
if (data && key in data) {
|
132
|
+
data[key] = (0, exports.recursiveBufferToValue)(data[key], fields[key].type);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
if (model instanceof graphql_1.GraphQLNonNull) {
|
138
|
+
return (0, exports.recursiveBufferToValue)(data, model.ofType);
|
139
|
+
}
|
140
|
+
if (model instanceof graphql_1.GraphQLList) {
|
141
|
+
for (let i = 0; i < data.length; i++) {
|
142
|
+
data[i] = (0, exports.recursiveBufferToValue)(data[i], model.ofType);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
return data;
|
146
|
+
};
|
147
|
+
exports.recursiveBufferToValue = recursiveBufferToValue;
|
99
148
|
const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) => {
|
100
149
|
if (!service.method) {
|
101
150
|
return {};
|
102
151
|
}
|
103
152
|
return service.method.reduce((obj, method) => {
|
104
153
|
const typing = (0, registry_1.getTyping)(method.inputType);
|
154
|
+
const outputTyping = (0, registry_1.getTyping)(method.outputType);
|
105
155
|
if (!typing) {
|
106
156
|
throw Error(`Method '${method.name}' could not find input type: ${method.inputType}`);
|
107
157
|
}
|
158
|
+
if (!outputTyping) {
|
159
|
+
throw Error(`Method '${method.name}' could not find output type: ${method.outputType}`);
|
160
|
+
}
|
108
161
|
if (!('fromPartial' in typing.processor)) {
|
109
162
|
throw Error(`Method ${method.name} input type '${method.inputType}' does not contain 'fromPartial' function`);
|
110
163
|
}
|
111
|
-
const defaults = typing.processor.fromPartial({});
|
112
164
|
let subjectField = null;
|
113
165
|
if (typing) {
|
114
166
|
for (let field of typing.meta.field) {
|
@@ -118,16 +170,20 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
|
|
118
170
|
}
|
119
171
|
}
|
120
172
|
}
|
121
|
-
|
173
|
+
let methodName = method.name;
|
174
|
+
if (Mutate.indexOf(method.name) > -1) {
|
175
|
+
methodName = 'Mutate';
|
176
|
+
}
|
177
|
+
if (methodName in obj) {
|
178
|
+
return obj;
|
179
|
+
}
|
180
|
+
obj[methodName] = async (args, context) => {
|
181
|
+
var _a;
|
122
182
|
const client = context[key].client;
|
123
183
|
const service = client[serviceKey];
|
124
184
|
try {
|
125
185
|
const converted = await (0, exports.recursiveUploadToBuffer)(args.input, typing.input);
|
126
|
-
let req =
|
127
|
-
// Fill defaults
|
128
|
-
...defaults,
|
129
|
-
...converted
|
130
|
-
};
|
186
|
+
let req = typing.processor.fromPartial(converted);
|
131
187
|
// convert enum strings to integers
|
132
188
|
req = (0, utils_1.convertEnumToInt)(typing, req);
|
133
189
|
if (subjectField !== null) {
|
@@ -136,8 +192,29 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
|
|
136
192
|
if (authToken && authToken.startsWith('Bearer ')) {
|
137
193
|
req.subject.token = authToken.split(' ')[1];
|
138
194
|
}
|
195
|
+
if (req.scope) {
|
196
|
+
req.subject.scope = req.scope;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
let realMethod = method.name;
|
200
|
+
if (Mutate.indexOf(method.name) > -1) {
|
201
|
+
const mode = (_a = args === null || args === void 0 ? void 0 : args.input) === null || _a === void 0 ? void 0 : _a.mode;
|
202
|
+
if (!mode) {
|
203
|
+
throw new Error('Please specify mode');
|
204
|
+
}
|
205
|
+
if (mode === 'CREATE') {
|
206
|
+
realMethod = 'Create';
|
207
|
+
}
|
208
|
+
else if (mode === 'UPDATE') {
|
209
|
+
realMethod = 'Update';
|
210
|
+
}
|
211
|
+
else if (mode === 'UPSERT') {
|
212
|
+
realMethod = 'Upsert';
|
213
|
+
}
|
139
214
|
}
|
140
|
-
|
215
|
+
console.log(outputTyping);
|
216
|
+
const rawResult = await service[realMethod](req);
|
217
|
+
const result = (0, exports.recursiveBufferToValue)(rawResult, outputTyping.output);
|
141
218
|
const bufferFields = (0, utils_1.getKeys)(grpcClientConfig === null || grpcClientConfig === void 0 ? void 0 : grpcClientConfig.bufferFields);
|
142
219
|
if (result instanceof stream.Readable) {
|
143
220
|
let operationStatus = { code: 0, message: '' };
|
@@ -226,155 +303,6 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
|
|
226
303
|
};
|
227
304
|
exports.getGQLResolverFunctions = getGQLResolverFunctions;
|
228
305
|
const namespaceResolverRegistry = new Map();
|
229
|
-
const MutateResolver = async (req, ctx, schema) => {
|
230
|
-
var _a, _b, _c, _d, _e, _f;
|
231
|
-
let module_name, key, service;
|
232
|
-
if ((_b = (_a = schema === null || schema === void 0 ? void 0 : schema.path) === null || _a === void 0 ? void 0 : _a.prev) === null || _b === void 0 ? void 0 : _b.key) {
|
233
|
-
key = schema.path.prev.key;
|
234
|
-
}
|
235
|
-
if ((_d = (_c = schema === null || schema === void 0 ? void 0 : schema.path) === null || _c === void 0 ? void 0 : _c.prev) === null || _d === void 0 ? void 0 : _d.typename) {
|
236
|
-
let typeName = schema.path.prev.typename;
|
237
|
-
if (typeName.endsWith('Mutation')) {
|
238
|
-
module_name = typeName.split('Mutation')[0];
|
239
|
-
}
|
240
|
-
}
|
241
|
-
if (key && module_name) {
|
242
|
-
module_name = (0, utils_1.convertyCamelToSnakeCase)(module_name);
|
243
|
-
key = (0, utils_1.convertyCamelToSnakeCase)(key);
|
244
|
-
service = (_e = ctx[module_name]) === null || _e === void 0 ? void 0 : _e.client[key];
|
245
|
-
}
|
246
|
-
try {
|
247
|
-
let method = '';
|
248
|
-
let input = req.input;
|
249
|
-
const mode = (_f = req === null || req === void 0 ? void 0 : req.input) === null || _f === void 0 ? void 0 : _f.mode;
|
250
|
-
if (!mode) {
|
251
|
-
throw new Error('Please specify mode');
|
252
|
-
}
|
253
|
-
if (mode === 'CREATE') {
|
254
|
-
method = 'Create';
|
255
|
-
}
|
256
|
-
else if (mode === 'UPDATE') {
|
257
|
-
method = 'Update';
|
258
|
-
}
|
259
|
-
else if (mode === 'UPSERT') {
|
260
|
-
method = 'Upsert';
|
261
|
-
}
|
262
|
-
const inputMethodTypeKey = module_name.toLowerCase() + '.' + key.toLowerCase() + '.' + method.toLowerCase();
|
263
|
-
const nsType = inputMethodType.get(inputMethodTypeKey);
|
264
|
-
if (nsType) {
|
265
|
-
const inputTyping = (0, registry_1.getTyping)(nsType);
|
266
|
-
(0, utils_1.convertEnumToInt)(inputTyping, input);
|
267
|
-
}
|
268
|
-
// check service object contains requested mode's method def
|
269
|
-
if (!service[method]) {
|
270
|
-
throw new Error(`Method ${method} not defined on ${module_name}`);
|
271
|
-
}
|
272
|
-
// update subject token from authorizatin header
|
273
|
-
let subject = {
|
274
|
-
id: '',
|
275
|
-
scope: '',
|
276
|
-
roleAssociations: [],
|
277
|
-
hierarchicalScopes: [],
|
278
|
-
token: '',
|
279
|
-
unauthenticated: false
|
280
|
-
};
|
281
|
-
const authToken = ctx.request.req.headers['authorization'];
|
282
|
-
if (authToken && authToken.startsWith('Bearer ')) {
|
283
|
-
subject.token = authToken.split(' ')[1];
|
284
|
-
}
|
285
|
-
// TODO identify google.protobufAny from config
|
286
|
-
for (let item of input.items) {
|
287
|
-
let keys = Object.keys(item);
|
288
|
-
for (let key of keys) {
|
289
|
-
if (item[key] && item[key].value) {
|
290
|
-
item[key] = { typeUrl: '', value: Buffer.from(JSON.stringify(item.data.value)) };
|
291
|
-
}
|
292
|
-
}
|
293
|
-
}
|
294
|
-
const result = await service[method]({
|
295
|
-
items: input === null || input === void 0 ? void 0 : input.items,
|
296
|
-
subject
|
297
|
-
});
|
298
|
-
// TODO read from grpcClientConfig
|
299
|
-
// const bufferFields = getKeys((grpcClientConfig as any)?.bufferFields);
|
300
|
-
const bufferFields = [];
|
301
|
-
if (result instanceof stream.Readable) {
|
302
|
-
let operationStatus = { code: 0, message: '' };
|
303
|
-
let aggregatedResponse = await new Promise((resolve, reject) => {
|
304
|
-
let response = {};
|
305
|
-
result.on('data', (chunk) => {
|
306
|
-
const chunkObj = _.cloneDeep(chunk);
|
307
|
-
if (!response) {
|
308
|
-
response = chunk;
|
309
|
-
}
|
310
|
-
else {
|
311
|
-
Object.assign(response, chunk);
|
312
|
-
}
|
313
|
-
const existingBufferFields = _.intersection(Object.keys(chunk), bufferFields);
|
314
|
-
for (let bufferField of existingBufferFields) {
|
315
|
-
if (chunkObj[bufferField] && chunkObj[bufferField].value) {
|
316
|
-
if (response[bufferField] && response[bufferField].value && !_.isArray(response[bufferField].value)) {
|
317
|
-
response[bufferField].value = [];
|
318
|
-
}
|
319
|
-
let data = JSON.parse(chunkObj[bufferField].value.toString());
|
320
|
-
if (_.isArray(data)) {
|
321
|
-
for (let dataObj of data) {
|
322
|
-
response[bufferField].value.push(dataObj);
|
323
|
-
}
|
324
|
-
}
|
325
|
-
else {
|
326
|
-
response[bufferField].value.push(data);
|
327
|
-
}
|
328
|
-
}
|
329
|
-
}
|
330
|
-
});
|
331
|
-
result.on('error', (err) => {
|
332
|
-
console.error(err);
|
333
|
-
operationStatus.code = err.code ? err.code : 500;
|
334
|
-
operationStatus.message = err.message;
|
335
|
-
});
|
336
|
-
result.on('end', () => {
|
337
|
-
if (_.isEmpty(operationStatus.message)) {
|
338
|
-
operationStatus.code = 200;
|
339
|
-
operationStatus.message = 'success';
|
340
|
-
}
|
341
|
-
resolve(response);
|
342
|
-
});
|
343
|
-
});
|
344
|
-
return { details: { items: aggregatedResponse, operationStatus } };
|
345
|
-
}
|
346
|
-
// TODO identify google.protobufAny from config
|
347
|
-
// let items = decodeBufferFields(result.items, bufferFields);
|
348
|
-
for (let item of result.items) {
|
349
|
-
if (item && item.payload) {
|
350
|
-
const keys = Object.keys(item.payload);
|
351
|
-
for (let bufferField of keys) {
|
352
|
-
if (item.payload[bufferField] && item.payload[bufferField].value) {
|
353
|
-
item.payload[bufferField].value = JSON.parse(item.payload[bufferField].value.toString());
|
354
|
-
}
|
355
|
-
}
|
356
|
-
}
|
357
|
-
}
|
358
|
-
return {
|
359
|
-
details: {
|
360
|
-
items: result.items,
|
361
|
-
operationStatus: result.operationStatus // overall status
|
362
|
-
}
|
363
|
-
};
|
364
|
-
}
|
365
|
-
catch (error) {
|
366
|
-
console.error(error);
|
367
|
-
return {
|
368
|
-
details: {
|
369
|
-
items: [],
|
370
|
-
operationStatus: {
|
371
|
-
code: error.code,
|
372
|
-
message: error.message
|
373
|
-
}
|
374
|
-
}
|
375
|
-
};
|
376
|
-
}
|
377
|
-
};
|
378
306
|
const registerResolverFunction = (namespace, name, func, mutation = false, subspace = undefined, service) => {
|
379
307
|
if (!namespaceResolverRegistry.has(namespace)) {
|
380
308
|
namespaceResolverRegistry.set(namespace, new Map());
|
@@ -404,11 +332,6 @@ const registerResolverFunction = (namespace, name, func, mutation = false, subsp
|
|
404
332
|
inputMethodType.set(key, value.inputType);
|
405
333
|
}
|
406
334
|
}
|
407
|
-
// custom mutation resolver for create, update and upsert - Mutate
|
408
|
-
if (Mutate.indexOf(name) > -1) {
|
409
|
-
name = 'Mutate';
|
410
|
-
func = MutateResolver;
|
411
|
-
}
|
412
335
|
space.set(name, func);
|
413
336
|
};
|
414
337
|
exports.registerResolverFunction = registerResolverFunction;
|
@@ -601,6 +524,9 @@ const getWhitelistBlacklistConfig = (metaService, queries, config) => {
|
|
601
524
|
}
|
602
525
|
}
|
603
526
|
}
|
527
|
+
if (Mutate.findIndex(val => mut.has(val)) > -1) {
|
528
|
+
mut.add('Mutate');
|
529
|
+
}
|
604
530
|
return {
|
605
531
|
mutations: mut,
|
606
532
|
queries: que
|
@@ -10,6 +10,7 @@ export interface TypingData {
|
|
10
10
|
}
|
11
11
|
export declare const registeredTypings: Map<string, TypingData>;
|
12
12
|
export declare const scalarTypes: string[];
|
13
|
+
export declare const IGoogleProtobufAny: GraphQLInputObjectType;
|
13
14
|
export declare const clearRegistry: () => void;
|
14
15
|
export declare const registerPackagesRecursive: (...protoMetadata: ProtoMetadata[]) => void;
|
15
16
|
export declare const getRegisteredEnumTypings: () => string[];
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getTyping = exports.registerEnumTyping = exports.registerTyping = exports.recursiveEnumCheck = exports.getNameSpaceTypeName = exports.getRegisteredEnumTypings = exports.registerPackagesRecursive = exports.clearRegistry = exports.scalarTypes = exports.registeredTypings = void 0;
|
3
|
+
exports.getTyping = exports.registerEnumTyping = exports.registerTyping = exports.recursiveEnumCheck = exports.getNameSpaceTypeName = exports.getRegisteredEnumTypings = exports.registerPackagesRecursive = exports.clearRegistry = exports.IGoogleProtobufAny = exports.scalarTypes = exports.registeredTypings = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
5
|
const definition_1 = require("graphql/type/definition");
|
6
6
|
const graphql_upload_1 = require("graphql-upload");
|
@@ -14,7 +14,28 @@ const registeredEnumTypes = [];
|
|
14
14
|
const MapScalar = new definition_1.GraphQLScalarType({
|
15
15
|
name: 'MapScalar',
|
16
16
|
});
|
17
|
+
const GoogleProtobufAnyValue = new definition_1.GraphQLScalarType({
|
18
|
+
name: 'GoogleProtobufAnyValue'
|
19
|
+
});
|
20
|
+
const protobufAnyFields = {
|
21
|
+
typeUrl: {
|
22
|
+
type: graphql_1.GraphQLString
|
23
|
+
},
|
24
|
+
value: {
|
25
|
+
type: GoogleProtobufAnyValue
|
26
|
+
}
|
27
|
+
};
|
28
|
+
const GoogleProtobufAny = new graphql_1.GraphQLObjectType({
|
29
|
+
name: 'GoogleProtobufAny',
|
30
|
+
fields: protobufAnyFields
|
31
|
+
});
|
32
|
+
exports.IGoogleProtobufAny = new definition_1.GraphQLInputObjectType({
|
33
|
+
name: 'IGoogleProtobufAny',
|
34
|
+
fields: protobufAnyFields
|
35
|
+
});
|
36
|
+
const googleProtobufAnyName = '.google.protobuf.Any';
|
17
37
|
const Mutate = ['Create', 'Update', 'Upsert'];
|
38
|
+
const CRUD_OPERATION_NAMES = ['Cretae', 'Update', 'Upsert', 'Delete', 'Read'];
|
18
39
|
const TodoScalar = new definition_1.GraphQLScalarType({
|
19
40
|
name: 'TodoScalar',
|
20
41
|
serialize: () => {
|
@@ -119,6 +140,7 @@ const ModeType = new definition_1.GraphQLEnumType({
|
|
119
140
|
});
|
120
141
|
const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
121
142
|
let insertMode = false;
|
143
|
+
let crudOperation = false;
|
122
144
|
const type = (protoPackage.startsWith('.') ? '' : '.') + protoPackage + '.' + message.name;
|
123
145
|
if (methodDef && methodDef.length > 0) {
|
124
146
|
for (let method of methodDef) {
|
@@ -127,8 +149,21 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
|
127
149
|
if ((Mutate.indexOf(method.name) > -1) && type === method.inputType) {
|
128
150
|
insertMode = true;
|
129
151
|
}
|
152
|
+
// add scope
|
153
|
+
if ((CRUD_OPERATION_NAMES.indexOf(method.name) > -1) && type === method.inputType) {
|
154
|
+
crudOperation = true;
|
155
|
+
}
|
130
156
|
}
|
131
157
|
}
|
158
|
+
if (type === googleProtobufAnyName) {
|
159
|
+
// Do not register any type
|
160
|
+
typeNameAndNameSpaceMapping.set(GoogleProtobufAny.name, type);
|
161
|
+
exports.registeredTypings.set(type, {
|
162
|
+
output: GoogleProtobufAny,
|
163
|
+
input: exports.IGoogleProtobufAny,
|
164
|
+
meta: message
|
165
|
+
});
|
166
|
+
}
|
132
167
|
if (exports.registeredTypings.has(type)) {
|
133
168
|
// TODO Log debug "Typings for object are already registered"
|
134
169
|
return;
|
@@ -166,12 +201,14 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
|
166
201
|
type: ModeType
|
167
202
|
};
|
168
203
|
}
|
169
|
-
|
170
|
-
|
171
|
-
result
|
172
|
-
|
173
|
-
|
174
|
-
|
204
|
+
if (crudOperation) {
|
205
|
+
// add scope to all mutations / queries
|
206
|
+
if (!result.scope) {
|
207
|
+
result['scope'] = {
|
208
|
+
description: 'target scope',
|
209
|
+
type: graphql_1.GraphQLString
|
210
|
+
};
|
211
|
+
}
|
175
212
|
}
|
176
213
|
return result;
|
177
214
|
};
|
@@ -235,6 +272,14 @@ const resolveMeta = (key, field, rootObjType, objName, input) => {
|
|
235
272
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_ENUM:
|
236
273
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_MESSAGE:
|
237
274
|
const objType = field.typeName;
|
275
|
+
if (objType === googleProtobufAnyName) {
|
276
|
+
if (input) {
|
277
|
+
result = exports.IGoogleProtobufAny;
|
278
|
+
break;
|
279
|
+
}
|
280
|
+
result = GoogleProtobufAny;
|
281
|
+
break;
|
282
|
+
}
|
238
283
|
if (!exports.registeredTypings.has(objType)) {
|
239
284
|
throw new Error("Typing '" + objType + "' not registered for key '" + key + "' in object: " + objName);
|
240
285
|
}
|
@@ -2,7 +2,7 @@ import { TypingData } from './registry';
|
|
2
2
|
export declare const capitalizeProtoName: (name: string) => string;
|
3
3
|
export declare const convertyCamelToSnakeCase: (entity: string) => string;
|
4
4
|
export declare const getKeys: (obj: any) => string[];
|
5
|
-
export declare const decodeBufferFields: (items: any, bufferFields: string[]) => any;
|
5
|
+
export declare const decodeBufferFields: (items: any[], bufferFields: string[]) => any;
|
6
6
|
/**
|
7
7
|
* converts enum string values to integers reading from the inputTyping
|
8
8
|
* @param TypingData input typing
|
package/dist/gql/protos/utils.js
CHANGED
@@ -36,7 +36,7 @@ const decodeBufferFields = (items, bufferFields) => {
|
|
36
36
|
if (item && item.payload) {
|
37
37
|
const existingBufferFields = _.intersection(Object.keys(item.payload), bufferFields);
|
38
38
|
for (let bufferField of existingBufferFields) {
|
39
|
-
if (item.payload[bufferField] && item.payload[bufferField].value) {
|
39
|
+
if (item.payload[bufferField] && item.payload[bufferField].value && item.payload[bufferField].value instanceof Buffer) {
|
40
40
|
item.payload[bufferField].value = JSON.parse(item.payload[bufferField].value.toString());
|
41
41
|
}
|
42
42
|
}
|