@graphql-codegen/graphql-modules-preset 2.5.2-alpha-20220926231710-4ae616388 → 2.5.3

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/builder.js CHANGED
@@ -6,7 +6,7 @@ const change_case_all_1 = require("change-case-all");
6
6
  const utils_js_1 = require("./utils.js");
7
7
  const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
8
8
  const resolverKeys = ['scalars', 'objects', 'enums'];
9
- function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }) {
9
+ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports = false, }) {
10
10
  const picks = (0, utils_js_1.createObject)(registryKeys, () => ({}));
11
11
  const defined = (0, utils_js_1.createObject)(registryKeys, () => []);
12
12
  const extended = (0, utils_js_1.createObject)(registryKeys, () => []);
@@ -59,9 +59,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
59
59
  //
60
60
  //
61
61
  // An actual output
62
- const imports = [`import * as ${importNamespace} from "${importPath}";`];
62
+ const imports = [`import${useTypeImports ? ' type' : ''} * as ${importNamespace} from "${importPath}";`];
63
63
  if (useGraphQLModules) {
64
- imports.push(`import * as gm from "graphql-modules";`);
64
+ imports.push(`import${useTypeImports ? ' type' : ''} * as gm from "graphql-modules";`);
65
65
  }
66
66
  let content = [
67
67
  printDefinedFields(),
package/cjs/index.js CHANGED
@@ -12,6 +12,7 @@ exports.preset = {
12
12
  const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
13
13
  const useGraphQLModules = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
14
14
  const requireRootResolvers = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.presetConfig.requireRootResolvers, false);
15
+ const useTypeImports = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.config.useTypeImports, false) || false;
15
16
  const cwd = (0, path_1.resolve)(options.presetConfig.cwd || process.cwd());
16
17
  const importTypesNamespace = options.presetConfig.importTypesNamespace || 'Types';
17
18
  if (!baseTypesPath) {
@@ -99,6 +100,7 @@ exports.preset = {
99
100
  (_b = schema.getMutationType()) === null || _b === void 0 ? void 0 : _b.name,
100
101
  (_c = schema.getSubscriptionType()) === null || _c === void 0 ? void 0 : _c.name,
101
102
  ].filter(Boolean),
103
+ useTypeImports,
102
104
  });
103
105
  },
104
106
  },
package/esm/builder.js CHANGED
@@ -3,7 +3,7 @@ import { pascalCase } from 'change-case-all';
3
3
  import { unique, withQuotes, buildBlock, pushUnique, concatByKey, uniqueByKey, createObject, collectUsedTypes, indent, } from './utils.js';
4
4
  const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
5
5
  const resolverKeys = ['scalars', 'objects', 'enums'];
