@eddeee888/gcg-typescript-resolver-files 0.0.7 → 0.1.1

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.
Files changed (102) hide show
  1. package/README.md +70 -14
  2. package/package.json +7 -5
  3. package/src/{run → generateResolverFiles}/addExternalResolverImport.d.ts +2 -2
  4. package/src/{run → generateResolverFiles}/addExternalResolverImport.js +0 -0
  5. package/src/generateResolverFiles/addExternalResolverImport.js.map +1 -0
  6. package/src/generateResolverFiles/addResolverMainFile.d.ts +2 -0
  7. package/src/{run/addResolversMainFile.js → generateResolverFiles/addResolverMainFile.js} +5 -5
  8. package/src/generateResolverFiles/addResolverMainFile.js.map +1 -0
  9. package/src/generateResolverFiles/fixExistingResolvers.d.ts +2 -0
  10. package/src/{run → generateResolverFiles}/fixExistingResolvers.js +2 -5
  11. package/src/generateResolverFiles/fixExistingResolvers.js.map +1 -0
  12. package/src/generateResolverFiles/generateResolverFiles.d.ts +2 -0
  13. package/src/{run/run.js → generateResolverFiles/generateResolverFiles.js} +10 -15
  14. package/src/generateResolverFiles/generateResolverFiles.js.map +1 -0
  15. package/src/{run → generateResolverFiles}/handleGraphQLObjectType.d.ts +1 -1
  16. package/src/{run → generateResolverFiles}/handleGraphQLObjectType.js +0 -0
  17. package/src/generateResolverFiles/handleGraphQLObjectType.js.map +1 -0
  18. package/src/{run → generateResolverFiles}/handleGraphQLRootObjectTypeField.d.ts +1 -1
  19. package/src/{run → generateResolverFiles}/handleGraphQLRootObjectTypeField.js +0 -0
  20. package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js.map +1 -0
  21. package/src/{run → generateResolverFiles}/handleGraphQLScalarType.d.ts +1 -1
  22. package/src/{run → generateResolverFiles}/handleGraphQLScalarType.js +0 -0
  23. package/src/generateResolverFiles/handleGraphQLScalarType.js.map +1 -0
  24. package/src/{run → generateResolverFiles}/handleGraphQLUninionType.d.ts +1 -1
  25. package/src/{run → generateResolverFiles}/handleGraphQLUninionType.js +0 -0
  26. package/src/generateResolverFiles/handleGraphQLUninionType.js.map +1 -0
  27. package/src/generateResolverFiles/index.d.ts +2 -0
  28. package/src/generateResolverFiles/index.js +8 -0
  29. package/src/generateResolverFiles/index.js.map +1 -0
  30. package/src/{types.d.ts → generateResolverFiles/types.d.ts} +7 -20
  31. package/src/{types.js → generateResolverFiles/types.js} +0 -0
  32. package/src/generateResolverFiles/types.js.map +1 -0
  33. package/src/{run → generateResolverFiles}/visitNamedType.d.ts +3 -2
  34. package/src/{run → generateResolverFiles}/visitNamedType.js +7 -15
  35. package/src/generateResolverFiles/visitNamedType.js.map +1 -0
  36. package/src/getPluginsConfig/getPluginsConfig.d.ts +13 -0
  37. package/src/getPluginsConfig/getPluginsConfig.js +52 -0
  38. package/src/getPluginsConfig/getPluginsConfig.js.map +1 -0
  39. package/src/getPluginsConfig/index.d.ts +1 -0
  40. package/src/getPluginsConfig/index.js +5 -0
  41. package/src/getPluginsConfig/index.js.map +1 -0
  42. package/src/parseSources/index.d.ts +1 -0
  43. package/src/parseSources/index.js +5 -0
  44. package/src/parseSources/index.js.map +1 -0
  45. package/src/parseSources/parseSources.d.ts +13 -0
  46. package/src/parseSources/parseSources.js +23 -0
  47. package/src/parseSources/parseSources.js.map +1 -0
  48. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.d.ts +7 -0
  49. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js +72 -0
  50. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js.map +1 -0
  51. package/src/parseTypeMappers/index.d.ts +1 -0
  52. package/src/parseTypeMappers/index.js +5 -0
  53. package/src/parseTypeMappers/index.js.map +1 -0
  54. package/src/parseTypeMappers/parseTypeMappers.d.ts +14 -0
  55. package/src/parseTypeMappers/parseTypeMappers.js +22 -0
  56. package/src/parseTypeMappers/parseTypeMappers.js.map +1 -0
  57. package/src/preset.d.ts +2 -27
  58. package/src/preset.js +30 -79
  59. package/src/preset.js.map +1 -1
  60. package/src/utils/index.d.ts +6 -0
  61. package/src/utils/index.js +24 -0
  62. package/src/utils/index.js.map +1 -0
  63. package/src/utils/isNativeNamedType.d.ts +2 -0
  64. package/src/utils/isNativeNamedType.js +18 -0
  65. package/src/utils/isNativeNamedType.js.map +1 -0
  66. package/src/utils/isRootObjectType.d.ts +2 -0
  67. package/src/utils/isRootObjectType.js +8 -0
  68. package/src/utils/isRootObjectType.js.map +1 -0
  69. package/src/utils/parseLocationForWhitelistedModule.d.ts +9 -0
  70. package/src/utils/parseLocationForWhitelistedModule.js +24 -0
  71. package/src/utils/parseLocationForWhitelistedModule.js.map +1 -0
  72. package/src/utils/printImportLine.d.ts +10 -0
  73. package/src/utils/printImportLine.js +29 -0
  74. package/src/utils/printImportLine.js.map +1 -0
  75. package/src/validatePresetConfig/index.d.ts +1 -0
  76. package/src/validatePresetConfig/index.js +5 -0
  77. package/src/validatePresetConfig/index.js.map +1 -0
  78. package/src/validatePresetConfig/validatePresetConfig.d.ts +33 -0
  79. package/src/validatePresetConfig/validatePresetConfig.js +69 -0
  80. package/src/validatePresetConfig/validatePresetConfig.js.map +1 -0
  81. package/src/run/addExternalResolverImport.js.map +0 -1
  82. package/src/run/addResolversMainFile.d.ts +0 -2
  83. package/src/run/addResolversMainFile.js.map +0 -1
  84. package/src/run/checkIfModuleIsWhitelisted.d.ts +0 -7
  85. package/src/run/checkIfModuleIsWhitelisted.js +0 -16
  86. package/src/run/checkIfModuleIsWhitelisted.js.map +0 -1
  87. package/src/run/fixExistingResolvers.d.ts +0 -2
  88. package/src/run/fixExistingResolvers.js.map +0 -1
  89. package/src/run/handleGraphQLObjectType.js.map +0 -1
  90. package/src/run/handleGraphQLRootObjectTypeField.js.map +0 -1
  91. package/src/run/handleGraphQLScalarType.js.map +0 -1
  92. package/src/run/handleGraphQLUninionType.js.map +0 -1
  93. package/src/run/index.d.ts +0 -1
  94. package/src/run/index.js +0 -6
  95. package/src/run/index.js.map +0 -1
  96. package/src/run/run.d.ts +0 -2
  97. package/src/run/run.js.map +0 -1
  98. package/src/run/visitNamedType.js.map +0 -1
  99. package/src/types.js.map +0 -1
  100. package/src/utils.d.ts +0 -7
  101. package/src/utils.js +0 -64
  102. package/src/utils.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./parseSources"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseSources/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import * as path from 'path';
