@graphql-mesh/transform-encapsulate 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/cjs/index.js +55 -0
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +22 -20
- package/package.json +26 -19
- package/typings/index.d.cts +15 -0
- package/{index.d.ts → typings/index.d.ts} +7 -5
- package/index.js +0 -52
package/cjs/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
4
|
+
const utils_2 = require("@graphql-tools/utils");
|
|
5
|
+
const wrap_1 = require("@graphql-tools/wrap");
|
|
6
|
+
const OPERATION_TYPE_SUFFIX_MAP = {
|
|
7
|
+
query: 'Query',
|
|
8
|
+
mutation: 'Mutation',
|
|
9
|
+
subscription: 'Subscription',
|
|
10
|
+
};
|
|
11
|
+
const DEFAULT_APPLY_TO = {
|
|
12
|
+
query: true,
|
|
13
|
+
mutation: true,
|
|
14
|
+
subscription: true,
|
|
15
|
+
};
|
|
16
|
+
class EncapsulateTransform {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
var _a;
|
|
19
|
+
this.transformMap = {};
|
|
20
|
+
this.transforms = [];
|
|
21
|
+
this.config = options.config;
|
|
22
|
+
this.name = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.name) || options.apiName;
|
|
23
|
+
if (!this.name) {
|
|
24
|
+
throw new Error(`Unable to execute encapsulate transform without a name. Please make sure to use it over a specific schema, or specify a name in your configuration!`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
*generateSchemaTransforms(originalWrappingSchema) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const applyTo = { ...DEFAULT_APPLY_TO, ...(((_a = this.config) === null || _a === void 0 ? void 0 : _a.applyTo) || {}) };
|
|
30
|
+
const outerTypeNames = (0, utils_2.getRootTypeMap)(originalWrappingSchema);
|
|
31
|
+
for (const operationType in applyTo) {
|
|
32
|
+
const outerTypeName = (_b = outerTypeNames.get(operationType)) === null || _b === void 0 ? void 0 : _b.name;
|
|
33
|
+
if (outerTypeName) {
|
|
34
|
+
this.transformMap[outerTypeName] = new wrap_1.WrapType(outerTypeName, `${this.name}${OPERATION_TYPE_SUFFIX_MAP[operationType]}`, this.name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const typeName of Object.keys(this.transformMap)) {
|
|
38
|
+
const fieldConfigMap = (0, utils_2.selectObjectFields)(originalWrappingSchema, typeName, () => true);
|
|
39
|
+
if (Object.keys(fieldConfigMap).length) {
|
|
40
|
+
yield this.transformMap[typeName];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
45
|
+
this.transforms = [...this.generateSchemaTransforms(originalWrappingSchema)];
|
|
46
|
+
return (0, utils_1.applySchemaTransforms)(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
|
|
47
|
+
}
|
|
48
|
+
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
49
|
+
return (0, utils_1.applyRequestTransforms)(originalRequest, delegationContext, transformationContext, this.transforms);
|
|
50
|
+
}
|
|
51
|
+
transformResult(originalResult, delegationContext, transformationContext) {
|
|
52
|
+
return (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformationContext, this.transforms);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = EncapsulateTransform;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
+
import { applyRequestTransforms, applyResultTransforms, applySchemaTransforms, } from '@graphql-mesh/utils';
|
|
2
|
+
import { getRootTypeMap, selectObjectFields, } from '@graphql-tools/utils';
|
|
1
3
|
import { WrapType } from '@graphql-tools/wrap';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const OPERATION_TYPE_SUFFIX_MAP = {
|
|
5
|
+
query: 'Query',
|
|
6
|
+
mutation: 'Mutation',
|
|
7
|
+
subscription: 'Subscription',
|
|
8
|
+
};
|
|
9
|
+
const DEFAULT_APPLY_TO = {
|
|
6
10
|
query: true,
|
|
7
11
|
mutation: true,
|
|
8
12
|
subscription: true,
|
|
9
13
|
};
|
|
10
|
-
class EncapsulateTransform {
|
|
14
|
+
export default class EncapsulateTransform {
|
|
11
15
|
constructor(options) {
|
|
16
|
+
var _a;
|
|
12
17
|
this.transformMap = {};
|
|
13
18
|
this.transforms = [];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!name) {
|
|
19
|
+
this.config = options.config;
|
|
20
|
+
this.name = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.name) || options.apiName;
|
|
21
|
+
if (!this.name) {
|
|
17
22
|
throw new Error(`Unable to execute encapsulate transform without a name. Please make sure to use it over a specific schema, or specify a name in your configuration!`);
|
|
18
23
|
}
|
|
19
|
-
const applyTo = { ...DEFUALT_APPLY_TO, ...((config === null || config === void 0 ? void 0 : config.applyTo) || {}) };
|
|
20
|
-
if (applyTo.query) {
|
|
21
|
-
this.transformMap.Query = new WrapType('Query', `${name}Query`, name);
|
|
22
|
-
}
|
|
23
|
-
if (applyTo.mutation) {
|
|
24
|
-
this.transformMap.Mutation = new WrapType('Mutation', `${name}Mutation`, name);
|
|
25
|
-
}
|
|
26
|
-
if (applyTo.subscription) {
|
|
27
|
-
this.transformMap.Subscription = new WrapType('Subscription', `${name}Subscription`, name);
|
|
28
|
-
}
|
|
29
24
|
}
|
|
30
25
|
*generateSchemaTransforms(originalWrappingSchema) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const applyTo = { ...DEFAULT_APPLY_TO, ...(((_a = this.config) === null || _a === void 0 ? void 0 : _a.applyTo) || {}) };
|
|
28
|
+
const outerTypeNames = getRootTypeMap(originalWrappingSchema);
|
|
29
|
+
for (const operationType in applyTo) {
|
|
30
|
+
const outerTypeName = (_b = outerTypeNames.get(operationType)) === null || _b === void 0 ? void 0 : _b.name;
|
|
31
|
+
if (outerTypeName) {
|
|
32
|
+
this.transformMap[outerTypeName] = new WrapType(outerTypeName, `${this.name}${OPERATION_TYPE_SUFFIX_MAP[operationType]}`, this.name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
31
35
|
for (const typeName of Object.keys(this.transformMap)) {
|
|
32
36
|
const fieldConfigMap = selectObjectFields(originalWrappingSchema, typeName, () => true);
|
|
33
37
|
if (Object.keys(fieldConfigMap).length) {
|
|
@@ -46,5 +50,3 @@ class EncapsulateTransform {
|
|
|
46
50
|
return applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
export default EncapsulateTransform;
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/transform-encapsulate",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/types": "0.
|
|
7
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
8
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
7
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-tools/utils": "^9.2.1",
|
|
9
|
+
"graphql": "*",
|
|
10
|
+
"tslib": "^2.4.0"
|
|
9
11
|
},
|
|
10
12
|
"dependencies": {
|
|
11
|
-
"@graphql-tools/delegate": "
|
|
12
|
-
"@graphql-tools/
|
|
13
|
-
"@graphql-tools/wrap": "8.5.0",
|
|
14
|
-
"tslib": "^2.4.0"
|
|
13
|
+
"@graphql-tools/delegate": "9.0.32",
|
|
14
|
+
"@graphql-tools/wrap": "9.4.2"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -19,21 +19,28 @@
|
|
|
19
19
|
"directory": "packages/transforms/encapsulate"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"main": "index.js",
|
|
23
|
-
"module": "index.
|
|
24
|
-
"typings": "index.d.ts",
|
|
22
|
+
"main": "cjs/index.js",
|
|
23
|
+
"module": "esm/index.js",
|
|
24
|
+
"typings": "typings/index.d.ts",
|
|
25
25
|
"typescript": {
|
|
26
|
-
"definition": "index.d.ts"
|
|
26
|
+
"definition": "typings/index.d.ts"
|
|
27
27
|
},
|
|
28
|
+
"type": "module",
|
|
28
29
|
"exports": {
|
|
29
30
|
".": {
|
|
30
|
-
"require":
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./typings/index.d.cts",
|
|
33
|
+
"default": "./cjs/index.js"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./typings/index.d.ts",
|
|
37
|
+
"default": "./esm/index.js"
|
|
38
|
+
},
|
|
39
|
+
"default": {
|
|
40
|
+
"types": "./typings/index.d.ts",
|
|
41
|
+
"default": "./esm/index.js"
|
|
42
|
+
}
|
|
36
43
|
},
|
|
37
44
|
"./package.json": "./package.json"
|
|
38
45
|
}
|
|
39
|
-
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
4
|
+
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
5
|
+
export default class EncapsulateTransform implements MeshTransform {
|
|
6
|
+
private transformMap;
|
|
7
|
+
private transforms;
|
|
8
|
+
private config;
|
|
9
|
+
private name;
|
|
10
|
+
constructor(options: MeshTransformOptions<YamlConfig.Transform['encapsulate']>);
|
|
11
|
+
generateSchemaTransforms(originalWrappingSchema: GraphQLSchema): Generator<Transform<any, Record<string, any>>, void, unknown>;
|
|
12
|
+
transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig, transformedSchema?: GraphQLSchema): GraphQLSchema;
|
|
13
|
+
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<any, any, any, Record<string, any>, any>;
|
|
14
|
+
transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<any, any>;
|
|
15
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { MeshTransform,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
4
|
+
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
5
5
|
export default class EncapsulateTransform implements MeshTransform {
|
|
6
6
|
private transformMap;
|
|
7
7
|
private transforms;
|
|
8
|
+
private config;
|
|
9
|
+
private name;
|
|
8
10
|
constructor(options: MeshTransformOptions<YamlConfig.Transform['encapsulate']>);
|
|
9
11
|
generateSchemaTransforms(originalWrappingSchema: GraphQLSchema): Generator<Transform<any, Record<string, any>>, void, unknown>;
|
|
10
12
|
transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig, transformedSchema?: GraphQLSchema): GraphQLSchema;
|
|
11
|
-
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<
|
|
12
|
-
transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<
|
|
13
|
+
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<any, any, any, Record<string, any>, any>;
|
|
14
|
+
transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<any, any>;
|
|
13
15
|
}
|
package/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const wrap = require('@graphql-tools/wrap');
|
|
4
|
-
const utils = require('@graphql-tools/utils');
|
|
5
|
-
const utils$1 = require('@graphql-mesh/utils');
|
|
6
|
-
|
|
7
|
-
const DEFUALT_APPLY_TO = {
|
|
8
|
-
query: true,
|
|
9
|
-
mutation: true,
|
|
10
|
-
subscription: true,
|
|
11
|
-
};
|
|
12
|
-
class EncapsulateTransform {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
this.transformMap = {};
|
|
15
|
-
this.transforms = [];
|
|
16
|
-
const config = options.config;
|
|
17
|
-
const name = (config === null || config === void 0 ? void 0 : config.name) || options.apiName;
|
|
18
|
-
if (!name) {
|
|
19
|
-
throw new Error(`Unable to execute encapsulate transform without a name. Please make sure to use it over a specific schema, or specify a name in your configuration!`);
|
|
20
|
-
}
|
|
21
|
-
const applyTo = { ...DEFUALT_APPLY_TO, ...((config === null || config === void 0 ? void 0 : config.applyTo) || {}) };
|
|
22
|
-
if (applyTo.query) {
|
|
23
|
-
this.transformMap.Query = new wrap.WrapType('Query', `${name}Query`, name);
|
|
24
|
-
}
|
|
25
|
-
if (applyTo.mutation) {
|
|
26
|
-
this.transformMap.Mutation = new wrap.WrapType('Mutation', `${name}Mutation`, name);
|
|
27
|
-
}
|
|
28
|
-
if (applyTo.subscription) {
|
|
29
|
-
this.transformMap.Subscription = new wrap.WrapType('Subscription', `${name}Subscription`, name);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
*generateSchemaTransforms(originalWrappingSchema) {
|
|
33
|
-
for (const typeName of Object.keys(this.transformMap)) {
|
|
34
|
-
const fieldConfigMap = utils.selectObjectFields(originalWrappingSchema, typeName, () => true);
|
|
35
|
-
if (Object.keys(fieldConfigMap).length) {
|
|
36
|
-
yield this.transformMap[typeName];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
41
|
-
this.transforms = [...this.generateSchemaTransforms(originalWrappingSchema)];
|
|
42
|
-
return utils$1.applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
|
|
43
|
-
}
|
|
44
|
-
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
45
|
-
return utils$1.applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
|
|
46
|
-
}
|
|
47
|
-
transformResult(originalResult, delegationContext, transformationContext) {
|
|
48
|
-
return utils$1.applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
module.exports = EncapsulateTransform;
|