6
- export function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }) {
6
+ export function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports = false, }) {
7
7
  const picks = createObject(registryKeys, () => ({}));
8
8
  const defined = createObject(registryKeys, () => []);
9
9
  const extended = createObject(registryKeys, () => []);
@@ -56,9 +56,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
56
56
  //
57
57
  //
58
58
  // An actual output
59
- const imports = [`import * as ${importNamespace} from "${importPath}";`];
59
+ const imports = [`import${useTypeImports ? ' type' : ''} * as ${importNamespace} from "${importPath}";`];
60
60
  if (useGraphQLModules) {
61
- imports.push(`import * as gm from "graphql-modules";`);
61
+ imports.push(`import${useTypeImports ? ' type' : ''} * as gm from "graphql-modules";`);
62
62
  }
63
63
  let content = [
64
64
  printDefinedFields(),
package/esm/index.js CHANGED
@@ -9,6 +9,7 @@ export const preset = {
9
9
  const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
10
10
  const useGraphQLModules = getConfigValue(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
11
11
  const requireRootResolvers = getConfigValue(options === null || options === void 0 ? void 0 : options.presetConfig.requireRootResolvers, false);
12
+ const useTypeImports = getConfigValue(options === null || options === void 0 ? void 0 : options.config.useTypeImports, false) || false;
12
13
  const cwd = resolve(options.presetConfig.cwd || process.cwd());
13
14
  const importTypesNamespace = options.presetConfig.importTypesNamespace || 'Types';
14
15
  if (!baseTypesPath) {
@@ -96,6 +97,7 @@ export const preset = {
96
97
  (_b = schema.getMutationType()) === null || _b === void 0 ? void 0 : _b.name,
97
98
  (_c = schema.getSubscriptionType()) === null || _c === void 0 ? void 0 : _c.name,
98
99
  ].filter(Boolean),
100
+ useTypeImports,
99
101
  });
100
102
  },
101
103
  },
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-codegen/graphql-modules-preset",
3
- "version": "2.5.2-alpha-20220926231710-4ae616388",
3
+ "version": "2.5.3",
4
4
  "description": "GraphQL Code Generator preset for modularized schema",
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
9
  "@graphql-codegen/plugin-helpers": "^2.6.2",
10
- "@graphql-codegen/visitor-plugin-common": "2.12.2-alpha-20220926231710-4ae616388",
10
+ "@graphql-codegen/visitor-plugin-common": "2.12.2",
11
11
  "@graphql-tools/utils": "^8.8.0",
12
12
  "parse-filepath": "^1.0.2",
13
13
  "change-case-all": "1.0.14",
@@ -1,7 +1,7 @@
1
1
  import { DocumentNode, GraphQLSchema } from 'graphql';
2
2
  import { ModulesConfig } from './config.cjs';
3
3
  import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
4
- export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }: {
4
+ export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports, }: {
5
5
  importNamespace: string;
6
6
  importPath: string;
7
7
  encapsulate: ModulesConfig['encapsulateModuleTypes'];
@@ -11,4 +11,5 @@ export declare function buildModule(name: string, doc: DocumentNode, { importNam
11
11
  baseVisitor: BaseVisitor;
12
12
  schema?: GraphQLSchema;
13
13
  useGraphQLModules: boolean;
14
+ useTypeImports?: boolean;
14
15
  }): string;
@@ -1,7 +1,7 @@
1
1
  import { DocumentNode, GraphQLSchema } from 'graphql';
2
2
  import { ModulesConfig } from './config.js';
3
3
  import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
4
- export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }: {
4
+ export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports, }: {
5
5
  importNamespace: string;
6
6
  importPath: string;
7
7
  encapsulate: ModulesConfig['encapsulateModuleTypes'];
@@ -11,4 +11,5 @@ export declare function buildModule(name: string, doc: DocumentNode, { importNam
11
11
  baseVisitor: BaseVisitor;
12
12
  schema?: GraphQLSchema;
13
13
  useGraphQLModules: boolean;
14
+ useTypeImports?: boolean;
14
15
  }): string;
@@ -6,14 +6,22 @@ export declare type ModulesConfig = {
6
6
  * The key of the output is used a base path for this file.
7
7
  *
8
8
  * @example
9
- * ```yaml
10
- * generates:
11
- * src/:
12
- * preset: modules
13
- * presetConfig:
14
- * baseTypesPath: types.ts
15
- * plugins:
16
- * - typescript-resolvers
9
+ * ```ts filename="codegen.ts" {10}
10
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
11
+ *
12
+ * const config: CodegenConfig = {
13
+ * // ...
14
+ * generates: {
15
+ * 'path/to/file.ts': {
16
+ * preset: 'modules',
17
+ * plugins: ['typescript-resolvers'],
18
+ * presetConfig: {
19
+ * baseTypesPath: 'types.ts'
20
+ * },
21
+ * },
22
+ * },
23
+ * };
24
+ * export default config;
17
25
  * ```
18
26
  */
19
27
  baseTypesPath: string;
@@ -32,15 +40,23 @@ export declare type ModulesConfig = {
32
40
  * @default process.cwd()
33
41
  *
34
42
  * @example
35
- * ```yaml
36
- * generates:
37
- * src/:
38
- * preset: modules
39
- * presetConfig:
40
- * baseTypesPath: types.ts
41
- * cwd: /some/path
42
- * plugins:
43
- * - typescript-resolvers
43
+ * ```ts filename="codegen.ts" {10}
44
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
45
+ *
46
+ * const config: CodegenConfig = {
47
+ * // ...
48
+ * generates: {
49
+ * 'path/to/file.ts': {
50
+ * preset: 'modules',
51
+ * plugins: ['typescript-resolvers'],
52
+ * presetConfig: {
53
+ * baseTypesPath: 'types.ts',
54
+ * cwd: '/some/path'
55
+ * },
56
+ * },
57
+ * },
58
+ * };
59
+ * export default config;
44
60
  * ```
45
61
  */
46
62
  cwd?: string;
@@ -51,15 +67,23 @@ export declare type ModulesConfig = {
51
67
  * @default Types
52
68
  *
53
69
  * @example
54
- * ```yaml
55
- * generates:
56
- * src/:
57
- * preset: modules
58
- * presetConfig:
59
- * baseTypesPath: types.ts
60
- * importTypesNamespace: core
61
- * plugins:
62
- * - typescript-resolvers
70
+ * ```ts filename="codegen.ts" {10}
71
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
72
+ *
73
+ * const config: CodegenConfig = {
74
+ * // ...
75
+ * generates: {
76
+ * 'path/to/file.ts': {
77
+ * preset: 'modules',
78
+ * plugins: ['typescript-resolvers'],
79
+ * presetConfig: {
80
+ * baseTypesPath: 'types.ts',
81
+ * importTypesNamespace: 'core'
82
+ * },
83
+ * },
84
+ * },
85
+ * };
86
+ * export default config;
63
87
  * ```
64
88
  */
65
89
  importTypesNamespace?: string;
@@ -6,14 +6,22 @@ export declare type ModulesConfig = {
6
6
  * The key of the output is used a base path for this file.
7
7
  *
8
8
  * @example
9
- * ```yaml
10
- * generates:
11
- * src/:
12
- * preset: modules
13
- * presetConfig:
14
- * baseTypesPath: types.ts
15
- * plugins:
16
- * - typescript-resolvers
9
+ * ```ts filename="codegen.ts" {10}
10
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
11
+ *
12
+ * const config: CodegenConfig = {
13
+ * // ...
14
+ * generates: {
15
+ * 'path/to/file.ts': {
16
+ * preset: 'modules',
17
+ * plugins: ['typescript-resolvers'],
18
+ * presetConfig: {
19
+ * baseTypesPath: 'types.ts'
20
+ * },
21
+ * },
22
+ * },
23
+ * };
24
+ * export default config;
17
25
  * ```
18
26
  */
19
27
  baseTypesPath: string;
@@ -32,15 +40,23 @@ export declare type ModulesConfig = {
32
40
  * @default process.cwd()
33
41
  *
34
42
  * @example
35
- * ```yaml
36
- * generates:
37
- * src/:
38
- * preset: modules
39
- * presetConfig:
40
- * baseTypesPath: types.ts
41
- * cwd: /some/path
42
- * plugins:
43
- * - typescript-resolvers
43
+ * ```ts filename="codegen.ts" {10}
44
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
45
+ *
46
+ * const config: CodegenConfig = {
47
+ * // ...
48
+ * generates: {
49
+ * 'path/to/file.ts': {
50
+ * preset: 'modules',
51
+ * plugins: ['typescript-resolvers'],
52
+ * presetConfig: {
53
+ * baseTypesPath: 'types.ts',
54
+ * cwd: '/some/path'
55
+ * },
56
+ * },
57
+ * },
58
+ * };
59
+ * export default config;
44
60
  * ```
45
61
  */
46
62
  cwd?: string;
@@ -51,15 +67,23 @@ export declare type ModulesConfig = {
51
67
  * @default Types
52
68
  *
53
69
  * @example
54
- * ```yaml
55
- * generates:
56
- * src/:
57
- * preset: modules
58
- * presetConfig:
59
- * baseTypesPath: types.ts
60
- * importTypesNamespace: core
61
- * plugins:
62
- * - typescript-resolvers
70
+ * ```ts filename="codegen.ts" {10}
71
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
72
+ *
73
+ * const config: CodegenConfig = {
74
+ * // ...
75
+ * generates: {
76
+ * 'path/to/file.ts': {
77
+ * preset: 'modules',
78
+ * plugins: ['typescript-resolvers'],
79
+ * presetConfig: {
80
+ * baseTypesPath: 'types.ts',
81
+ * importTypesNamespace: 'core'
82
+ * },
83
+ * },
84
+ * },
85
+ * };
86
+ * export default config;
63
87
  * ```
64
88
  */
65
89
  importTypesNamespace?: string;