@graphql-codegen/graphql-modules-preset 2.5.0 → 2.5.1-alpha-20220805095358-8b7e687d1
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/package.json +4 -4
- package/typings/builder.d.cts +14 -0
- package/typings/config.d.cts +114 -0
- package/typings/index.d.cts +4 -0
- package/typings/utils.d.cts +25 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/graphql-modules-preset",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1-alpha-20220805095358-8b7e687d1",
|
|
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
|
-
"@graphql-codegen/plugin-helpers": "
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.12.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "2.6.2-alpha-20220805095358-8b7e687d1",
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.12.1-alpha-20220805095358-8b7e687d1",
|
|
11
11
|
"@graphql-tools/utils": "^8.8.0",
|
|
12
12
|
"parse-filepath": "^1.0.2",
|
|
13
13
|
"change-case-all": "1.0.14",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"require": {
|
|
32
|
-
"types": "./typings/index.d.
|
|
32
|
+
"types": "./typings/index.d.cts",
|
|
33
33
|
"default": "./cjs/index.js"
|
|
34
34
|
},
|
|
35
35
|
"import": {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
|
+
import { ModulesConfig } from './config.cjs';
|
|
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, }: {
|
|
5
|
+
importNamespace: string;
|
|
6
|
+
importPath: string;
|
|
7
|
+
encapsulate: ModulesConfig['encapsulateModuleTypes'];
|
|
8
|
+
requireRootResolvers: ModulesConfig['requireRootResolvers'];
|
|
9
|
+
shouldDeclare: boolean;
|
|
10
|
+
rootTypes: string[];
|
|
11
|
+
baseVisitor: BaseVisitor;
|
|
12
|
+
schema?: GraphQLSchema;
|
|
13
|
+
useGraphQLModules: boolean;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export declare type ModulesConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* @name baseTypesPath
|
|
4
|
+
* @type string
|
|
5
|
+
* @description Required, should point to the base schema types file.
|
|
6
|
+
* The key of the output is used a base path for this file.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```yaml
|
|
10
|
+
* generates:
|
|
11
|
+
* src/:
|
|
12
|
+
* preset: modules
|
|
13
|
+
* presetConfig:
|
|
14
|
+
* baseTypesPath: types.ts
|
|
15
|
+
* plugins:
|
|
16
|
+
* - typescript-resolvers
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
baseTypesPath: string;
|
|
20
|
+
/**
|
|
21
|
+
* @name importBaseTypesFrom
|
|
22
|
+
* @type string
|
|
23
|
+
* @description Overrides the package import for the base types. Use this if you are within a monorepo, and you wish
|
|
24
|
+
* to import the base types directly from a different package, and not from a relative path.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
importBaseTypesFrom?: string;
|
|
28
|
+
/**
|
|
29
|
+
* @name cwd
|
|
30
|
+
* @type string
|
|
31
|
+
* @description Optional, override the `cwd` of the execution. We are using `cwd` to figure out the imports between files. Use this if your execution path is not your project root directory.
|
|
32
|
+
* @default process.cwd()
|
|
33
|
+
*
|
|
34
|
+
* @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
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
cwd?: string;
|
|
47
|
+
/**
|
|
48
|
+
* @name importTypesNamespace
|
|
49
|
+
* @type string
|
|
50
|
+
* @description Optional, override the name of the import namespace used to import from the `baseTypesPath` file.
|
|
51
|
+
* @default Types
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```yaml
|
|
55
|
+
* generates:
|
|
56
|
+
* src/:
|
|
57
|
+
* preset: modules
|
|
58
|
+
* presetConfig:
|
|
59
|
+
* baseTypesPath: types.ts
|
|
60
|
+
* importTypesNamespace: core
|
|
61
|
+
* plugins:
|
|
62
|
+
* - typescript-resolvers
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
importTypesNamespace?: string;
|
|
66
|
+
/**
|
|
67
|
+
* @name filename
|
|
68
|
+
* @type string
|
|
69
|
+
* @description Required, sets the file name for the generated files.
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
filename: string;
|
|
73
|
+
/**
|
|
74
|
+
* @name encapsulateModuleTypes
|
|
75
|
+
* @type string
|
|
76
|
+
* @default namespace
|
|
77
|
+
* @description Configure how to encapsulate the module types, to avoid confusion.
|
|
78
|
+
*
|
|
79
|
+
* `namespace` (default): will wrap all types in a TypeScript namespace, using the module name.
|
|
80
|
+
* `prefix`: will prefix all types from a specific module with the module name.
|
|
81
|
+
* `none`: will skip encapsulation, and generate type as-is.
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
encapsulateModuleTypes: 'prefix' | 'namespace' | 'none';
|
|
85
|
+
/**
|
|
86
|
+
* @name requireRootResolvers
|
|
87
|
+
* @type boolean
|
|
88
|
+
* @default false
|
|
89
|
+
* @description Generate resolvers of root types (Query, Mutation and Subscription) as non-optional.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```yml
|
|
93
|
+
* generates:
|
|
94
|
+
* src/:
|
|
95
|
+
* preset: modules
|
|
96
|
+
* presetConfig:
|
|
97
|
+
* baseTypesPath: types.ts
|
|
98
|
+
* filename: types.ts
|
|
99
|
+
* requireRootResolvers: true
|
|
100
|
+
* plugins:
|
|
101
|
+
* - typescript-resolvers
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
requireRootResolvers?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* @name useGraphQLModules
|
|
107
|
+
* @type boolean
|
|
108
|
+
* @default true
|
|
109
|
+
* @description By default, the generated types will generate some code specific to `graphql-modules` library.
|
|
110
|
+
*
|
|
111
|
+
* If you are not using GraphQL-Modules, you can disable this feature by setting this to `false`.
|
|
112
|
+
*/
|
|
113
|
+
useGraphQLModules?: boolean;
|
|
114
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DocumentNode, NamedTypeNode, TypeNode } from 'graphql';
|
|
2
|
+
import { Source } from '@graphql-tools/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Searches every node to collect used types
|
|
5
|
+
*/
|
|
6
|
+
export declare function collectUsedTypes(doc: DocumentNode): string[];
|
|
7
|
+
export declare function resolveTypeNode(node: TypeNode): NamedTypeNode;
|
|
8
|
+
export declare function isGraphQLPrimitive(name: string): boolean;
|
|
9
|
+
export declare function unique<T>(val: T, i: number, all: T[]): boolean;
|
|
10
|
+
export declare function withQuotes(val: string): string;
|
|
11
|
+
export declare function indent(size: number): (val: string) => string;
|
|
12
|
+
export declare function buildBlock({ name, lines }: {
|
|
13
|
+
name: string;
|
|
14
|
+
lines: string[];
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function groupSourcesByModule(sources: Source[], basePath: string): Record<string, Source[]>;
|
|
17
|
+
export declare function stripFilename(path: string): string;
|
|
18
|
+
export declare function normalize(path: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Pushes an item to a list only if the list doesn't include the item
|
|
21
|
+
*/
|
|
22
|
+
export declare function pushUnique<T>(list: T[], item: T): void;
|
|
23
|
+
export declare function concatByKey<T extends Record<string, any[]>, K extends keyof T>(left: T, right: T, key: K): T[K][number][];
|
|
24
|
+
export declare function uniqueByKey<T extends Record<string, any[]>, K extends keyof T>(left: T, right: T, key: K): any[];
|
|
25
|
+
export declare function createObject<K extends string, T>(keys: K[], valueFn: (key: K) => T): Record<K, T>;
|