3
+ import type { Source } from '@graphql-tools/utils';
4
+ export interface ParsedSource {
5
+ source: Source;
6
+ sourcePath: path.ParsedPath;
7
+ moduleName: string;
8
+ }
9
+ export interface ParseSourcesResult {
10
+ sourceMap: Record<string, ParsedSource>;
11
+ mergedSDL: string;
12
+ }
13
+ export declare function parseSources(sources: Source[]): ParseSourcesResult;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSources = void 0;
4
+ const path = require("path");
5
+ function parseSources(sources) {
6
+ return sources.reduce((result, source) => {
7
+ if (!source.location) {
8
+ throw new Error('Missing source location');
9
+ }
10
+ const sourcePath = path.parse(source.location);
11
+ const moduleDir = sourcePath.dir;
12
+ const [moduleName] = moduleDir.split(path.sep).slice(-1);
13
+ result.sourceMap[source.location] = {
14
+ source,
15
+ sourcePath,
16
+ moduleName,
17
+ };
18
+ result.mergedSDL += `\n${source.rawSDL}`;
19
+ return result;
20
+ }, { sourceMap: {}, mergedSDL: '' });
21
+ }
22
+ exports.parseSources = parseSources;
23
+ //# sourceMappingURL=parseSources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSources.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseSources/parseSources.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAc7B,SAAgB,YAAY,CAAC,OAAiB;IAC5C,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC;QAEjC,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAEzD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;YAClC,MAAM;YACN,UAAU;YACV,UAAU;SACX,CAAC;QAEF,MAAM,CAAC,SAAS,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QAEzC,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CACjC,CAAC;AACJ,CAAC;AAxBD,oCAwBC"}
@@ -0,0 +1,7 @@
1
+ import type { SourceFile } from 'ts-morph';
2
+ import type { TypeMappersMap } from './parseTypeMappers';
3
+ export declare const collectTypeMappersFromSourceFile: ({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath, }: {
4
+ typeMappersSourceFile: SourceFile;
5
+ typeMappersSuffix: string;
6
+ resolverTypesPath: string;
7
+ }, result: TypeMappersMap) => void;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectTypeMappersFromSourceFile = void 0;
4
+ const path = require("path");
5
+ const utils_1 = require("../utils");
6
+ const collectTypeMappersFromSourceFile = ({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath, }, result) => {
7
+ // Look for interfaces with exported keywords
8
+ typeMappersSourceFile.getInterfaces().forEach((interfaceDeclaration) => {
9
+ if (!interfaceDeclaration.hasExportKeyword()) {
10
+ return;
11
+ }
12
+ addTypeMapperDetailsIfValid({
13
+ identifierName: interfaceDeclaration.getName(),
14
+ typeMappersSuffix,
15
+ typeMappersFilePath: typeMappersSourceFile.getFilePath(),
16
+ resolverTypesPath,
17
+ }, result);
18
+ });
19
+ // Look for exported types with exported keywords
20
+ typeMappersSourceFile.getTypeAliases().forEach((typeAlias) => {
21
+ if (!typeAlias.hasExportKeyword()) {
22
+ return;
23
+ }
24
+ addTypeMapperDetailsIfValid({
25
+ identifierName: typeAlias.getName(),
26
+ typeMappersSuffix,
27
+ typeMappersFilePath: typeMappersSourceFile.getFilePath(),
28
+ resolverTypesPath,
29
+ }, result);
30
+ });
31
+ // Look for named exports e.g.
32
+ // - export { something } from 'module';
33
+ // - export type { something } from 'module';
34
+ // - export { something, somethingelse }'
35
+ typeMappersSourceFile.getExportDeclarations().forEach((exportDeclaration) => {
36
+ exportDeclaration.getNamedExports().forEach((namedExport) => {
37
+ let identifierName = namedExport.getFullText();
38
+ const aliasNode = namedExport.getAliasNode();
39
+ if (aliasNode) {
40
+ identifierName = aliasNode.getFullText();
41
+ }
42
+ addTypeMapperDetailsIfValid({
43
+ identifierName: identifierName.trim(),
44
+ typeMappersSuffix,
45
+ typeMappersFilePath: typeMappersSourceFile.getFilePath(),
46
+ resolverTypesPath,
47
+ }, result);
48
+ });
49
+ });
50
+ };
51
+ exports.collectTypeMappersFromSourceFile = collectTypeMappersFromSourceFile;
52
+ const addTypeMapperDetailsIfValid = ({ identifierName, typeMappersSuffix, typeMappersFilePath, resolverTypesPath, }, result) => {
53
+ if (!identifierName.endsWith(typeMappersSuffix)) {
54
+ return;
55
+ }
56
+ const [schemaType] = identifierName.split(typeMappersSuffix);
57
+ if (!schemaType) {
58
+ return;
59
+ }
60
+ const parsedRelativePathFromResolverTypesToSourceFile = path.parse(path.relative(path.dirname(resolverTypesPath), typeMappersFilePath));
61
+ const relativeImportPathFromResolverTypesToSourceFile = (0, utils_1.normalizeRelativePath)(path.join(parsedRelativePathFromResolverTypesToSourceFile.dir, parsedRelativePathFromResolverTypesToSourceFile.name));
62
+ const configImportPath = `${relativeImportPathFromResolverTypesToSourceFile}#${identifierName}`;
63
+ if (result[schemaType]) {
64
+ throw new Error(`GraphQL type "${schemaType}" has duplicated "${identifierName}" mappers:\n - ${configImportPath}\n - ${result[schemaType].configImportPath}`);
65
+ }
66
+ result[schemaType] = {
67
+ schemaType,
68
+ typeMapperName: identifierName,
69
+ configImportPath,
70
+ };
71
+ };
72
+ //# sourceMappingURL=collectTypeMappersFromSourceFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectTypeMappersFromSourceFile.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/collectTypeMappersFromSourceFile.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,oCAAiD;AAG1C,MAAM,gCAAgC,GAAG,CAC9C,EACE,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,GAKlB,EACD,MAAsB,EAChB,EAAE;IACR,6CAA6C;IAC7C,qBAAqB,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,CAAC,oBAAoB,EAAE,EAAE;QACrE,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,EAAE;YAC5C,OAAO;SACR;QAED,2BAA2B,CACzB;YACE,cAAc,EAAE,oBAAoB,CAAC,OAAO,EAAE;YAC9C,iBAAiB;YACjB,mBAAmB,EAAE,qBAAqB,CAAC,WAAW,EAAE;YACxD,iBAAiB;SAClB,EACD,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,iDAAiD;IACjD,qBAAqB,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC3D,IAAI,CAA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R;IAED,MAAM,+CAA+C,GAAG,IAAI,CAAC,KAAK,CAChE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,mBAAmB,CAAC,CACpE,CAAC;IACF,MAAM,+CAA+C,GAAG,IAAA,6BAAqB,EAC3E,IAAI,CAAC,IAAI,CACP,+CAA+C,CAAC,GAAG,EACnD,+CAA+C,CAAC,IAAI,CACrD,CACF,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAG,+CAA+C,IAAI,cAAc,EAAE,CAAC;IAEhG,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CACb,iBAAiB,UAAU,qBAAqB,cAAc,mBAAmB,gBAAgB,SAAS,MAAM,CAAC,UAAU,CAAC,CAAC,gBAAgB,EAAE,CAChJ,CAAC;KACH;IAED,MAAM,CAAC,UAAU,CAAC,GAAG;QACnB,UAAU;QACV,cAAc,EAAE,cAAc;QAC9B,gBAAgB;KACjB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './parseTypeMappers';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./parseTypeMappers"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC"}
@@ -0,0 +1,14 @@
1
+ import type { ParseSourcesResult } from '../parseSources';
2
+ export interface ParseTypeMappersParams {
3
+ sourceMap: ParseSourcesResult['sourceMap'];
4
+ resolverTypesPath: string;
5
+ typeMappersFileExtension: string;
6
+ typeMappersSuffix: string;
7
+ }
8
+ export interface TypeMapperDetails {
9
+ schemaType: string;
10
+ typeMapperName: string;
11
+ configImportPath: string;
12
+ }
13
+ export declare type TypeMappersMap = Record<string, TypeMapperDetails>;
14
+ export declare const parseTypeMappers: ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, }: ParseTypeMappersParams) => TypeMappersMap;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTypeMappers = void 0;
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const ts_morph_1 = require("ts-morph");
7
+ const collectTypeMappersFromSourceFile_1 = require("./collectTypeMappersFromSourceFile");
8
+ const parseTypeMappers = ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, }) => {
9
+ const result = Object.entries(sourceMap).reduce((res, [_, { sourcePath }]) => {
10
+ const typeMapperFilePath = path.join(sourcePath.dir, `${sourcePath.name}${typeMappersFileExtension}`);
11
+ if (!fs.existsSync(typeMapperFilePath)) {
12
+ return res;
13
+ }
14
+ const project = new ts_morph_1.Project();
15
+ const [typeMappersSourceFile] = project.addSourceFilesAtPaths(typeMapperFilePath);
16
+ (0, collectTypeMappersFromSourceFile_1.collectTypeMappersFromSourceFile)({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath }, res);
17
+ return res;
18
+ }, {});
19
+ return result;
20
+ };
21
+ exports.parseTypeMappers = parseTypeMappers;
22
+ //# sourceMappingURL=parseTypeMappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseTypeMappers.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/parseTypeMappers.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,yBAAyB;AACzB,uCAAmC;AAEnC,yFAAsF;AAiB/E,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GACM,EAAkB,EAAE;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC7C,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE;QAC3B,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAClC,UAAU,CAAC,GAAG,EACd,GAAG,UAAU,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAChD,CAAC;QAEF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;YACtC,OAAO,GAAG,CAAC;SACZ;QAED,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAC;QAC9B,MAAM,CAAC,qBAAqB,CAAC,GAC3B,OAAO,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;QAEpD,IAAA,mEAAgC,EAC9B,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,EAC/D,GAAG,CACJ,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA/BW,QAAA,gBAAgB,oBA+B3B"}
package/src/preset.d.ts CHANGED
@@ -1,28 +1,3 @@
1
- import * as typeScriptPlugin from '@graphql-codegen/typescript';
2
- import * as typeScriptResolversPlugin from '@graphql-codegen/typescript-resolvers';
3
1
  import type { Types } from '@graphql-codegen/plugin-helpers';
