@eddeee888/gcg-typescript-resolver-files 0.18.0 → 0.18.2
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/dist/defineConfig.d.ts +1 -1
- package/dist/defineConfig.js +8 -0
- package/package.json +7 -3
- package/CHANGELOG.md +0 -816
- package/DEVELOPMENT.md +0 -49
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
- package/eslint.config.mjs +0 -22
- package/project.json +0 -8
- package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.ts +0 -109
- package/src/addVirtualTypesFileToTsMorphProject/index.ts +0 -1
- package/src/defineConfig.spec.ts +0 -76
- package/src/defineConfig.ts +0 -37
- package/src/generateResolverFiles/addExternalResolverImport.ts +0 -185
- package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.spec.ts +0 -1174
- package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.ts +0 -144
- package/src/generateResolverFiles/addResolverMainFiles.ts +0 -343
- package/src/generateResolverFiles/ensureEnumTypeResolversAreGenerated.ts +0 -51
- package/src/generateResolverFiles/generateResolverFiles.ts +0 -148
- package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.spec.ts +0 -127
- package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.ts +0 -25
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.spec.ts +0 -147
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.ts +0 -34
- package/src/generateResolverFiles/handleGraphQLEnumType.ts +0 -100
- package/src/generateResolverFiles/handleGraphQLInterfaceType.ts +0 -70
- package/src/generateResolverFiles/handleGraphQLObjectType.ts +0 -171
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.ts +0 -105
- package/src/generateResolverFiles/handleGraphQLScalarType.ts +0 -81
- package/src/generateResolverFiles/handleGraphQLUnionType.ts +0 -68
- package/src/generateResolverFiles/index.ts +0 -2
- package/src/generateResolverFiles/postProcessFiles.ts +0 -287
- package/src/generateResolverFiles/types.ts +0 -203
- package/src/generateResolverFiles/visitNamedType.ts +0 -66
- package/src/generateTypeDefsFiles/generateTypeDefsContent.ts +0 -15
- package/src/generateTypeDefsFiles/generateTypeDefsFiles.ts +0 -100
- package/src/generateTypeDefsFiles/index.ts +0 -1
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.ts +0 -361
- package/src/getGraphQLObjectTypeResolversToGenerate/getNodePropertyMap.spec.ts +0 -115
- package/src/getGraphQLObjectTypeResolversToGenerate/getNodePropertyMap.ts +0 -88
- package/src/getGraphQLObjectTypeResolversToGenerate/index.ts +0 -1
- package/src/index.ts +0 -3
- package/src/normalizeAddConfigPath/index.ts +0 -1
- package/src/normalizeAddConfigPath/normalizeAddConfigPath.ts +0 -29
- package/src/parseGraphQLSchema/index.ts +0 -2
- package/src/parseGraphQLSchema/normalizeResolverName.ts +0 -28
- package/src/parseGraphQLSchema/parseGraphQLSchema.ts +0 -531
- package/src/parseGraphQLSchema/parseLocationForOutputDir.ts +0 -76
- package/src/parseSources/index.ts +0 -1
- package/src/parseSources/parseSources.ts +0 -83
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.spec.ts +0 -789
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.ts +0 -197
- package/src/parseTypeMappers/index.ts +0 -1
- package/src/parseTypeMappers/parseTypeMappers.ts +0 -75
- package/src/preset.ts +0 -317
- package/src/utils/cwd.ts +0 -8
- package/src/utils/fmt.ts +0 -16
- package/src/utils/index.ts +0 -12
- package/src/utils/isMatchResolverNamePattern.ts +0 -27
- package/src/utils/isNativeNamedType.ts +0 -21
- package/src/utils/isRootObjectType.ts +0 -8
- package/src/utils/isWhitelistedModule.spec.ts +0 -71
- package/src/utils/isWhitelistedModule.ts +0 -21
- package/src/utils/logger.ts +0 -14
- package/src/utils/normalizeImportExtension.spec.ts +0 -42
- package/src/utils/normalizeImportExtension.ts +0 -16
- package/src/utils/normalizeRelativePath.ts +0 -6
- package/src/utils/parseLocationForWhitelistedModule.spec.ts +0 -130
- package/src/utils/parseLocationForWhitelistedModule.ts +0 -38
- package/src/utils/printImportLine.spec.ts +0 -150
- package/src/utils/printImportLine.ts +0 -78
- package/src/utils/relativeModulePath.ts +0 -7
- package/src/validateAndMergeParsedConfigs/index.ts +0 -1
- package/src/validateAndMergeParsedConfigs/validateAndMergeParsedConfigs.spec.ts +0 -211
- package/src/validateAndMergeParsedConfigs/validateAndMergeParsedConfigs.ts +0 -92
- package/src/validatePresetConfig/index.ts +0 -1
- package/src/validatePresetConfig/validatePresetConfig.spec.ts +0 -706
- package/src/validatePresetConfig/validatePresetConfig.ts +0 -571
- package/tsconfig.json +0 -14
- package/tsconfig.lib.json +0 -18
- package/tsconfig.spec.json +0 -20
- package/vite.config.ts +0 -24
package/src/defineConfig.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
|
-
import type { TypedPresetConfig } from './validatePresetConfig/index.js';
|
|
4
|
-
import { preset } from './preset.js';
|
|
5
|
-
|
|
6
|
-
export const defineConfig = (
|
|
7
|
-
presetConfig: TypedPresetConfig = {},
|
|
8
|
-
context: {
|
|
9
|
-
baseOutputDir?: string;
|
|
10
|
-
schema?: Types.ConfiguredOutput['schema'];
|
|
11
|
-
hooks?: Types.ConfiguredOutput['hooks'];
|
|
12
|
-
} = {}
|
|
13
|
-
): Pick<
|
|
14
|
-
Types.ConfiguredOutput,
|
|
15
|
-
'preset' | 'presetConfig' | 'watchPattern' | 'schema' | 'hooks'
|
|
16
|
-
> => {
|
|
17
|
-
const { schema, baseOutputDir = '', hooks } = context;
|
|
18
|
-
|
|
19
|
-
const mappersFileExtension =
|
|
20
|
-
presetConfig.mappersFileExtension || '.mappers.ts';
|
|
21
|
-
|
|
22
|
-
const watchPattern: string[] = [];
|
|
23
|
-
const mapperWatchPattern = path.posix.join(
|
|
24
|
-
baseOutputDir,
|
|
25
|
-
'**',
|
|
26
|
-
`*${mappersFileExtension}`
|
|
27
|
-
);
|
|
28
|
-
watchPattern.push(mapperWatchPattern);
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
preset,
|
|
32
|
-
presetConfig,
|
|
33
|
-
watchPattern,
|
|
34
|
-
schema,
|
|
35
|
-
hooks,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { normalizeRelativePath } from '../utils/index.js';
|
|
2
|
-
import type { GenerateResolverFilesContext } from './types.js';
|
|
3
|
-
|
|
4
|
-
interface AddExternalResolverImportParams {
|
|
5
|
-
moduleName: string;
|
|
6
|
-
relativePathFromBaseToModule: string[];
|
|
7
|
-
normalizedResolverName: string;
|
|
8
|
-
/*
|
|
9
|
-
* configImportSyntax has 2 forms
|
|
10
|
-
* 1. relative import: <relativePath>#{default as AliasIdentifier|named_import (as AliasIdentifier)}
|
|
11
|
-
* 2. absolute import: ~<absolutePath>#{default as AliasIdentifier|named_import (as AliasIdentifier)}
|
|
12
|
-
*/
|
|
13
|
-
configImportSyntax: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* addExternalResolverImport
|
|
18
|
-
*
|
|
19
|
-
* External resolvers are resolvers that are not managed by server preset:
|
|
20
|
-
* - unmanaged resolvers e.g. using config.externalResolvers or config.scalarsOverrides
|
|
21
|
-
* - resolvers that come from an external module e.g. `graphql-scalars`
|
|
22
|
-
*
|
|
23
|
-
* 1. parse external resolvers (originally from ) import syntax
|
|
24
|
-
* 2. dedupes any duplicated imports
|
|
25
|
-
* 3. declares the which identifier name to use for GraphQL object or resolver in identifierUsages
|
|
26
|
-
*/
|
|
27
|
-
export const addExternalResolverImport = (
|
|
28
|
-
params: AddExternalResolverImportParams,
|
|
29
|
-
{
|
|
30
|
-
result,
|
|
31
|
-
config: { emitLegacyCommonJSImports, importExtension },
|
|
32
|
-
}: GenerateResolverFilesContext
|
|
33
|
-
): void => {
|
|
34
|
-
const { importIdentifier, identifierUsage, moduleImport } =
|
|
35
|
-
parseImportSyntax(params);
|
|
36
|
-
|
|
37
|
-
let shouldPushIndentifierUsages = false;
|
|
38
|
-
result.externalImports[moduleImport] =
|
|
39
|
-
result.externalImports[moduleImport] ||
|
|
40
|
-
({
|
|
41
|
-
moduleName: params.moduleName,
|
|
42
|
-
relativePathFromBaseToModule: params.relativePathFromBaseToModule,
|
|
43
|
-
importLineMeta: {
|
|
44
|
-
isTypeImport: false,
|
|
45
|
-
module: moduleImport,
|
|
46
|
-
moduleType: 'preserve',
|
|
47
|
-
namedImports: [],
|
|
48
|
-
defaultImport: undefined,
|
|
49
|
-
emitLegacyCommonJSImports,
|
|
50
|
-
importExtension,
|
|
51
|
-
},
|
|
52
|
-
identifierUsages: [],
|
|
53
|
-
} satisfies GenerateResolverFilesContext['result']['externalImports'][number]);
|
|
54
|
-
|
|
55
|
-
const { importLineMeta, identifierUsages } =
|
|
56
|
-
result.externalImports[moduleImport];
|
|
57
|
-
|
|
58
|
-
switch (importIdentifier.__type) {
|
|
59
|
-
case 'default':
|
|
60
|
-
if (
|
|
61
|
-
importLineMeta.defaultImport &&
|
|
62
|
-
importLineMeta.defaultImport !== importIdentifier.defaultImport
|
|
63
|
-
) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`There can be only one default import from '${moduleImport}'. Current: ${importLineMeta.defaultImport}. New: ${importIdentifier.defaultImport}`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
importLineMeta.defaultImport = importIdentifier.defaultImport;
|
|
69
|
-
shouldPushIndentifierUsages = true;
|
|
70
|
-
break;
|
|
71
|
-
case 'named': {
|
|
72
|
-
const foundSameImport = importLineMeta.namedImports.find(
|
|
73
|
-
(existingImport) =>
|
|
74
|
-
typeof existingImport === 'string' &&
|
|
75
|
-
existingImport === importIdentifier.namedImport
|
|
76
|
-
);
|
|
77
|
-
if (!foundSameImport) {
|
|
78
|
-
importLineMeta.namedImports.push(importIdentifier.namedImport);
|
|
79
|
-
shouldPushIndentifierUsages = true;
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case 'namedWithAlias': {
|
|
84
|
-
const foundSameImport = importLineMeta.namedImports.find(
|
|
85
|
-
(existingImport) =>
|
|
86
|
-
typeof existingImport === 'object' &&
|
|
87
|
-
existingImport.identifierName === importIdentifier.identifierName &&
|
|
88
|
-
existingImport.propertyName === importIdentifier.propertyName
|
|
89
|
-
);
|
|
90
|
-
if (!foundSameImport) {
|
|
91
|
-
importLineMeta.namedImports.push({
|
|
92
|
-
propertyName: importIdentifier.propertyName,
|
|
93
|
-
identifierName: importIdentifier.identifierName,
|
|
94
|
-
});
|
|
95
|
-
shouldPushIndentifierUsages = true;
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
default:
|
|
100
|
-
// importIdentifier is `never` unless new __type is added
|
|
101
|
-
// i.e. this is here for typesafety
|
|
102
|
-
return importIdentifier;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (shouldPushIndentifierUsages) {
|
|
106
|
-
identifierUsages.push(identifierUsage);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const parseImportSyntax = ({
|
|
111
|
-
configImportSyntax,
|
|
112
|
-
normalizedResolverName,
|
|
113
|
-
}: AddExternalResolverImportParams): {
|
|
114
|
-
importIdentifier:
|
|
115
|
-
| { __type: 'default'; defaultImport: string }
|
|
116
|
-
| { __type: 'named'; namedImport: string }
|
|
117
|
-
| {
|
|
118
|
-
__type: 'namedWithAlias';
|
|
119
|
-
propertyName: string;
|
|
120
|
-
identifierName: string;
|
|
121
|
-
};
|
|
122
|
-
identifierUsage: { identifierName: string; normalizedResolverName: string };
|
|
123
|
-
moduleImport: string;
|
|
124
|
-
} => {
|
|
125
|
-
const isAbsoluteImport = configImportSyntax[0] === '~';
|
|
126
|
-
|
|
127
|
-
const importStringWithoutRelativity = isAbsoluteImport
|
|
128
|
-
? configImportSyntax.slice(1)
|
|
129
|
-
: configImportSyntax;
|
|
130
|
-
|
|
131
|
-
const [rawModuleName, importIdentifier] =
|
|
132
|
-
importStringWithoutRelativity.split('#');
|
|
133
|
-
|
|
134
|
-
const moduleImport = isAbsoluteImport
|
|
135
|
-
? rawModuleName
|
|
136
|
-
: normalizeRelativePath(rawModuleName);
|
|
137
|
-
|
|
138
|
-
if (importIdentifier.startsWith('default')) {
|
|
139
|
-
if (!importIdentifier.startsWith('default as ')) {
|
|
140
|
-
throw new Error(
|
|
141
|
-
`Invalid import syntax. "${configImportSyntax}": Default import must include identifier name e.g. moduleName#default as Identifier`
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
const [_, defaultImportIdentifier] = importIdentifier.split('default as ');
|
|
145
|
-
return {
|
|
146
|
-
importIdentifier: {
|
|
147
|
-
__type: 'default',
|
|
148
|
-
defaultImport: defaultImportIdentifier,
|
|
149
|
-
},
|
|
150
|
-
identifierUsage: {
|
|
151
|
-
identifierName: defaultImportIdentifier,
|
|
152
|
-
normalizedResolverName,
|
|
153
|
-
},
|
|
154
|
-
moduleImport,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const namedImportParts = importIdentifier.split(' as ');
|
|
159
|
-
if (namedImportParts.length === 1) {
|
|
160
|
-
return {
|
|
161
|
-
importIdentifier: {
|
|
162
|
-
__type: 'named',
|
|
163
|
-
namedImport: namedImportParts[0],
|
|
164
|
-
},
|
|
165
|
-
identifierUsage: {
|
|
166
|
-
identifierName: namedImportParts[0],
|
|
167
|
-
normalizedResolverName,
|
|
168
|
-
},
|
|
169
|
-
moduleImport,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
importIdentifier: {
|
|
175
|
-
__type: 'namedWithAlias',
|
|
176
|
-
propertyName: namedImportParts[0],
|
|
177
|
-
identifierName: namedImportParts[1],
|
|
178
|
-
},
|
|
179
|
-
identifierUsage: {
|
|
180
|
-
identifierName: namedImportParts[1],
|
|
181
|
-
normalizedResolverName,
|
|
182
|
-
},
|
|
183
|
-
moduleImport,
|
|
184
|
-
};
|
|
185
|
-
};
|