@eddeee888/gcg-typescript-resolver-files 0.3.0 → 0.4.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.
- package/README.md +200 -34
- package/package.json +5 -5
- package/src/defineConfig.d.ts +5 -0
- package/src/defineConfig.js +19 -0
- package/src/defineConfig.js.map +1 -0
- package/src/generateResolverFiles/addExternalResolverImport.d.ts +2 -1
- package/src/generateResolverFiles/addExternalResolverImport.js +3 -1
- package/src/generateResolverFiles/addExternalResolverImport.js.map +1 -1
- package/src/generateResolverFiles/addResolverMainFile.d.ts +4 -1
- package/src/generateResolverFiles/addResolverMainFile.js +75 -50
- package/src/generateResolverFiles/addResolverMainFile.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLObjectType.js +3 -1
- package/src/generateResolverFiles/handleGraphQLObjectType.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js +10 -2
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLScalarType.js +3 -1
- package/src/generateResolverFiles/handleGraphQLScalarType.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLUninionType.js +3 -1
- package/src/generateResolverFiles/handleGraphQLUninionType.js.map +1 -1
- package/src/generateResolverFiles/postProcessFiles.js +2 -1
- package/src/generateResolverFiles/postProcessFiles.js.map +1 -1
- package/src/generateResolverFiles/types.d.ts +12 -4
- package/src/generateResolverFiles/visitNamedType.js +28 -11
- package/src/generateResolverFiles/visitNamedType.js.map +1 -1
- package/src/generateTypeDefsFiles/generateTypeDefsContent.js.map +1 -0
- package/src/generateTypeDefsFiles/generateTypeDefsFiles.d.ts +13 -0
- package/src/generateTypeDefsFiles/generateTypeDefsFiles.js +64 -0
- package/src/generateTypeDefsFiles/generateTypeDefsFiles.js.map +1 -0
- package/src/generateTypeDefsFiles/index.d.ts +1 -0
- package/src/{generateTypeDefsContent → generateTypeDefsFiles}/index.js +1 -1
- package/src/{generateTypeDefsContent → generateTypeDefsFiles}/index.js.map +1 -1
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.d.ts +3 -3
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js +2 -2
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/parseGraphQLSchema/index.d.ts +1 -0
- package/src/{getPluginsConfig → parseGraphQLSchema}/index.js +1 -1
- package/src/parseGraphQLSchema/index.js.map +1 -0
- package/src/parseGraphQLSchema/parseGraphQLSchema.d.ts +20 -0
- package/src/{getPluginsConfig/getPluginsConfig.js → parseGraphQLSchema/parseGraphQLSchema.js} +10 -9
- package/src/parseGraphQLSchema/parseGraphQLSchema.js.map +1 -0
- package/src/parseSources/parseSources.d.ts +0 -1
- package/src/parseSources/parseSources.js +2 -3
- package/src/parseSources/parseSources.js.map +1 -1
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.d.ts +2 -1
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js +20 -5
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js.map +1 -1
- package/src/parseTypeMappers/parseTypeMappers.d.ts +3 -2
- package/src/parseTypeMappers/parseTypeMappers.js +3 -2
- package/src/parseTypeMappers/parseTypeMappers.js.map +1 -1
- package/src/preset.js +33 -23
- package/src/preset.js.map +1 -1
- package/src/utils/cwd.d.ts +4 -0
- package/src/utils/cwd.js +12 -0
- package/src/utils/cwd.js.map +1 -0
- package/src/utils/fmt.d.ts +7 -0
- package/src/utils/fmt.js +16 -0
- package/src/utils/fmt.js.map +1 -0
- package/src/utils/getNodePropertyMap.d.ts +1 -1
- package/src/utils/getNodePropertyMap.js +23 -15
- package/src/utils/getNodePropertyMap.js.map +1 -1
- package/src/utils/index.d.ts +5 -2
- package/src/utils/index.js +5 -16
- package/src/utils/index.js.map +1 -1
- package/src/utils/isRootObjectType.d.ts +1 -1
- package/src/utils/isWhitelistedModule.d.ts +5 -0
- package/src/utils/isWhitelistedModule.js +16 -0
- package/src/utils/isWhitelistedModule.js.map +1 -0
- package/src/utils/normalizeRelativePath.d.ts +1 -0
- package/src/utils/normalizeRelativePath.js +11 -0
- package/src/utils/normalizeRelativePath.js.map +1 -0
- package/src/utils/parseLocationForWhitelistedModule.js +7 -9
- package/src/utils/parseLocationForWhitelistedModule.js.map +1 -1
- package/src/utils/printImportLine.d.ts +2 -1
- package/src/utils/printImportLine.js +4 -2
- package/src/utils/printImportLine.js.map +1 -1
- package/src/utils/relativeModulePath.d.ts +1 -0
- package/src/utils/relativeModulePath.js +11 -0
- package/src/utils/relativeModulePath.js.map +1 -0
- package/src/validatePresetConfig/validatePresetConfig.d.ts +21 -5
- package/src/validatePresetConfig/validatePresetConfig.js +38 -19
- package/src/validatePresetConfig/validatePresetConfig.js.map +1 -1
- package/src/generateTypeDefsContent/generateTypeDefsContent.js.map +0 -1
- package/src/generateTypeDefsContent/index.d.ts +0 -1
- package/src/getPluginsConfig/getPluginsConfig.d.ts +0 -19
- package/src/getPluginsConfig/getPluginsConfig.js.map +0 -1
- package/src/getPluginsConfig/index.d.ts +0 -1
- package/src/getPluginsConfig/index.js.map +0 -1
- /package/src/{generateTypeDefsContent → generateTypeDefsFiles}/generateTypeDefsContent.d.ts +0 -0
- /package/src/{generateTypeDefsContent → generateTypeDefsFiles}/generateTypeDefsContent.js +0 -0
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This [GraphQL Code Generator](https://www.the-guild.dev/graphql/codegen) plugin creates resolvers given GraphQL schema.
|
|
4
4
|
|
|
5
|
-
This relies on types generated from [typescript](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript) and [@graphql-codegen/typescript-resolvers](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers) plugins.
|
|
5
|
+
This relies on types generated from [@graphql-codegen/typescript](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript) and [@graphql-codegen/typescript-resolvers](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers) plugins.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
yarn add -D @eddeee888/gcg-typescript-resolver-files
|
|
8
|
+
yarn add -D @graphql-codegen/cli @eddeee888/gcg-typescript-resolver-files
|
|
9
9
|
yarn add graphql-scalars
|
|
10
10
|
```
|
|
11
11
|
|
|
@@ -17,17 +17,17 @@ yarn add graphql-scalars
|
|
|
17
17
|
- Automatically sets up GraphQL Scalars with types and config from [graphql-scalars](https://github.com/Urigo/graphql-scalars) with ability to opt-out
|
|
18
18
|
- Automatically extracts object type mapper interfaces and types (marked with `Mapper` suffix) from accompanying `.mappers.ts` files in each module. For example, if the schema file is `/path/to/schema.graphql`, the mapper file is `/path/to/schema.mappers.ts`.
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Getting Started
|
|
21
21
|
|
|
22
22
|
### Setup
|
|
23
23
|
|
|
24
|
+
#### Files
|
|
25
|
+
|
|
24
26
|
```graphql
|
|
25
|
-
# src/
|
|
27
|
+
# src/schema/base/schema.graphql
|
|
26
28
|
type Query
|
|
27
|
-
```
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
# src/graphql/modules/user/schema.graphqls
|
|
30
|
+
# src/schema/user/schema.graphql
|
|
31
31
|
extend type Query {
|
|
32
32
|
user(id: ID!): User
|
|
33
33
|
}
|
|
@@ -44,7 +44,7 @@ type Address {
|
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
````ts
|
|
47
|
-
// src/
|
|
47
|
+
// src/schema/user/schema.mappers.ts
|
|
48
48
|
|
|
49
49
|
// Exporting the following Mapper interfaces and types is the equivalent of this codegen config:
|
|
50
50
|
// ```yml
|
|
@@ -62,39 +62,205 @@ export interface UserMapper {
|
|
|
62
62
|
}
|
|
63
63
|
````
|
|
64
64
|
|
|
65
|
+
#### Codegen Config
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// codegen.ts
|
|
69
|
+
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
70
|
+
import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files';
|
|
71
|
+
|
|
72
|
+
const config: CodegenConfig = {
|
|
73
|
+
schema: '**/schema.graphql',
|
|
74
|
+
generates: {
|
|
75
|
+
'src/schema': defineConfig(),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default config;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
OR
|
|
83
|
+
|
|
65
84
|
```yml
|
|
66
85
|
# codegen.yml
|
|
67
|
-
schema: '**/*.
|
|
86
|
+
schema: '**/*.graphql'
|
|
68
87
|
generates:
|
|
69
|
-
src/
|
|
88
|
+
src/schema:
|
|
70
89
|
preset: '@eddeee888/gcg-typescript-resolver-files'
|
|
90
|
+
watchPattern: '**/*.mappers.ts'
|
|
71
91
|
```
|
|
72
92
|
|
|
73
93
|
### Result
|
|
74
94
|
|
|
75
95
|
Running codegen will generate the following files:
|
|
76
96
|
|
|
77
|
-
- `src/
|
|
78
|
-
- `src/
|
|
79
|
-
- `src/
|
|
80
|
-
- `src/
|
|
81
|
-
- `src/
|
|
82
|
-
- `src/
|
|
83
|
-
|
|
84
|
-
## Config
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
- `src/schema/user/resolvers/Query/user.ts`
|
|
98
|
+
- `src/schema/user/resolvers/User.ts`
|
|
99
|
+
- `src/schema/user/resolvers/Address.ts`
|
|
100
|
+
- `src/schema/resolvers.generated.ts`
|
|
101
|
+
- `src/schema/typeDefs.generated.ts`
|
|
102
|
+
- `src/schema/types.generated.ts`
|
|
103
|
+
|
|
104
|
+
## Config Options
|
|
105
|
+
|
|
106
|
+
### mode
|
|
107
|
+
|
|
108
|
+
`merged` or `modules` (Default: `modules`)
|
|
109
|
+
|
|
110
|
+
How files are collocated. `modules` detects containing dir of a schema file as "modules", then split resolvers into those modules. `merged` treats `baseOutputDir` as the one and only module and generates resolvers.
|
|
111
|
+
|
|
112
|
+
### resolverTypesPath
|
|
113
|
+
|
|
114
|
+
`string` (Default: `./types.generated.ts`)
|
|
115
|
+
|
|
116
|
+
Relative path to type file generated by `typescript-resolvers` plugin.
|
|
117
|
+
|
|
118
|
+
### resolverRelativeTargetDir
|
|
119
|
+
|
|
120
|
+
`string` (Default: `resolvers`)
|
|
121
|
+
|
|
122
|
+
Relative path to target dir. For `config.mode=merged`, files will be generated into `<baseOutputDir>/<resolverRelativeTargetDir>`. For `config.mode=modules`, files will be generated into `<baseOutputDir>/<moduleName>/<resolverRelativeTargetDir>`.
|
|
123
|
+
|
|
124
|
+
### resolverMainFileMode
|
|
125
|
+
|
|
126
|
+
`merged` or `modules` (Default: `merged`)
|
|
127
|
+
|
|
128
|
+
How to generate file/s that put resolvers map together:
|
|
129
|
+
|
|
130
|
+
- `merged`: one file
|
|
131
|
+
- `modules`: one file per module
|
|
132
|
+
|
|
133
|
+
### resolverMainFile
|
|
134
|
+
|
|
135
|
+
`string` (Default: `resolvers.generated.ts`)
|
|
136
|
+
|
|
137
|
+
File that puts all generated resolvers together. Relative from `baseOutputDir`.
|
|
138
|
+
|
|
139
|
+
### typeDefsFileMode
|
|
140
|
+
|
|
141
|
+
`merged` or `mergedWhitelisted` or `modules` (Default: `merged`)
|
|
142
|
+
|
|
143
|
+
How to generate typeDefs file/s:
|
|
144
|
+
|
|
145
|
+
- `merged`: one file
|
|
146
|
+
- `mergedWhitelisted`: one file but only contains whitelisted modules
|
|
147
|
+
- `modules`: one file per module
|
|
148
|
+
|
|
149
|
+
If `config.mode=merged`, this config is always `merged`
|
|
150
|
+
|
|
151
|
+
### typeDefsFilePath
|
|
152
|
+
|
|
153
|
+
`string` or `false` (Default: `./typeDefs.generated.ts`)
|
|
154
|
+
|
|
155
|
+
Where to generate typeDefs files. If value is `false` or empty string, the file/s are not generated.
|
|
156
|
+
|
|
157
|
+
If `typeDefsFileMode=merged` or `typeDefsFileMode=mergedWhitelisted`, this path is relative from `baseOutputDir`.
|
|
158
|
+
|
|
159
|
+
If `typeDefsFileMode=modules`, this path is relative from each module directory.
|
|
160
|
+
|
|
161
|
+
### whitelistedModules
|
|
162
|
+
|
|
163
|
+
`Array<string>` (Only works with `config.mode=modules`)
|
|
164
|
+
|
|
165
|
+
Whitelists modules to generate files and entries in main file. By default all modules are whitelisted. Useful for gradual migrations.
|
|
166
|
+
|
|
167
|
+
### blacklistedModules
|
|
168
|
+
|
|
169
|
+
`Array<string>` (Only works with `config.mode=modules`)
|
|
170
|
+
|
|
171
|
+
Blacklists modules to avoid generate files and entries in main file. Useful for gradual migrations.
|
|
172
|
+
|
|
173
|
+
### externalResolvers
|
|
174
|
+
|
|
175
|
+
`Record<string, string>`
|
|
176
|
+
|
|
177
|
+
Map of relative or absolute path (prefixed with `~`) to external or existing resolvers.
|
|
178
|
+
|
|
179
|
+
Examples:
|
|
180
|
+
|
|
181
|
+
- `DateTime: ~graphql-scalars#DateTimeResolver`
|
|
182
|
+
- `Query.me: '~@org/meResolver#default as meResolver'`
|
|
183
|
+
- `User: 'otherResolvers#User as UserResolver'`.
|
|
184
|
+
|
|
185
|
+
### typesPluginsConfig
|
|
186
|
+
|
|
187
|
+
`(@graphql-codegen/typescript).TypeScriptPluginConfig & (@graphql-codegen/typescript-resolvers).TypeScriptResolversPluginConfig`
|
|
188
|
+
|
|
189
|
+
Takes [typescript config](https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript) and [typescript-resolvers config](https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers) to override the defaults.
|
|
190
|
+
|
|
191
|
+
### mappersFileExtension
|
|
192
|
+
|
|
193
|
+
`string` (Default: `.mappers.ts`)
|
|
194
|
+
|
|
195
|
+
The files with this extension provides mappers interfaces and types for the schema files in the same module.
|
|
196
|
+
|
|
197
|
+
### mappersSuffix
|
|
198
|
+
|
|
199
|
+
`string` (Default: `Mapper`)
|
|
200
|
+
|
|
201
|
+
Exported interfaces and types with this suffix from `mappersFile` in each module are put into the mappers object of [@graphql-codegen/typescript-resolvers](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers).
|
|
202
|
+
|
|
203
|
+
### tsConfigFilePath
|
|
204
|
+
|
|
205
|
+
`string` (Default: `./tsconfig.json`)
|
|
206
|
+
|
|
207
|
+
Project's TypeScript config, relative from project root. This helps type analysis such as resolving custom module paths.
|
|
208
|
+
|
|
209
|
+
### fixObjectTypeResolvers
|
|
210
|
+
|
|
211
|
+
`smart` or `disabled` (Default: `smart`) (Experimental)
|
|
212
|
+
|
|
213
|
+
Statically compares object type's mapper types' field against schema types' fields, creating resolvers if required
|
|
214
|
+
|
|
215
|
+
### emitLegacyCommonJSImports
|
|
216
|
+
|
|
217
|
+
`bool` (Default: `true`)
|
|
218
|
+
|
|
219
|
+
Determines whether imports emitted should use CommonJS syntax or ESM syntax (with `.js` file endings)
|
|
220
|
+
|
|
221
|
+
## Config Examples
|
|
222
|
+
|
|
223
|
+
#### 1. Custom Config
|
|
224
|
+
|
|
225
|
+
Custom preset config can be set using the `presetConfig` option:
|
|
226
|
+
|
|
227
|
+
```yml
|
|
228
|
+
# codegen.yml
|
|
229
|
+
schema: '**/*.graphql'
|
|
230
|
+
generates:
|
|
231
|
+
src/schema:
|
|
232
|
+
preset: '@eddeee888/gcg-typescript-resolver-files'
|
|
233
|
+
presetConfig:
|
|
234
|
+
mode: 'modules'
|
|
235
|
+
resolverTypesPath: './types.gen.ts'
|
|
236
|
+
typeDefsFilePath: false
|
|
237
|
+
typesPluginsConfig: # Pass config you'd normally use for `typescript` and `typescript-resolvers` here
|
|
238
|
+
nonOptionalTypename: false
|
|
239
|
+
federation: true
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### 2. Using TypeScript Config File
|
|
243
|
+
|
|
244
|
+
If you use `codegen.ts`, you can use the exported `defineConfig` function to get better TypeScript support:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
248
|
+
import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files';
|
|
249
|
+
|
|
250
|
+
const config: CodegenConfig = {
|
|
251
|
+
schema: '**/schema.graphql',
|
|
252
|
+
generates: {
|
|
253
|
+
'src/schema': defineConfig({
|
|
254
|
+
mode: 'modules',
|
|
255
|
+
resolverTypesPath: './types.gen.ts',
|
|
256
|
+
typeDefsFilePath: false,
|
|
257
|
+
typesPluginsConfig: {
|
|
258
|
+
// Pass config you'd normally use for `typescript` and `typescript-resolvers` here
|
|
259
|
+
nonOptionalTypename: false,
|
|
260
|
+
federation: true,
|
|
261
|
+
},
|
|
262
|
+
}),
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
export default config;
|
|
266
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eddeee888/gcg-typescript-resolver-files",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/eddeee888/graphql-code-generator-plugins.git",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@graphql-codegen/add": "^4.0.0",
|
|
31
|
-
"@graphql-codegen/plugin-helpers": "^4.
|
|
32
|
-
"@graphql-codegen/typescript": "^3.0.
|
|
33
|
-
"@graphql-codegen/typescript-resolvers": "^3.
|
|
31
|
+
"@graphql-codegen/plugin-helpers": "^4.2.0",
|
|
32
|
+
"@graphql-codegen/typescript": "^3.0.3",
|
|
33
|
+
"@graphql-codegen/typescript-resolvers": "^3.2.0",
|
|
34
34
|
"graphql-scalars": "^1.20.1",
|
|
35
|
-
"ts-morph": "^
|
|
35
|
+
"ts-morph": "^18.0.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"directory": "../../dist/packages/typescript-resolver-files"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import type { TypedPresetConfig } from './validatePresetConfig';
|
|
3
|
+
export declare const defineConfig: (presetConfig?: TypedPresetConfig, context?: {
|
|
4
|
+
baseOutputDir: string;
|
|
5
|
+
}) => Pick<Types.ConfiguredOutput, 'preset' | 'presetConfig' | 'watchPattern'>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineConfig = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const preset_1 = require("./preset");
|
|
6
|
+
const defineConfig = (presetConfig = {}, context = { baseOutputDir: '' }) => {
|
|
7
|
+
const { baseOutputDir } = context;
|
|
8
|
+
const mappersFileExtension = presetConfig.mappersFileExtension || '.mappers.ts';
|
|
9
|
+
const watchPattern = [];
|
|
10
|
+
const mapperWatchPattern = path.posix.join(baseOutputDir, '**', `*${mappersFileExtension}`);
|
|
11
|
+
watchPattern.push(mapperWatchPattern);
|
|
12
|
+
return {
|
|
13
|
+
preset: preset_1.preset,
|
|
14
|
+
presetConfig,
|
|
15
|
+
watchPattern,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.defineConfig = defineConfig;
|
|
19
|
+
//# sourceMappingURL=defineConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineConfig.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/defineConfig.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAG7B,qCAAkC;AAE3B,MAAM,YAAY,GAAG,CAC1B,eAAkC,EAAE,EACpC,UAAqC,EAAE,aAAa,EAAE,EAAE,EAAE,EACgB,EAAE;IAC5E,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAElC,MAAM,oBAAoB,GACxB,YAAY,CAAC,oBAAoB,IAAI,aAAa,CAAC;IAErD,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CACxC,aAAa,EACb,IAAI,EACJ,IAAI,oBAAoB,EAAE,CAC3B,CAAC;IACF,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAEtC,OAAO;QACL,MAAM,EAAN,eAAM;QACN,YAAY;QACZ,YAAY;KACb,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,YAAY,gBAsBvB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { GenerateResolverFilesContext } from './types';
|
|
2
2
|
interface AddExternalResolverImportParams {
|
|
3
|
+
moduleName: string;
|
|
3
4
|
normalizedResolverName: string;
|
|
4
5
|
configImportSyntax: string;
|
|
5
6
|
}
|
|
6
|
-
export declare const addExternalResolverImport: (params: AddExternalResolverImportParams, { result }: GenerateResolverFilesContext) => void;
|
|
7
|
+
export declare const addExternalResolverImport: (params: AddExternalResolverImportParams, { result, config: { emitLegacyCommonJSImports }, }: GenerateResolverFilesContext) => void;
|
|
7
8
|
export {};
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addExternalResolverImport = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const addExternalResolverImport = (params, { result }) => {
|
|
5
|
+
const addExternalResolverImport = (params, { result, config: { emitLegacyCommonJSImports }, }) => {
|
|
6
6
|
const { importIdentifier, identifierUsage, moduleImport } = parseImportSyntax(params);
|
|
7
7
|
result.externalImports[moduleImport] =
|
|
8
8
|
result.externalImports[moduleImport] ||
|
|
9
9
|
{
|
|
10
|
+
moduleName: params.moduleName,
|
|
10
11
|
importLineMeta: {
|
|
11
12
|
isTypeImport: false,
|
|
12
13
|
module: moduleImport,
|
|
13
14
|
namedImports: [],
|
|
14
15
|
defaultImport: undefined,
|
|
16
|
+
emitLegacyCommonJSImports: emitLegacyCommonJSImports,
|
|
15
17
|
},
|
|
16
18
|
identifierUsages: [],
|
|
17
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExternalResolverImport.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/addExternalResolverImport.ts"],"names":[],"mappings":";;;AAAA,oCAAiD;
|
|
1
|
+
{"version":3,"file":"addExternalResolverImport.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/addExternalResolverImport.ts"],"names":[],"mappings":";;;AAAA,oCAAiD;AAc1C,MAAM,yBAAyB,GAAG,CACvC,MAAuC,EACvC,EACE,MAAM,EACN,MAAM,EAAE,EAAE,yBAAyB,EAAE,GACR,EACzB,EAAE;IACR,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAAE,GACvD,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE5B,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC;QAClC,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC;YACnC;gBACC,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,cAAc,EAAE;oBACd,YAAY,EAAE,KAAK;oBACnB,MAAM,EAAE,YAAY;oBACpB,YAAY,EAAE,EAAE;oBAChB,aAAa,EAAE,SAAS;oBACxB,yBAAyB,EAAE,yBAAyB;iBACrD;gBACD,gBAAgB,EAAE,EAAE;aACiD,CAAC;IAE1E,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IAE5D,QAAQ,gBAAgB,CAAC,MAAM,EAAE;QAC/B,KAAK,SAAS;YACZ,IACE,cA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ename addResolverMainFile -> addResolverMainFiles
|
|
4
|
+
*/
|
|
5
|
+
export declare const addResolverMainFile: ({ config: { baseOutputDir, resolverTypesPath, resolverMainFile, resolverMainFileMode, emitLegacyCommonJSImports, }, result, }: GenerateResolverFilesContext) => void;
|
|
@@ -3,23 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addResolverMainFile = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const createDefaultFileDetails = () => ({
|
|
7
|
+
importLines: [],
|
|
8
|
+
queryFields: [],
|
|
9
|
+
mutationFields: [],
|
|
10
|
+
subscriptionFields: [],
|
|
11
|
+
objectTypes: [],
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* TODO: rename addResolverMainFile -> addResolverMainFiles
|
|
15
|
+
*/
|
|
16
|
+
const addResolverMainFile = ({ config: { baseOutputDir, resolverTypesPath, resolverMainFile, resolverMainFileMode, emitLegacyCommonJSImports, }, result, }) => {
|
|
17
|
+
const resolverMainFiles = Object.entries(result.files).reduce((res, [filepath, file]) => {
|
|
11
18
|
if (file.__filetype === 'file') {
|
|
12
19
|
return res;
|
|
13
20
|
}
|
|
21
|
+
const { meta } = file;
|
|
22
|
+
// If resolverMainFileMode === 'modules', generate main resolver files into modules, otherwise, do it at baseOutputDir
|
|
23
|
+
const resolverMainFilename = resolverMainFileMode === 'modules'
|
|
24
|
+
? path.posix.join(baseOutputDir, meta.moduleName, resolverMainFile)
|
|
25
|
+
: path.posix.join(baseOutputDir, resolverMainFile);
|
|
26
|
+
const outputDir = path.dirname(resolverMainFilename);
|
|
27
|
+
if (!res[resolverMainFilename]) {
|
|
28
|
+
res[resolverMainFilename] = createDefaultFileDetails();
|
|
29
|
+
}
|
|
14
30
|
// Non Root Object fields that was generated
|
|
15
31
|
if (file.__filetype === 'objectType' ||
|
|
16
32
|
file.__filetype === 'generalResolver') {
|
|
17
|
-
res.importLines.push((0, utils_1.printImportLine)({
|
|
33
|
+
res[resolverMainFilename].importLines.push((0, utils_1.printImportLine)({
|
|
18
34
|
isTypeImport: false,
|
|
19
35
|
module: (0, utils_1.relativeModulePath)(outputDir, filepath),
|
|
20
36
|
namedImports: [file.mainImportIdentifier],
|
|
37
|
+
emitLegacyCommonJSImports,
|
|
21
38
|
}));
|
|
22
|
-
res.objectTypes.push({
|
|
39
|
+
res[resolverMainFilename].objectTypes.push({
|
|
23
40
|
propertyName: file.mainImportIdentifier,
|
|
24
41
|
identifierName: file.mainImportIdentifier,
|
|
25
42
|
});
|
|
@@ -33,37 +50,40 @@ const addResolverMainFile = ({ config: { baseOutputDir, resolverTypesPath, resol
|
|
|
33
50
|
propertyName: file.mainImportIdentifier,
|
|
34
51
|
identifierName,
|
|
35
52
|
};
|
|
36
|
-
res.importLines.push((0, utils_1.printImportLine)({
|
|
53
|
+
res[resolverMainFilename].importLines.push((0, utils_1.printImportLine)({
|
|
37
54
|
isTypeImport: false,
|
|
38
55
|
module: (0, utils_1.relativeModulePath)(outputDir, filepath),
|
|
39
56
|
namedImports: [fieldMapping],
|
|
57
|
+
emitLegacyCommonJSImports,
|
|
40
58
|
}));
|
|
41
59
|
const rootObjectMap = {
|
|
42
|
-
Query: () => res.queryFields.push(fieldMapping),
|
|
43
|
-
Mutation: () => res.mutationFields.push(fieldMapping),
|
|
44
|
-
Subscription: () => res.subscriptionFields.push(fieldMapping),
|
|
60
|
+
Query: () => res[resolverMainFilename].queryFields.push(fieldMapping),
|
|
61
|
+
Mutation: () => res[resolverMainFilename].mutationFields.push(fieldMapping),
|
|
62
|
+
Subscription: () => res[resolverMainFilename].subscriptionFields.push(fieldMapping),
|
|
45
63
|
};
|
|
46
64
|
rootObjectMap[file.meta.belongsToRootObject]();
|
|
47
65
|
return res;
|
|
48
|
-
}, {
|
|
49
|
-
importLines: [],
|
|
50
|
-
queryFields: [],
|
|
51
|
-
mutationFields: [],
|
|
52
|
-
subscriptionFields: [],
|
|
53
|
-
objectTypes: [],
|
|
54
|
-
});
|
|
66
|
+
}, {});
|
|
55
67
|
Object.entries(result.externalImports).reduce((res, [module, meta]) => {
|
|
56
|
-
|
|
68
|
+
// If resolverMainFileMode === 'modules', generate main resolver files into modules, otherwise, do it at baseOutputDir
|
|
69
|
+
const resolverMainFilename = resolverMainFileMode === 'modules'
|
|
70
|
+
? path.posix.join(baseOutputDir, meta.moduleName, resolverMainFile)
|
|
71
|
+
: path.posix.join(baseOutputDir, resolverMainFile);
|
|
72
|
+
if (!res[resolverMainFilename]) {
|
|
73
|
+
res[resolverMainFilename] = createDefaultFileDetails();
|
|
74
|
+
}
|
|
75
|
+
res[resolverMainFilename].importLines.push((0, utils_1.printImportLine)({
|
|
57
76
|
isTypeImport: false,
|
|
58
77
|
module,
|
|
59
78
|
namedImports: meta.importLineMeta.namedImports,
|
|
60
79
|
defaultImport: meta.importLineMeta.defaultImport,
|
|
80
|
+
emitLegacyCommonJSImports,
|
|
61
81
|
}));
|
|
62
82
|
meta.identifierUsages.forEach((usage) => {
|
|
63
83
|
const resolverNameParts = usage.normalizedResolverName.split('.');
|
|
64
84
|
// Only 1 part, this is a GraphQL ObjectType
|
|
65
85
|
if (resolverNameParts.length === 1) {
|
|
66
|
-
res.objectTypes.push({
|
|
86
|
+
res[resolverMainFilename].objectTypes.push({
|
|
67
87
|
propertyName: resolverNameParts[0],
|
|
68
88
|
identifierName: usage.identifierName,
|
|
69
89
|
});
|
|
@@ -79,48 +99,53 @@ const addResolverMainFile = ({ config: { baseOutputDir, resolverTypesPath, resol
|
|
|
79
99
|
propertyName: field,
|
|
80
100
|
};
|
|
81
101
|
const rootObjectMap = {
|
|
82
|
-
Query: () => res.queryFields.push(fieldMapping),
|
|
83
|
-
Mutation: () => res.mutationFields.push(fieldMapping),
|
|
84
|
-
Subscription: () => res.subscriptionFields.push(fieldMapping),
|
|
102
|
+
Query: () => res[resolverMainFilename].queryFields.push(fieldMapping),
|
|
103
|
+
Mutation: () => res[resolverMainFilename].mutationFields.push(fieldMapping),
|
|
104
|
+
Subscription: () => res[resolverMainFilename].subscriptionFields.push(fieldMapping),
|
|
85
105
|
};
|
|
86
106
|
rootObjectMap[rootObjectType]();
|
|
87
107
|
});
|
|
88
108
|
return res;
|
|
89
|
-
},
|
|
109
|
+
}, resolverMainFiles);
|
|
90
110
|
const resolversIdentifier = 'resolvers';
|
|
91
111
|
const resolversTypeName = 'Resolvers'; // Generated type from typescript-resolvers plugin
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
Object.entries(resolverMainFiles).forEach(([resolverMainFilename, resolverMainFile]) => {
|
|
113
|
+
const outputDir = path.dirname(resolverMainFilename);
|
|
114
|
+
const relativePathToResolverTypes = (0, utils_1.relativeModulePath)(outputDir, resolverTypesPath);
|
|
115
|
+
const queries = resolverMainFile.queryFields.length > 0
|
|
116
|
+
? `Query: { ${resolverMainFile.queryFields
|
|
117
|
+
.map(printObjectMapping)
|
|
118
|
+
.join(',')} },`
|
|
119
|
+
: '';
|
|
120
|
+
const mutations = resolverMainFile.mutationFields.length > 0
|
|
121
|
+
? `Mutation: { ${resolverMainFile.mutationFields
|
|
122
|
+
.map(printObjectMapping)
|
|
123
|
+
.join(',')} },`
|
|
124
|
+
: '';
|
|
125
|
+
const suscriptions = resolverMainFile.subscriptionFields.length > 0
|
|
126
|
+
? `Subscription: { ${resolverMainFile.subscriptionFields
|
|
127
|
+
.map(printObjectMapping)
|
|
128
|
+
.join(',')} },`
|
|
129
|
+
: '';
|
|
130
|
+
result.files[resolverMainFilename] = {
|
|
131
|
+
__filetype: 'file',
|
|
132
|
+
content: `/* This file was automatically generated. DO NOT UPDATE MANUALLY. */
|
|
110
133
|
${(0, utils_1.printImportLine)({
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
isTypeImport: true,
|
|
135
|
+
module: relativePathToResolverTypes,
|
|
136
|
+
namedImports: [resolversTypeName],
|
|
137
|
+
emitLegacyCommonJSImports,
|
|
138
|
+
})}
|
|
139
|
+
${resolverMainFile.importLines.map((line) => line).join('\n')}
|
|
116
140
|
export const ${resolversIdentifier}: ${resolversTypeName} = {
|
|
117
141
|
${queries}
|
|
118
142
|
${mutations}
|
|
119
143
|
${suscriptions}
|
|
120
|
-
${
|
|
144
|
+
${resolverMainFile.objectTypes.map(printObjectMapping).join(',\n')}
|
|
121
145
|
}`,
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
mainImportIdentifier: resolversIdentifier,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
124
149
|
};
|
|
125
150
|
exports.addResolverMainFile = addResolverMainFile;
|
|
126
151
|
const printObjectMapping = ({ propertyName, identifierName, }) => `${propertyName}: ${identifierName}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addResolverMainFile.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFile.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,oCAKkB;
|
|
1
|
+
{"version":3,"file":"addResolverMainFile.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFile.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,oCAKkB;AAUlB,MAAM,wBAAwB,GAAG,GAAgB,EAAE,CAAC,CAAC;IACnD,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,EAAE;IAClB,kBAAkB,EAAE,EAAE;IACtB,WAAW,EAAE,EAAE;CAChB,CAAC,CAAC;AAEH;;GAEG;AACI,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;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const handleGraphQLObjectType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta }, { result, config: { graphQLObjectTypeResolversToGenerate } }) => {
|
|
5
|
+
const handleGraphQLObjectType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta, moduleName, }, { result, config: { graphQLObjectTypeResolversToGenerate, emitLegacyCommonJSImports }, }) => {
|
|
6
6
|
const variableStatement = `export const ${resolverName}: ${resolversTypeMeta.typeString} = {
|
|
7
7
|
/* Implement ${resolverName} resolver logic here */
|
|
8
8
|
};`;
|
|
@@ -13,10 +13,12 @@ const handleGraphQLObjectType = ({ fieldFilePath, resolverName, normalizedResolv
|
|
|
13
13
|
isTypeImport: true,
|
|
14
14
|
module: resolversTypeMeta.module,
|
|
15
15
|
namedImports: [resolversTypeMeta.typeNamedImport],
|
|
16
|
+
emitLegacyCommonJSImports,
|
|
16
17
|
})}
|
|
17
18
|
${variableStatement}`,
|
|
18
19
|
mainImportIdentifier: resolverName,
|
|
19
20
|
meta: {
|
|
21
|
+
moduleName,
|
|
20
22
|
normalizedResolverName,
|
|
21
23
|
variableStatement,
|
|
22
24
|
resolversToGenerate: graphQLObjectTypeResolversToGenerate[resolverName], // Array of all resolvers that may need type checking
|