@graphql-mesh/transform-prefix 1.0.0-alpha-20220804093904-8e2e41f7f → 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.
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const utils_1 = require("@graphql-tools/utils");
5
+ const shared_js_1 = require("./shared.js");
6
+ const rootOperations = new Set(['Query', 'Mutation', 'Subscription']);
7
+ class BarePrefix {
8
+ constructor(options) {
9
+ this.noWrap = true;
10
+ const { apiName, config } = options;
11
+ this.ignoreList = [...(config.ignore || []), ...shared_js_1.ignoreList];
12
+ this.includeRootOperations = config.includeRootOperations === true;
13
+ this.includeTypes = config.includeTypes !== false;
14
+ this.prefix = null;
15
+ if (config.value) {
16
+ this.prefix = config.value;
17
+ }
18
+ else if (apiName) {
19
+ this.prefix = `${apiName}_`;
20
+ }
21
+ if (!this.prefix) {
22
+ throw new Error(`Transform 'prefix' has missing config: prefix`);
23
+ }
24
+ }
25
+ transformSchema(schema) {
26
+ return (0, utils_1.mapSchema)(schema, {
27
+ [utils_1.MapperKind.TYPE]: (type) => {
28
+ if (this.includeTypes && !(0, graphql_1.isSpecifiedScalarType)(type)) {
29
+ const currentName = type.name;
30
+ if (!this.ignoreList.includes(currentName)) {
31
+ return (0, utils_1.renameType)(type, this.prefix + currentName);
32
+ }
33
+ }
34
+ return undefined;
35
+ },
36
+ [utils_1.MapperKind.ABSTRACT_TYPE]: type => {
37
+ if (this.includeTypes && !(0, graphql_1.isSpecifiedScalarType)(type)) {
38
+ const existingResolver = type.resolveType;
39
+ type.resolveType = async (data, context, info, abstractType) => {
40
+ const typeName = await existingResolver(data, context, info, abstractType);
41
+ return this.prefix + typeName;
42
+ };
43
+ const currentName = type.name;
44
+ return (0, utils_1.renameType)(type, this.prefix + currentName);
45
+ }
46
+ return undefined;
47
+ },
48
+ [utils_1.MapperKind.ROOT_OBJECT]() {
49
+ return undefined;
50
+ },
51
+ ...(this.includeRootOperations && {
52
+ [utils_1.MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
53
+ return !rootOperations.has(typeName) || // check we're in a root Type
54
+ this.ignoreList.includes(typeName) || // check if type is to be ignored
55
+ this.ignoreList.includes(`${typeName}.${fieldName}`) // check if field in type is to be ignored
56
+ ? undefined // do not perform any change
57
+ : [`${this.prefix}${fieldName}`, fieldConfig]; // apply prefix
58
+ },
59
+ }),
60
+ });
61
+ }
62
+ }
63
+ exports.default = BarePrefix;
package/cjs/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const barePrefix_js_1 = tslib_1.__importDefault(require("./barePrefix.js"));
5
+ const wrapPrefix_js_1 = tslib_1.__importDefault(require("./wrapPrefix.js"));
6
+ exports.default = (function PrefixTransform(options) {
7
+ return options.config.mode === 'bare' ? new barePrefix_js_1.default(options) : new wrapPrefix_js_1.default(options);
8
+ });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/cjs/shared.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ignoreList = void 0;
4
+ const graphql_scalars_1 = require("graphql-scalars");
5
+ exports.ignoreList = [
6
+ 'Int',
7
+ 'Float',
8
+ 'String',
9
+ 'Boolean',
10
+ 'ID',
11
+ 'date',
12
+ 'hostname',
13
+ 'regex',
14
+ 'json-pointer',
15
+ 'relative-json-pointer',
16
+ 'uri-reference',
17
+ 'uri-template',
18
+ 'ObjMap',
19
+ 'HttpMethod',
20
+ ...Object.keys(graphql_scalars_1.resolvers),
21
+ ];
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@graphql-mesh/utils");
4
+ const wrap_1 = require("@graphql-tools/wrap");
5
+ const shared_js_1 = require("./shared.js");
6
+ class WrapPrefix {
7
+ constructor(options) {
8
+ this.transforms = [];
9
+ const { apiName, config } = options;
10
+ let prefix = null;
11
+ if (config.value) {
12
+ prefix = config.value;
13
+ }
14
+ else if (apiName) {
15
+ prefix = `${apiName}_`;
16
+ }
17
+ if (!prefix) {
18
+ throw new Error(`Transform 'prefix' has missing config: prefix`);
19
+ }
20
+ const ignoreList = [...(config.ignore || []), ...shared_js_1.ignoreList];
21
+ const includeTypes = config.includeTypes !== false;
22
+ if (includeTypes) {
23
+ this.transforms.push(new wrap_1.RenameTypes(typeName => ignoreList.includes(typeName) ? typeName : `${prefix}${typeName}`));
24
+ }
25
+ const includeRootOperations = config.includeRootOperations === true;
26
+ if (includeRootOperations) {
27
+ this.transforms.push(new wrap_1.RenameRootFields((typeName, fieldName) => ignoreList.includes(typeName) || ignoreList.includes(`${typeName}.${fieldName}`)
28
+ ? fieldName
29
+ : `${prefix}${fieldName}`));
30
+ }
31
+ }
32
+ transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
33
+ return (0, utils_1.applySchemaTransforms)(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
34
+ }
35
+ transformRequest(originalRequest, delegationContext, transformationContext) {
36
+ return (0, utils_1.applyRequestTransforms)(originalRequest, delegationContext, transformationContext, this.transforms);
37
+ }
38
+ transformResult(originalResult, delegationContext, transformationContext) {
39
+ return (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformationContext, this.transforms);
40
+ }
41
+ }
42
+ exports.default = WrapPrefix;
@@ -0,0 +1,60 @@
1
+ import { isSpecifiedScalarType, } from 'graphql';
2
+ import { MapperKind, mapSchema, renameType } from '@graphql-tools/utils';
3
+ import { ignoreList as defaultIgnoreList } from './shared.js';
4
+ const rootOperations = new Set(['Query', 'Mutation', 'Subscription']);
5
+ export default class BarePrefix {
6
+ constructor(options) {
7
+ this.noWrap = true;
8
+ const { apiName, config } = options;
9
+ this.ignoreList = [...(config.ignore || []), ...defaultIgnoreList];
10
+ this.includeRootOperations = config.includeRootOperations === true;
11
+ this.includeTypes = config.includeTypes !== false;
12
+ this.prefix = null;
13
+ if (config.value) {
14
+ this.prefix = config.value;
15
+ }
16
+ else if (apiName) {
17
+ this.prefix = `${apiName}_`;
18
+ }
19
+ if (!this.prefix) {
20
+ throw new Error(`Transform 'prefix' has missing config: prefix`);
21
+ }
22
+ }
23
+ transformSchema(schema) {
24
+ return mapSchema(schema, {
25
+ [MapperKind.TYPE]: (type) => {
26
+ if (this.includeTypes && !isSpecifiedScalarType(type)) {
27
+ const currentName = type.name;
28
+ if (!this.ignoreList.includes(currentName)) {
29
+ return renameType(type, this.prefix + currentName);
30
+ }
31
+ }
32
+ return undefined;
33
+ },
34
+ [MapperKind.ABSTRACT_TYPE]: type => {
35
+ if (this.includeTypes && !isSpecifiedScalarType(type)) {
36
+ const existingResolver = type.resolveType;
37
+ type.resolveType = async (data, context, info, abstractType) => {
38
+ const typeName = await existingResolver(data, context, info, abstractType);
39
+ return this.prefix + typeName;
40
+ };
41
+ const currentName = type.name;
42
+ return renameType(type, this.prefix + currentName);
43
+ }
44
+ return undefined;
45
+ },
46
+ [MapperKind.ROOT_OBJECT]() {
47
+ return undefined;
48
+ },
49
+ ...(this.includeRootOperations && {
50
+ [MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
51
+ return !rootOperations.has(typeName) || // check we're in a root Type
52
+ this.ignoreList.includes(typeName) || // check if type is to be ignored
53
+ this.ignoreList.includes(`${typeName}.${fieldName}`) // check if field in type is to be ignored
54
+ ? undefined // do not perform any change
55
+ : [`${this.prefix}${fieldName}`, fieldConfig]; // apply prefix
56
+ },
57
+ }),
58
+ });
59
+ }
60
+ }
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import BarePrefix from './barePrefix.js';
2
+ import WrapPrefix from './wrapPrefix.js';
3
+ export default (function PrefixTransform(options) {
4
+ return options.config.mode === 'bare' ? new BarePrefix(options) : new WrapPrefix(options);
5
+ });
package/esm/shared.js ADDED
@@ -0,0 +1,18 @@
1
+ import { resolvers as scalarsResolversMap } from 'graphql-scalars';
2
+ export const ignoreList = [
3
+ 'Int',
4
+ 'Float',
5
+ 'String',
6
+ 'Boolean',
7
+ 'ID',
8
+ 'date',
9
+ 'hostname',
10
+ 'regex',
11
+ 'json-pointer',
12
+ 'relative-json-pointer',
13
+ 'uri-reference',
14
+ 'uri-template',
15
+ 'ObjMap',
16
+ 'HttpMethod',
17
+ ...Object.keys(scalarsResolversMap),
18
+ ];
@@ -0,0 +1,39 @@
1
+ import { applyRequestTransforms, applyResultTransforms, applySchemaTransforms, } from '@graphql-mesh/utils';
2
+ import { RenameRootFields, RenameTypes } from '@graphql-tools/wrap';
3
+ import { ignoreList as defaultIgnoreList } from './shared.js';
4
+ export default class WrapPrefix {
5
+ constructor(options) {
6
+ this.transforms = [];
7
+ const { apiName, config } = options;
8
+ let prefix = null;
9
+ if (config.value) {
10
+ prefix = config.value;
11
+ }
12
+ else if (apiName) {
13
+ prefix = `${apiName}_`;
14
+ }
15
+ if (!prefix) {
16
+ throw new Error(`Transform 'prefix' has missing config: prefix`);
17
+ }
18
+ const ignoreList = [...(config.ignore || []), ...defaultIgnoreList];
19
+ const includeTypes = config.includeTypes !== false;
20
+ if (includeTypes) {
21
+ this.transforms.push(new RenameTypes(typeName => ignoreList.includes(typeName) ? typeName : `${prefix}${typeName}`));
22
+ }
23
+ const includeRootOperations = config.includeRootOperations === true;
24
+ if (includeRootOperations) {
25
+ this.transforms.push(new RenameRootFields((typeName, fieldName) => ignoreList.includes(typeName) || ignoreList.includes(`${typeName}.${fieldName}`)
26
+ ? fieldName
27
+ : `${prefix}${fieldName}`));
28
+ }
29
+ }
30
+ transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
31
+ return applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
32
+ }
33
+ transformRequest(originalRequest, delegationContext, transformationContext) {
34
+ return applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
35
+ }
36
+ transformResult(originalResult, delegationContext, transformationContext) {
37
+ return applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
38
+ }
39
+ }
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@graphql-mesh/transform-prefix",
3
- "version": "1.0.0-alpha-20220804093904-8e2e41f7f",
3
+ "version": "1.0.0-alpha-20230420181317-a95037648",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-20220804093904-8e2e41f7f",
7
- "@graphql-mesh/utils": "1.0.0-alpha-20220804093904-8e2e41f7f",
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": "8.8.1",
12
- "@graphql-tools/utils": "8.9.0",
13
- "@graphql-tools/wrap": "8.5.1",
14
- "graphql-scalars": "1.17.0",
15
- "tslib": "^2.4.0"
13
+ "@graphql-tools/delegate": "9.0.32",
14
+ "@graphql-tools/wrap": "9.4.2",
15
+ "graphql-scalars": "^1.20.4"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
@@ -20,21 +20,28 @@
20
20
  "directory": "packages/transforms/prefix"
