@geins/core 0.3.3 → 0.3.4-canary
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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +7 -0
- package/dist/index.cjs +29 -6
- package/dist/index.esm.js +29 -6
- package/dist/services/graphQLService.d.ts +1 -0
- package/package.json +3 -3
- package/src/services/graphQLService.ts +28 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -2,5 +2,5 @@ yarn run v1.22.22
|
|
|
2
2
|
$ rollup -c
|
|
3
3
|
[36m
|
|
4
4
|
[1msrc/index.ts[22m → [1mdist/index.cjs, dist/index.esm.js[22m...[39m
|
|
5
|
-
[32mcreated [1mdist/index.cjs, dist/index.esm.js[22m in [1m6.
|
|
6
|
-
Done in
|
|
5
|
+
[32mcreated [1mdist/index.cjs, dist/index.esm.js[22m in [1m6.1s[22m[39m
|
|
6
|
+
Done in 6.66s.
|
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -21378,6 +21378,26 @@ var GraphQLService = /** @class */ (function (_super) {
|
|
|
21378
21378
|
function GraphQLService(client, geinsSettings) {
|
|
21379
21379
|
return _super.call(this, client, geinsSettings) || this;
|
|
21380
21380
|
}
|
|
21381
|
+
GraphQLService.prototype.verifyQueryOptions = function (options) {
|
|
21382
|
+
var _a, _b, _c, _d;
|
|
21383
|
+
if (!options.query) {
|
|
21384
|
+
throw new Error('Query is required');
|
|
21385
|
+
}
|
|
21386
|
+
if (!(((_d = (_c = (_b = (_a = options.query) === null || _a === void 0 ? void 0 : _a.definitions) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.variableDefinitions) === null || _d === void 0 ? void 0 : _d.length) > 0)) {
|
|
21387
|
+
console.log('NO VARS');
|
|
21388
|
+
return options;
|
|
21389
|
+
}
|
|
21390
|
+
var queryOptions = __assign({}, options);
|
|
21391
|
+
queryOptions.variables = this.createVariables(queryOptions.variables);
|
|
21392
|
+
var queryVars = queryOptions.query.definitions[0].variableDefinitions.map(function (v) { return v.variable.name.value; });
|
|
21393
|
+
var providedVars = Object.keys(queryOptions.variables);
|
|
21394
|
+
providedVars.forEach(function (v) {
|
|
21395
|
+
if (!queryVars.includes(v)) {
|
|
21396
|
+
delete queryOptions.variables[v];
|
|
21397
|
+
}
|
|
21398
|
+
});
|
|
21399
|
+
return queryOptions;
|
|
21400
|
+
};
|
|
21381
21401
|
/**
|
|
21382
21402
|
* Generic method to run any GraphQL query
|
|
21383
21403
|
* @param query - The GraphQL query DocumentNode or gql query object
|
|
@@ -21387,22 +21407,25 @@ var GraphQLService = /** @class */ (function (_super) {
|
|
|
21387
21407
|
*/
|
|
21388
21408
|
GraphQLService.prototype.query = function (options) {
|
|
21389
21409
|
return __awaiter(this, void 0, void 0, function () {
|
|
21390
|
-
var result, _a, parsedResult, error_1;
|
|
21410
|
+
var queryOptions, result, _a, parsedResult, error_1;
|
|
21391
21411
|
return __generator(this, function (_b) {
|
|
21392
21412
|
switch (_b.label) {
|
|
21393
21413
|
case 0:
|
|
21394
|
-
_b.trys.push([0,
|
|
21395
|
-
|
|
21396
|
-
return [4 /*yield*/, this.runQuery(options)];
|
|
21414
|
+
_b.trys.push([0, 3, , 4]);
|
|
21415
|
+
return [4 /*yield*/, this.verifyQueryOptions(options)];
|
|
21397
21416
|
case 1:
|
|
21417
|
+
queryOptions = _b.sent();
|
|
21418
|
+
_a = this.cleanObject;
|
|
21419
|
+
return [4 /*yield*/, this.runQuery(queryOptions)];
|
|
21420
|
+
case 2:
|
|
21398
21421
|
result = _a.apply(this, [_b.sent()]);
|
|
21399
21422
|
parsedResult = this.parseResult(result);
|
|
21400
21423
|
return [2 /*return*/, parsedResult];
|
|
21401
|
-
case
|
|
21424
|
+
case 3:
|
|
21402
21425
|
error_1 = _b.sent();
|
|
21403
21426
|
console.error('Query error:', error_1);
|
|
21404
21427
|
return [2 /*return*/, null];
|
|
21405
|
-
case
|
|
21428
|
+
case 4: return [2 /*return*/, null];
|
|
21406
21429
|
}
|
|
21407
21430
|
});
|
|
21408
21431
|
});
|
package/dist/index.esm.js
CHANGED
|
@@ -21376,6 +21376,26 @@ var GraphQLService = /** @class */ (function (_super) {
|
|
|
21376
21376
|
function GraphQLService(client, geinsSettings) {
|
|
21377
21377
|
return _super.call(this, client, geinsSettings) || this;
|
|
21378
21378
|
}
|
|
21379
|
+
GraphQLService.prototype.verifyQueryOptions = function (options) {
|
|
21380
|
+
var _a, _b, _c, _d;
|
|
21381
|
+
if (!options.query) {
|
|
21382
|
+
throw new Error('Query is required');
|
|
21383
|
+
}
|
|
21384
|
+
if (!(((_d = (_c = (_b = (_a = options.query) === null || _a === void 0 ? void 0 : _a.definitions) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.variableDefinitions) === null || _d === void 0 ? void 0 : _d.length) > 0)) {
|
|
21385
|
+
console.log('NO VARS');
|
|
21386
|
+
return options;
|
|
21387
|
+
}
|
|
21388
|
+
var queryOptions = __assign({}, options);
|
|
21389
|
+
queryOptions.variables = this.createVariables(queryOptions.variables);
|
|
21390
|
+
var queryVars = queryOptions.query.definitions[0].variableDefinitions.map(function (v) { return v.variable.name.value; });
|
|
21391
|
+
var providedVars = Object.keys(queryOptions.variables);
|
|
21392
|
+
providedVars.forEach(function (v) {
|
|
21393
|
+
if (!queryVars.includes(v)) {
|
|
21394
|
+
delete queryOptions.variables[v];
|
|
21395
|
+
}
|
|
21396
|
+
});
|
|
21397
|
+
return queryOptions;
|
|
21398
|
+
};
|
|
21379
21399
|
/**
|
|
21380
21400
|
* Generic method to run any GraphQL query
|
|
21381
21401
|
* @param query - The GraphQL query DocumentNode or gql query object
|
|
@@ -21385,22 +21405,25 @@ var GraphQLService = /** @class */ (function (_super) {
|
|
|
21385
21405
|
*/
|
|
21386
21406
|
GraphQLService.prototype.query = function (options) {
|
|
21387
21407
|
return __awaiter(this, void 0, void 0, function () {
|
|
21388
|
-
var result, _a, parsedResult, error_1;
|
|
21408
|
+
var queryOptions, result, _a, parsedResult, error_1;
|
|
21389
21409
|
return __generator(this, function (_b) {
|
|
21390
21410
|
switch (_b.label) {
|
|
21391
21411
|
case 0:
|
|
21392
|
-
_b.trys.push([0,
|
|
21393
|
-
|
|
21394
|
-
return [4 /*yield*/, this.runQuery(options)];
|
|
21412
|
+
_b.trys.push([0, 3, , 4]);
|
|
21413
|
+
return [4 /*yield*/, this.verifyQueryOptions(options)];
|
|
21395
21414
|
case 1:
|
|
21415
|
+
queryOptions = _b.sent();
|
|
21416
|
+
_a = this.cleanObject;
|
|
21417
|
+
return [4 /*yield*/, this.runQuery(queryOptions)];
|
|
21418
|
+
case 2:
|
|
21396
21419
|
result = _a.apply(this, [_b.sent()]);
|
|
21397
21420
|
parsedResult = this.parseResult(result);
|
|
21398
21421
|
return [2 /*return*/, parsedResult];
|
|
21399
|
-
case
|
|
21422
|
+
case 3:
|
|
21400
21423
|
error_1 = _b.sent();
|
|
21401
21424
|
console.error('Query error:', error_1);
|
|
21402
21425
|
return [2 /*return*/, null];
|
|
21403
|
-
case
|
|
21426
|
+
case 4: return [2 /*return*/, null];
|
|
21404
21427
|
}
|
|
21405
21428
|
});
|
|
21406
21429
|
});
|
|
@@ -3,6 +3,7 @@ import { BaseApiService } from '../base/baseApiService';
|
|
|
3
3
|
import { GraphQLQueryOptions } from '../api-client/merchantApiClient';
|
|
4
4
|
export declare class GraphQLService extends BaseApiService {
|
|
5
5
|
constructor(client: any, geinsSettings: GeinsSettings);
|
|
6
|
+
protected verifyQueryOptions(options: GraphQLQueryOptions): GraphQLQueryOptions;
|
|
6
7
|
/**
|
|
7
8
|
* Generic method to run any GraphQL query
|
|
8
9
|
* @param query - The GraphQL query DocumentNode or gql query object
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geins/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4-canary",
|
|
4
4
|
"main": "dist/index.cjs",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"broadcast-channel": "^7.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@geins/types": "0.3.
|
|
24
|
-
"@geins/eslint-config": "
|
|
23
|
+
"@geins/types": "0.3.4-canary",
|
|
24
|
+
"@geins/eslint-config": "0.1.5-canary",
|
|
25
25
|
"@rollup/plugin-commonjs": "^28.0.0",
|
|
26
26
|
"@rollup/plugin-graphql": "^2.0.5",
|
|
27
27
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
@@ -6,6 +6,31 @@ export class GraphQLService extends BaseApiService {
|
|
|
6
6
|
constructor(client: any, geinsSettings: GeinsSettings) {
|
|
7
7
|
super(client, geinsSettings);
|
|
8
8
|
}
|
|
9
|
+
protected verifyQueryOptions(options: GraphQLQueryOptions): GraphQLQueryOptions {
|
|
10
|
+
if (!options.query) {
|
|
11
|
+
throw new Error('Query is required');
|
|
12
|
+
}
|
|
13
|
+
if (!(options.query?.definitions?.[0]?.variableDefinitions?.length > 0)) {
|
|
14
|
+
console.log('NO VARS');
|
|
15
|
+
return options;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const queryOptions = { ...options };
|
|
19
|
+
queryOptions.variables = this.createVariables(queryOptions.variables);
|
|
20
|
+
|
|
21
|
+
const queryVars = queryOptions.query.definitions[0].variableDefinitions.map(
|
|
22
|
+
(v: any) => v.variable.name.value,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const providedVars = Object.keys(queryOptions.variables);
|
|
26
|
+
providedVars.forEach(v => {
|
|
27
|
+
if (!queryVars.includes(v)) {
|
|
28
|
+
delete queryOptions.variables[v];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return queryOptions;
|
|
33
|
+
}
|
|
9
34
|
|
|
10
35
|
/**
|
|
11
36
|
* Generic method to run any GraphQL query
|
|
@@ -16,7 +41,9 @@ export class GraphQLService extends BaseApiService {
|
|
|
16
41
|
*/
|
|
17
42
|
async query<T = any>(options: GraphQLQueryOptions): Promise<T | null> {
|
|
18
43
|
try {
|
|
19
|
-
const
|
|
44
|
+
const queryOptions = await this.verifyQueryOptions(options);
|
|
45
|
+
|
|
46
|
+
const result = this.cleanObject(await this.runQuery(queryOptions));
|
|
20
47
|
const parsedResult = this.parseResult(result);
|
|
21
48
|
return parsedResult as T;
|
|
22
49
|
} catch (error) {
|