4
- declare type ParsedTypesPluginsConfig = Omit<typeScriptPlugin.TypeScriptPluginConfig, 'scalars'> & Omit<typeScriptResolversPlugin.TypeScriptResolversPluginConfig, 'scalars'> & {
5
- scalars: Record<string, string>;
6
- };
7
- interface ParsedPresetConfig {
8
- resolverTypesPath: string;
9
- relativeTargetDir: string;
10
- mainFile: string;
11
- mode: 'merged' | 'modules';
12
- whitelistedModules: string[];
13
- blacklistedModules: string[];
14
- externalResolvers: Record<string, string>;
15
- typesPluginsConfig: ParsedTypesPluginsConfig;
16
- }
17
- export declare const preset: Types.OutputPreset<ParsedPresetConfig>;
18
- export interface TypeScriptResolverFilesPresetConfig {
19
- resolverTypesPath?: string;
20
- relativeTargetDir?: string;
21
- mainFile?: string;
22
- mode?: string;
23
- whitelistedModules?: string[];
24
- blacklistedModules?: string[];
25
- externalResolvers?: Record<string, string>;
26
- typesPluginsConfig?: typeScriptPlugin.TypeScriptPluginConfig & typeScriptResolversPlugin.TypeScriptResolversPluginConfig;
27
- }
28
- export {};
2
+ import { RawPresetConfig } from './validatePresetConfig';
3
+ export declare const preset: Types.OutputPreset<RawPresetConfig>;
package/src/preset.js CHANGED
@@ -5,11 +5,11 @@ const path = require("path");
5
5
  const addPlugin = require("@graphql-codegen/add");