21
21
  },
22
22
  "license": "MIT",
23
- "main": "index.js",
24
- "module": "index.mjs",
25
- "typings": "index.d.ts",
23
+ "main": "cjs/index.js",
24
+ "module": "esm/index.js",
25
+ "typings": "typings/index.d.ts",
26
26
  "typescript": {
27
- "definition": "index.d.ts"
27
+ "definition": "typings/index.d.ts"
28
28
  },
29
+ "type": "module",
29
30
  "exports": {
30
31
  ".": {
31
- "require": "./index.js",
32
- "import": "./index.mjs"
33
- },
34
- "./*": {
35
- "require": "./*.js",
36
- "import": "./*.mjs"
32
+ "require": {
33
+ "types": "./typings/index.d.cts",
34
+ "default": "./cjs/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./typings/index.d.ts",
38
+ "default": "./esm/index.js"
39
+ },
40
+ "default": {
41
+ "types": "./typings/index.d.ts",
42
+ "default": "./esm/index.js"
43
+ }
37
44
  },
38
45
  "./package.json": "./package.json"
39
46
  }
40
- }
47
+ }
@@ -0,0 +1,11 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
+ export default class BarePrefix implements MeshTransform {
4
+ noWrap: boolean;
5
+ private ignoreList;
6
+ private includeRootOperations;
7
+ private includeTypes;
8
+ private prefix;
9
+ constructor(options: MeshTransformOptions<YamlConfig.PrefixTransformConfig>);
10
+ transformSchema(schema: GraphQLSchema): GraphQLSchema;
11
+ }
@@ -1,5 +1,5 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
- import { MeshTransform, YamlConfig, MeshTransformOptions } from '@graphql-mesh/types';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
3
  export default class BarePrefix implements MeshTransform {
4
4
  noWrap: boolean;
5
5
  private ignoreList;
@@ -0,0 +1,8 @@
1
+ import { MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
2
+ import BarePrefix from './barePrefix.cjs';
3
+ import WrapPrefix from './wrapPrefix.cjs';
4
+ interface PrefixTransformConstructor {
5
+ new (options: MeshTransformOptions<YamlConfig.Transform['prefix']>): BarePrefix | WrapPrefix;
6
+ }
7
+ declare const _default: PrefixTransformConstructor;
8
+ export default _default;
@@ -1,6 +1,6 @@
1
- import { YamlConfig, MeshTransformOptions } from '@graphql-mesh/types';
2
- import WrapPrefix from './wrapPrefix';
3
- import BarePrefix from './barePrefix';
1
+ import { MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
2
+ import BarePrefix from './barePrefix.js';
3
+ import WrapPrefix from './wrapPrefix.js';
4
4
  interface PrefixTransformConstructor {
5
5
  new (options: MeshTransformOptions<YamlConfig.Transform['prefix']>): BarePrefix | WrapPrefix;
6
6
  }
@@ -0,0 +1 @@
1
+ export declare const ignoreList: string[];
@@ -0,0 +1 @@
1
+ export declare const ignoreList: string[];
@@ -0,0 +1,11 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
+ import { DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
4
+ import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
5
+ export default class WrapPrefix implements MeshTransform {
6
+ private transforms;
7
+ constructor(options: MeshTransformOptions<YamlConfig.PrefixTransformConfig>);
8
+ transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig, transformedSchema?: GraphQLSchema): GraphQLSchema;
9
+ transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<any, any, any, Record<string, any>, any>;
10
+ transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<any, any>;
11
+ }
@@ -1,11 +1,11 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
- import { MeshTransform, YamlConfig, MeshTransformOptions } from '@graphql-mesh/types';
3
- import { ExecutionResult, ExecutionRequest } from '@graphql-tools/utils';
4
- import { SubschemaConfig, DelegationContext } from '@graphql-tools/delegate';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
+ import { DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
4
+ import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
5
5
  export default class WrapPrefix implements MeshTransform {
6
6
  private transforms;
7
7
  constructor(options: MeshTransformOptions<YamlConfig.PrefixTransformConfig>);
8
8
  transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig, transformedSchema?: GraphQLSchema): GraphQLSchema;
9
- transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<Record<string, any>, any, any, Record<string, any>>;
10
- transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<Record<string, any>>;
9
+ transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<any, any, any, Record<string, any>, any>;
10
+ transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<any, any>;
11
11
  }
package/index.js DELETED
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- const wrap = require('@graphql-tools/wrap');
4
- const utils = require('@graphql-mesh/utils');
5
- const graphqlScalars = require('graphql-scalars');
6
- const graphql = require('graphql');
7
- const utils$1 = require('@graphql-tools/utils');
8
-
9
- class WrapPrefix {
10
- constructor(options) {
11
- this.transforms = [];
12
- const { apiName, config } = options;
13
- let prefix = null;
14
- if (config.value) {
15
- prefix = config.value;
16
- }
17
- else if (apiName) {
18
- prefix = `${apiName}_`;
19
- }
20
- if (!prefix) {
21
- throw new Error(`Transform 'prefix' has missing config: prefix`);
22
- }
23
- const ignoreList = [
24
- ...(config.ignore || []),
25
- 'date',
26
- 'hostname',
27
- 'regex',
28
- 'json-pointer',
29
- 'relative-json-pointer',
30
- 'uri-reference',
31
- 'uri-template',
32
- ...Object.keys(graphqlScalars.resolvers),
33
- ];
34
- const includeTypes = config.includeTypes !== false;
35
- if (includeTypes) {
36
- this.transforms.push(new wrap.RenameTypes(typeName => (ignoreList.includes(typeName) ? typeName : `${prefix}${typeName}`)));
37
- }
38
- const includeRootOperations = config.includeRootOperations === true;
39
- if (includeRootOperations) {
40
- this.transforms.push(new wrap.RenameRootFields((typeName, fieldName) => ignoreList.includes(typeName) || ignoreList.includes(`${typeName}.${fieldName}`)
41
- ? fieldName
42
- : `${prefix}${fieldName}`));
43
- }
44
- }
45
- transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
46
- return utils.applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
47
- }
48
- transformRequest(originalRequest, delegationContext, transformationContext) {
49
- return utils.applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
50
- }
51
- transformResult(originalResult, delegationContext, transformationContext) {
52
- return utils.applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
53
- }
54
- }
55
-
56
- const rootOperations = new Set(['Query', 'Mutation', 'Subscription']);
57
- class BarePrefix {
58
- constructor(options) {
59
- this.noWrap = true;
60
- const { apiName, config } = options;
61
- this.ignoreList = config.ignore || [];
62
- this.includeRootOperations = config.includeRootOperations === true;
63
- this.includeTypes = config.includeTypes !== false;
64
- this.prefix = null;
65
- if (config.value) {
66
- this.prefix = config.value;
67
- }
68
- else if (apiName) {
69
- this.prefix = `${apiName}_`;
70
- }
71
- if (!this.prefix) {
72
- throw new Error(`Transform 'prefix' has missing config: prefix`);
73
- }
74
- }
75
- transformSchema(schema) {
76
- return utils$1.mapSchema(schema, {
77
- [utils$1.MapperKind.TYPE]: (type) => {
78
- if (this.includeTypes && !graphql.isSpecifiedScalarType(type)) {
79
- const currentName = type.name;
80
- if (!this.ignoreList.includes(currentName)) {
81
- return utils$1.renameType(type, this.prefix + currentName);
82
- }
83
- }
84
- return undefined;
85
- },
86
- [utils$1.MapperKind.ROOT_OBJECT]() {
87
- return undefined;
88
- },
89
- ...(this.includeRootOperations && {
90
- [utils$1.MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
91
- return !rootOperations.has(typeName) || // check we're in a root Type
92
- this.ignoreList.includes(typeName) || // check if type is to be ignored
93
- this.ignoreList.includes(`${typeName}.${fieldName}`) // check if field in type is to be ignored
94
- ? undefined // do not perform any change
95
- : [`${this.prefix}${fieldName}`, fieldConfig]; // apply prefix
96
- },
97
- }),
98
- });
99
- }
100
- }
101
-
102
- const PrefixTransform = (function PrefixTransform(options) {
103
- return options.config.mode === 'bare' ? new BarePrefix(options) : new WrapPrefix(options);
104
- });
105
-
106
- module.exports = PrefixTransform;
package/index.mjs DELETED
@@ -1,104 +0,0 @@
1
- import { RenameTypes, RenameRootFields } from '@graphql-tools/wrap';
2
- import { applySchemaTransforms, applyRequestTransforms, applyResultTransforms } from '@graphql-mesh/utils';
3
- import { resolvers } from 'graphql-scalars';
4
- import { isSpecifiedScalarType } from 'graphql';
5
- import { mapSchema, MapperKind, renameType } from '@graphql-tools/utils';
6
-
7
- class WrapPrefix {
8
- constructor(options) {
9
- this.transforms = [];
10
- const { apiName, config } = options;
11
- let prefix = null;
12
- if (config.value) {
13
- prefix = config.value;
14
- }
15
- else if (apiName) {
16
- prefix = `${apiName}_`;
17
- }
18
- if (!prefix) {
19
- throw new Error(`Transform 'prefix' has missing config: prefix`);
20
- }
21
- const ignoreList = [
22
- ...(config.ignore || []),
23
- 'date',
24
- 'hostname',
25
- 'regex',
26
- 'json-pointer',
27
- 'relative-json-pointer',
28
- 'uri-reference',
29
- 'uri-template',
30
- ...Object.keys(resolvers),
31
- ];
32
- const includeTypes = config.includeTypes !== false;
33
- if (includeTypes) {
34
- this.transforms.push(new RenameTypes(typeName => (ignoreList.includes(typeName) ? typeName : `${prefix}${typeName}`)));
35
- }
36
- const includeRootOperations = config.includeRootOperations === true;
37
- if (includeRootOperations) {
38
- this.transforms.push(new RenameRootFields((typeName, fieldName) => ignoreList.includes(typeName) || ignoreList.includes(`${typeName}.${fieldName}`)
39
- ? fieldName
40
- : `${prefix}${fieldName}`));
41
- }
42
- }
43
- transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
44
- return applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
45
- }
46
- transformRequest(originalRequest, delegationContext, transformationContext) {
47
- return applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
48
- }
49
- transformResult(originalResult, delegationContext, transformationContext) {
50
- return applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
51
- }
52
- }
53
-
54
- const rootOperations = new Set(['Query', 'Mutation', 'Subscription']);
55
- class BarePrefix {
56
- constructor(options) {
57
- this.noWrap = true;
58
- const { apiName, config } = options;
59
- this.ignoreList = config.ignore || [];
60
- this.includeRootOperations = config.includeRootOperations === true;
61
- this.includeTypes = config.includeTypes !== false;
62
- this.prefix = null;
63
- if (config.value) {
64
- this.prefix = config.value;
65
- }
66
- else if (apiName) {
67
- this.prefix = `${apiName}_`;
68
- }
69
- if (!this.prefix) {
70
- throw new Error(`Transform 'prefix' has missing config: prefix`);
71
- }
72
- }
73
- transformSchema(schema) {
74
- return mapSchema(schema, {
75
- [MapperKind.TYPE]: (type) => {
76
- if (this.includeTypes && !isSpecifiedScalarType(type)) {
77
- const currentName = type.name;
78
- if (!this.ignoreList.includes(currentName)) {
79
- return renameType(type, this.prefix + currentName);
80
- }
81
- }
82
- return undefined;
83
- },
84
- [MapperKind.ROOT_OBJECT]() {
85
- return undefined;
86
- },
87
- ...(this.includeRootOperations && {
88
- [MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
89
- return !rootOperations.has(typeName) || // check we're in a root Type
90
- this.ignoreList.includes(typeName) || // check if type is to be ignored
91
- this.ignoreList.includes(`${typeName}.${fieldName}`) // check if field in type is to be ignored
92
- ? undefined // do not perform any change
93
- : [`${this.prefix}${fieldName}`, fieldConfig]; // apply prefix
94
- },
95
- }),
96
- });
97
- }
98
- }
99
-
100
- const PrefixTransform = (function PrefixTransform(options) {
101
- return options.config.mode === 'bare' ? new BarePrefix(options) : new WrapPrefix(options);
102
- });
103
-
104
- export default PrefixTransform;