6
6
  const typeScriptPlugin = require("@graphql-codegen/typescript");
7
7
  const typeScriptResolversPlugin = require("@graphql-codegen/typescript-resolvers");
8
- const graphql_scalars_1 = require("graphql-scalars");
9
- const utils_1 = require("./utils");
10
- const run_1 = require("./run");
11
- const graphql_1 = require("graphql");
12
- const presetName = '@eddeee888/gcg-typescript-resolver-files';
8
+ const parseSources_1 = require("./parseSources");
9
+ const getPluginsConfig_1 = require("./getPluginsConfig");
10
+ const generateResolverFiles_1 = require("./generateResolverFiles");
11
+ const parseTypeMappers_1 = require("./parseTypeMappers");
12
+ const validatePresetConfig_1 = require("./validatePresetConfig");
13
13
  exports.preset = {
14
14
  buildGeneratesSection: ({ schema, schemaAst, presetConfig: rawPresetConfig, baseOutputDir, }) => {
15
15
  if (!schemaAst) {
@@ -19,49 +19,47 @@ exports.preset = {
19
19
  if (!Array.isArray(sources) || sources.length === 0) {
20
20
  throw new Error('Empty Sources. Make sure schema files are parsed correctly.');
21
21
  }
22
- const sourcesMap = (0, utils_1.parseSources)(sources);
23
- const { resolverTypesPath: relativeResolverTypesPathFromBaseOutputDir, relativeTargetDir, mainFile, mode, whitelistedModules, blacklistedModules, externalResolvers, typesPluginsConfig, } = validatePresetConfig(rawPresetConfig);
24
- // typescript and typescript-resolvers
25
- const { defaultScalarTypesMap, defaultScalarExternalResolvers } = Object.entries(schemaAst.getTypeMap()).reduce((res, [schemaType, namedType]) => {
26
- if (!(0, graphql_1.isScalarType)(namedType)) {
27
- return res;
28
- }
29
- const scalarResolver = graphql_scalars_1.resolvers[schemaType];
30
- if (!scalarResolver) {
31
- return res;
32
- }
33
- if (scalarResolver.extensions.codegenScalarType &&
34
- typeof scalarResolver.extensions.codegenScalarType === 'string') {
35
- res.defaultScalarTypesMap[schemaType] =
36
- scalarResolver.extensions.codegenScalarType;
37
- }
38
- res.defaultScalarExternalResolvers[schemaType] = `~graphql-scalars#${scalarResolver.name}Resolver`;
39
- return res;
40
- }, { defaultScalarTypesMap: {}, defaultScalarExternalResolvers: {} });
22
+ const { resolverTypesPath: relativeResolverTypesPathFromBaseOutputDir, resolverRelativeTargetDir, mappersFileExtension: typeMappersFileExtension, mappersSuffix: typeMappersSuffix, resolverMainFile, mode, whitelistedModules, blacklistedModules, externalResolvers, typesPluginsConfig, } = (0, validatePresetConfig_1.validatePresetConfig)(rawPresetConfig);
23
+ const resolverTypesPath = path.join(baseOutputDir, relativeResolverTypesPathFromBaseOutputDir);
24
+ const { sourceMap } = (0, parseSources_1.parseSources)(sources);
25
+ const typeMappersMap = (0, parseTypeMappers_1.parseTypeMappers)({
26
+ sourceMap,
27
+ resolverTypesPath,
28
+ typeMappersFileExtension,
29
+ typeMappersSuffix,
30
+ });
31
+ // typescript and typescript-resolvers plugins config
32
+ const { defaultScalarTypesMap, defaultScalarExternalResolvers, defaultTypeMappers, } = (0, getPluginsConfig_1.getPluginsConfig)({
33
+ schemaAst,
34
+ sourceMap,
35
+ typeMappersMap,
36
+ whitelistedModules,
37
+ blacklistedModules,
38
+ });
41
39
  const resolverTypesFile = {
42
- filename: path.join(baseOutputDir, relativeResolverTypesPathFromBaseOutputDir),
40
+ filename: resolverTypesPath,
43
41
  pluginMap: {
44
42
  typescript: typeScriptPlugin,
45
43
  'typescript-resolvers': typeScriptResolversPlugin,
46
44
  },
47
45
  plugins: [{ typescript: {} }, { ['typescript-resolvers']: {} }],
48
- config: Object.assign(Object.assign({ enumsAsTypes: true, nonOptionalTypename: true }, typesPluginsConfig), { scalars: Object.assign(Object.assign({}, defaultScalarTypesMap), typesPluginsConfig.scalars) }),
46
+ config: Object.assign(Object.assign({ enumsAsTypes: true, nonOptionalTypename: true }, typesPluginsConfig), { scalars: Object.assign(Object.assign({}, defaultScalarTypesMap), typesPluginsConfig.scalars), mappers: Object.assign(Object.assign({}, defaultTypeMappers), typesPluginsConfig.mappers) }),
49
47
  schema,
50
48
  documents: [],
51
49
  };
52
- // typescript-resolver-types
50
+ // resolver files
53
51
  const result = {
54
52
  files: {},
55
53
  externalImports: {},
56
54
  };
57
- (0, run_1.run)({
55
+ (0, generateResolverFiles_1.generateResolverFiles)({
58
56
  config: {
59
57
  schema: schemaAst,
60
- sourcesMap,
58
+ sourceMap,
61
59
  baseOutputDir,
62
- resolverTypesPath: path.join(baseOutputDir, relativeResolverTypesPathFromBaseOutputDir),
63
- relativeTargetDir,
64
- mainFile,
60
+ resolverTypesPath,
61
+ resolverRelativeTargetDir,
62
+ resolverMainFile,
65
63
  mode,
66
64
  whitelistedModules,
67
65
  blacklistedModules,
@@ -82,51 +80,4 @@ exports.preset = {
82
80
  return generatesSection;
83
81
  },
84
82
  };
85
- const validatePresetConfig = ({ resolverTypesPath, relativeTargetDir = '', mainFile = 'index.ts', mode = 'modules', whitelistedModules, blacklistedModules, externalResolvers = {}, typesPluginsConfig = {}, }) => {
86
- if (!resolverTypesPath) {
87
- throw new Error(`Validation Error - ${presetName} - presetConfig.resolverTypesPath is required`);
88
- }
89
- if (path.extname(mainFile) === '') {
90
- throw new Error(`Validation Error - ${presetName} - presetConfig.mainFile must be a valid file name`);
91
- }
92
- if (mode !== 'merged' && mode !== 'modules') {
93
- throw new Error(`Validation Error - ${presetName} - presetConfig.mode must be "merged" or "modules" (default is "modules")`);
94
- }
95
- if (whitelistedModules) {
96
- if (!Array.isArray(whitelistedModules)) {
97
- throw new Error(`Validation Error - ${presetName} - presetConfig.whitelistedModules must be an array if provided`);
98
- }
99
- if (mode !== 'modules') {
100
- throw new Error(`Validation Error - ${presetName} - presetConfig.whitelistedModules can only be used with presetConfig.mode == "modules"`);
101
- }
102
- }
103
- if (blacklistedModules) {
104
- if (!Array.isArray(blacklistedModules)) {
105
- throw new Error(`Validation Error - ${presetName} - presetConfig.blacklistedModules must be an array if provided`);
106
- }
107
- if (mode !== 'modules') {
108
- throw new Error(`Validation Error - ${presetName} - presetConfig.blacklistedModules can only be used with presetConfig.mode == "modules"`);
109
- }
110
- }
111
- if (!validateTypesPluginsConfig(typesPluginsConfig)) {
112
- throw new Error('Invalid typescriptPluginConfig. Should not see this.');
113
- }
114
- return {
115
- resolverTypesPath,
116
- relativeTargetDir,
117
- mainFile,
118
- mode: mode,
119
- whitelistedModules: whitelistedModules || [],
120
- blacklistedModules: blacklistedModules || [],
121
- externalResolvers,
122
- typesPluginsConfig,
123
- };
124
- };
125
- const validateTypesPluginsConfig = (config) => {
126
- config.scalars = config.scalars || {};
127
- if (typeof config.scalars === 'string') {
128
- throw new Error(`Validation Error - ${presetName} - presetConfig.typesPluginsConfig.scalars of type "string" is not supported`);
129
- }
130
- return true;
131
- };
132
83
  //# sourceMappingURL=preset.js.map
package/src/preset.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"preset.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/preset.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,kDAAkD;AAClD,gEAAgE;AAChE,mFAAmF;AACnF,qDAA+D;AAE/D,mCAAuC;AAEvC,+BAA4B;AAC5B,qCAAuC;AAqBvC,MAAM,UAAU,GAAG,0CAA0C,CAAC;AAEjD,QAAA,MAAM,GAA2C;IAC5D,qBAAqB,EAAE,CAAC,EACtB,MAAM,EACN,SAAS,EACT,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,EAAE,EAAE;QACH,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACtC;QACD,MAAM,OAAO,G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tB,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,yFAAyF,CAC1H,CAAC;SACH;KACF;IAED,IAAI,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,EAAE;QACnD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;KACzE;IAED,OAAO;QACL,iBAAiB;QACjB,iBAAiB;QACjB,QAAQ;QACR,IAAI,EAAE,IAAI;QACV,kBAAkB,EAAE,kBAAkB,IAAI,EAAE;QAC5C,kBAAkB,EAAE,kBAAkB,IAAI,EAAE;QAC5C,iBAAiB;QACjB,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CACjC,MAA8E,EAC1B,EAAE;IACtD,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;IACtC,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,8EAA8E,CAC/G,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
1
+ {"version":3,"file":"preset.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/preset.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,kDAAkD;AAClD,gEAAgE;AAChE,mFAAmF;AAEnF,iDAA8C;AAC9C,yDAAsD;AACtD,mEAGiC;AACjC,yDAAsD;AACtD,iEAA+E;AAElE,QAAA,MAAM,GAAwC;IACzD,qBAAqB,EAAE,CAAC,EACtB,MAAM,EACN,SAAS,EACT,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,EAAE,EAAE;QACH,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACtC;QACD,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC;QACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI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,IAEhC;YACD,MAAM;YACN,SAAS,EAAE,EAAE;SACd,CAAC;QAEF,iBAAiB;QACjB,MAAM,MAAM,GAA2C;YACrD,KAAK,EAAE,EAAE;YACT,eAAe,EAAE,EAAE;SACpB,CAAC;QACF,IAAA,6CAAqB,EAAC;YACpB,MAAM,EAAE;gBACN,MAAM,EAAE,SAAS;gBACjB,SAAS;gBACT,aAAa;gBACb,iBAAiB;gBACjB,yBAAyB;gBACzB,gBAAgB;gBAChB,IAAI;gBACJ,kBAAkB;gBAClB,kBAAkB;gBAClB,iBAAiB,kCACZ,8BAA8B,GAC9B,iBAAiB,CACrB;aACF;YACD,MAAM;SACP,CAAC,CAAC;QAEH,6BAA6B;QAC7B,MAAM,gBAAgB,GAA4B,MAAM,CAAC,OAAO,CAC9D,MAAM,CAAC,KAAK,CACb,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAClC,QAAQ;YACR,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE;YAC7B,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;YAC/B,MAAM,EAAE,EAAE;YACV,MAAM;YACN,SAAS,EAAE,EAAE;SACd,CAAC,CAAC,CAAC;QACJ,gBAAgB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACzC,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './parseLocationForWhitelistedModule';
2
+ export * from './isNativeNamedType';
3
+ export * from './isRootObjectType';
4
+ export * from './printImportLine';
5
+ export declare const relativeModulePath: (from: string, to: string) => string;
6
+ export declare const normalizeRelativePath: (path: string) => string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeRelativePath = exports.relativeModulePath = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path = require("path");
6
+ tslib_1.__exportStar(require("./parseLocationForWhitelistedModule"), exports);
7
+ tslib_1.__exportStar(require("./isNativeNamedType"), exports);
8
+ tslib_1.__exportStar(require("./isRootObjectType"), exports);
9
+ tslib_1.__exportStar(require("./printImportLine"), exports);
10
+ // TODO: break the functions below this line into smaller files
11
+ // -----------
12
+ const relativeModulePath = (from, to) => {
13
+ const rawPath = path.relative(from, to);
14
+ return (0, exports.normalizeRelativePath)(rawPath);
15
+ };
16
+ exports.relativeModulePath = relativeModulePath;
17
+ const normalizeRelativePath = (path) => {
18
+ if (!path.startsWith('../') || !path.startsWith('./')) {
19
+ return `./${path}`;
20
+ }
21
+ return path;
22
+ };
23
+ exports.normalizeRelativePath = normalizeRelativePath;
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/index.ts"],"names":[],"mappings":";;;;AAAA,6BAA6B;AAE7B,8EAAoD;AACpD,8DAAoC;AACpC,6DAAmC;AACnC,4DAAkC;AAElC,+DAA+D;AAC/D,cAAc;AACP,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,EAAU,EAAU,EAAE;IACrE,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxC,OAAO,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAC;AACxC,CAAC,CAAC;AAHW,QAAA,kBAAkB,sBAG7B;AAEK,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAU,EAAE;IAC5D,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACrD,OAAO,KAAK,IAAI,EAAE,CAAC;KACpB;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC"}
@@ -0,0 +1,2 @@
1
+ import { GraphQLNamedType } from 'graphql';
2
+ export declare const isNativeNamedType: (namedType: GraphQLNamedType) => boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNativeNamedType = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const isNativeNamedType = (namedType) => {
6
+ // "Native" NamedType in this context means the following:
7
+ // 1. introspection types i.e. with `__` prefixes
8
+ // 2. base scalars e.g. Boolean, Int, etc.
9
+ // 3. Other natives (mostly base scalars) which was not defined in the schema i.e. no `astNode`
10
+ if ((0, graphql_1.isSpecifiedScalarType)(namedType) ||
11
+ (0, graphql_1.isIntrospectionType)(namedType) ||
12
+ !namedType.astNode) {
13
+ return true;
14
+ }
15
+ return false;
16
+ };
17
+ exports.isNativeNamedType = isNativeNamedType;
18
+ //# sourceMappingURL=isNativeNamedType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNativeNamedType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/isNativeNamedType.ts"],"names":[],"mappings":";;;AAAA,qCAIiB;AAEV,MAAM,iBAAiB,GAAG,CAAC,SAA2B,EAAW,EAAE;IACxE,0DAA0D;IAC1D,iDAAiD;IACjD,0CAA0C;IAC1C,+FAA+F;IAC/F,IACE,IAAA,+BAAqB,EAAC,SAAS,CAAC;QAChC,IAAA,6BAAmB,EAAC,SAAS,CAAC;QAC9B,CAAC,SAAS,CAAC,OAAO,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B"}
@@ -0,0 +1,2 @@
1
+ export declare type RootObjectType = 'Query' | 'Mutation' | 'Subscription';
2
+ export declare const isRootObjectType: (typeName: string) => typeName is RootObjectType;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRootObjectType = void 0;
4
+ const isRootObjectType = (typeName) => typeName === 'Query' ||
5
+ typeName === 'Mutation' ||
6
+ typeName === 'Subscription';
7
+ exports.isRootObjectType = isRootObjectType;
8
+ //# sourceMappingURL=isRootObjectType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isRootObjectType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/isRootObjectType.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAG,CAC9B,QAAgB,EACY,EAAE,CAC9B,QAAQ,KAAK,OAAO;IACpB,QAAQ,KAAK,UAAU;IACvB,QAAQ,KAAK,cAAc,CAAC;AALjB,QAAA,gBAAgB,oBAKC"}
@@ -0,0 +1,9 @@
1
+ import type { Location } from 'graphql';
2
+ import type { ParseSourcesResult, ParsedSource } from '../parseSources';
3
+ export interface ParseLocationForWhitelistedModule {
4
+ location: Location | undefined;
5
+ sourceMap: ParseSourcesResult['sourceMap'];
6
+ whitelistedModules: string[];
7
+ blacklistedModules: string[];
8
+ }
9
+ export declare const parseLocationForWhitelistedModule: ({ location, sourceMap, whitelistedModules, blacklistedModules, }: ParseLocationForWhitelistedModule) => ParsedSource | undefined;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLocationForWhitelistedModule = void 0;
4
+ const parseLocationForWhitelistedModule = ({ location, sourceMap, whitelistedModules, blacklistedModules, }) => {
5
+ if (!location) {
6
+ throw new Error('Location is invalid');
7
+ }
8
+ const sourceFilename = location.source.name;
9
+ const sourceFile = sourceMap[sourceFilename];
10
+ if (!sourceFile) {
11
+ throw new Error(`Unable to find ${sourceFilename} in sourceMap`);
12
+ }
13
+ if (blacklistedModules.includes(sourceFile.moduleName)) {
14
+ return;
15
+ }
16
+ const isInWhitelistedModule =
17
+ // whitelistedModules is empty a.k.a. all are whitelisted
18
+ whitelistedModules.length === 0
19
+ ? true
20
+ : whitelistedModules.includes(sourceFile.moduleName);
21
+ return isInWhitelistedModule ? sourceFile : undefined;
22
+ };
23
+ exports.parseLocationForWhitelistedModule = parseLocationForWhitelistedModule;
24
+ //# sourceMappingURL=parseLocationForWhitelistedModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseLocationForWhitelistedModule.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/parseLocationForWhitelistedModule.ts"],"names":[],"mappings":";;;AAUO,MAAM,iCAAiC,GAAG,CAAC,EAChD,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,kBAAkB,GACgB,EAA4B,EAAE;IAChE,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;KACxC;IAED,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;IAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IAC7C,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,cAAc,eAAe,CAAC,CAAC;KAClE;IAED,IAAI,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QACtD,OAAO;KACR;IAED,MAAM,qBAAqB;IACzB,yDAAyD;IACzD,kBAAkB,CAAC,MAAM,KAAK,CAAC;QAC7B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAEzD,OAAO,qBAAqB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC,CAAC;AA3BW,QAAA,iCAAiC,qCA2B5C"}
@@ -0,0 +1,10 @@
1
+ export interface ImportLineMeta {
2
+ isTypeImport: boolean;
3
+ module: string;
4
+ namedImports: (string | {
5
+ propertyName: string;
6
+ identifierName: string;
7
+ })[];
8
+ defaultImport?: string;
9
+ }
10
+ export declare function printImportLine({ isTypeImport, module, namedImports, defaultImport, }: ImportLineMeta): string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printImportLine = void 0;
4
+ function printImportLine({ isTypeImport, module, namedImports, defaultImport, }) {
5
+ const typeImportKeyword = isTypeImport ? 'type' : '';
6
+ const hasDefaultImport = Boolean(defaultImport);
7
+ const hasNamedImports = namedImports.length > 0;
8
+ const namedImportsString = hasNamedImports
9
+ ? `{ ${namedImports.map(printNamedImportSpecifier).join(',')} }`
10
+ : '';
11
+ return `import ${typeImportKeyword} ${defaultImport || ''} ${hasDefaultImport && hasNamedImports ? ',' : ''} ${namedImportsString} from '${normalizeModuleExtensionForImport(module)}';`;
12
+ }
13
+ exports.printImportLine = printImportLine;
14
+ const normalizeModuleExtensionForImport = (module) => {
15
+ if (module.endsWith('.ts')) {
16
+ return module.split('.').slice(0, -1).join('.');
17
+ }
18
+ return module;
19
+ };
20
+ const printNamedImportSpecifier = (namedImport) => {
21
+ if (typeof namedImport === 'string') {
22
+ return namedImport;
23
+ }
24
+ if (namedImport.propertyName === namedImport.identifierName) {
25
+ return namedImport.identifierName;
26
+ }
27
+ return `${namedImport.propertyName} as ${namedImport.identifierName}`;
28
+ };
29
+ //# sourceMappingURL=printImportLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printImportLine.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/printImportLine.ts"],"names":[],"mappings":";;;AAOA,SAAgB,eAAe,CAAC,EAC9B,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,aAAa,GACE;IACf,MAAM,iBAAiB,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,MAAM,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAChD,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAChD,MAAM,kBAAkB,GAAG,eAAe;QACxC,CAAC,CAAC,KAAK,YAAY,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI;QAChE,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,UAAU,iBAAiB,IAAI,aAAa,IAAI,EAAE,IACvD,gBAAgB,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAC9C,IAAI,kBAAkB,UAAU,iCAAiC,CAAC,MAAM,CAAC,IAAI,CAAC;AAChF,CAAC;AAhBD,0CAgBC;AAED,MAAM,iCAAiC,GAAG,CAAC,MAAc,EAAU,EAAE;IACnE,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACjD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAChC,WAAmD,EAC3C,EAAE;IACV,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,WAAW,CAAC,YAAY,KAAK,WAAW,CAAC,cAAc,EAAE;QAC3D,OAAO,WAAW,CAAC,cAAc,CAAC;KACnC;IAED,OAAO,GAAG,WAAW,CAAC,YAAY,OAAO,WAAW,CAAC,cAAc,EAAE,CAAC;AACxE,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './validatePresetConfig';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./validatePresetConfig"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/validatePresetConfig/index.ts"],"names":[],"mappings":";;;AAAA,iEAAuC"}
@@ -0,0 +1,33 @@
1
+ import * as typeScriptPlugin from '@graphql-codegen/typescript';
2
+ import * as typeScriptResolversPlugin from '@graphql-codegen/typescript-resolvers';
3
+ declare type ParsedTypesPluginsConfig = Omit<typeScriptPlugin.TypeScriptPluginConfig, 'scalars'> & Omit<typeScriptResolversPlugin.TypeScriptResolversPluginConfig, 'scalars'> & {
4
+ scalars: Record<string, string>;
5
+ };
6
+ interface ParsedPresetConfig {
7
+ resolverTypesPath: string;
8
+ resolverRelativeTargetDir: string;
9
+ resolverMainFile: string;
10
+ typeDefsFilePath: string | false;
11
+ mappersFileExtension: string;
12
+ mappersSuffix: string;
13
+ mode: 'merged' | 'modules';
14
+ whitelistedModules: string[];
15
+ blacklistedModules: string[];
16
+ externalResolvers: Record<string, string>;
17
+ typesPluginsConfig: ParsedTypesPluginsConfig;
18
+ }
19
+ export interface RawPresetConfig {
20
+ resolverTypesPath?: string;
21
+ resolverRelativeTargetDir?: string;
22
+ resolverMainFile?: string;
23
+ typeDefsFilePath?: string | boolean;
24
+ mappersFileExtension?: string;
25
+ mappersSuffix?: string;
26
+ mode?: string;
27
+ whitelistedModules?: string[];
28
+ blacklistedModules?: string[];
29
+ externalResolvers?: Record<string, string>;
30
+ typesPluginsConfig?: typeScriptPlugin.TypeScriptPluginConfig & typeScriptResolversPlugin.TypeScriptResolversPluginConfig;
31
+ }
32
+ export declare const validatePresetConfig: ({ resolverTypesPath, resolverRelativeTargetDir, resolverMainFile, typeDefsFilePath, mappersFileExtension, mappersSuffix, mode, whitelistedModules, blacklistedModules, externalResolvers, typesPluginsConfig, }: RawPresetConfig) => ParsedPresetConfig;
33
+ export {};