@graphql-codegen/visitor-plugin-common 6.0.1 → 6.1.0-alpha-20251001144629-b40a8cbfdf8586bb3e4a3d39cbd6c6b0d4f1bb74
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.
|
@@ -55,6 +55,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
55
55
|
mapOrStr: rawConfig.enumValues,
|
|
56
56
|
}),
|
|
57
57
|
addUnderscoreToArgsType: (0, utils_js_1.getConfigValue)(rawConfig.addUnderscoreToArgsType, false),
|
|
58
|
+
addInterfaceFieldResolverTypes: (0, utils_js_1.getConfigValue)(rawConfig.addInterfaceFieldResolverTypes, false),
|
|
58
59
|
contextType: (0, mappers_js_1.parseMapper)(rawConfig.contextType || 'any', 'ContextType'),
|
|
59
60
|
fieldContextTypes: (0, utils_js_1.getConfigValue)(rawConfig.fieldContextTypes, []),
|
|
60
61
|
directiveContextTypes: (0, utils_js_1.getConfigValue)(rawConfig.directiveContextTypes, []),
|
|
@@ -1008,7 +1009,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
1008
1009
|
// So, we filter out the normal fields declared on the Interface and add the __resolveReference resolver.
|
|
1009
1010
|
const fields = node.fields.map(({ printContent }) => printContent(node, this.config.avoidOptionals.resolvers));
|
|
1010
1011
|
for (const field of fields) {
|
|
1011
|
-
if (field.meta.federation?.isResolveReference) {
|
|
1012
|
+
if (field.meta.federation?.isResolveReference || this.config.addInterfaceFieldResolverTypes) {
|
|
1012
1013
|
blockFields.push(field.value);
|
|
1013
1014
|
}
|
|
1014
1015
|
}
|
|
@@ -51,6 +51,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
51
51
|
mapOrStr: rawConfig.enumValues,
|
|
52
52
|
}),
|
|
53
53
|
addUnderscoreToArgsType: getConfigValue(rawConfig.addUnderscoreToArgsType, false),
|
|
54
|
+
addInterfaceFieldResolverTypes: getConfigValue(rawConfig.addInterfaceFieldResolverTypes, false),
|
|
54
55
|
contextType: parseMapper(rawConfig.contextType || 'any', 'ContextType'),
|
|
55
56
|
fieldContextTypes: getConfigValue(rawConfig.fieldContextTypes, []),
|
|
56
57
|
directiveContextTypes: getConfigValue(rawConfig.directiveContextTypes, []),
|
|
@@ -1004,7 +1005,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
1004
1005
|
// So, we filter out the normal fields declared on the Interface and add the __resolveReference resolver.
|
|
1005
1006
|
const fields = node.fields.map(({ printContent }) => printContent(node, this.config.avoidOptionals.resolvers));
|
|
1006
1007
|
for (const field of fields) {
|
|
1007
|
-
if (field.meta.federation?.isResolveReference) {
|
|
1008
|
+
if (field.meta.federation?.isResolveReference || this.config.addInterfaceFieldResolverTypes) {
|
|
1008
1009
|
blockFields.push(field.value);
|
|
1009
1010
|
}
|
|
1010
1011
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0-alpha-20251001144629-b40a8cbfdf8586bb3e4a3d39cbd6c6b0d4f1bb74",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"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"
|
|
6
6
|
},
|
|
@@ -16,6 +16,7 @@ export interface ParsedResolversConfig extends ParsedConfig {
|
|
|
16
16
|
defaultMapper: ParsedMapper | null;
|
|
17
17
|
avoidOptionals: NormalizedAvoidOptionalsConfig;
|
|
18
18
|
addUnderscoreToArgsType: boolean;
|
|
19
|
+
addInterfaceFieldResolverTypes: boolean;
|
|
19
20
|
enumValues: ParsedEnumValuesMap;
|
|
20
21
|
resolverTypeWrapperSignature: string;
|
|
21
22
|
federation: boolean;
|
|
@@ -637,6 +638,40 @@ export interface RawResolversConfig extends RawConfig {
|
|
|
637
638
|
* This may not work for cases where provided default mapper types are also nested e.g. `defaultMapper: DeepPartial<{T}>` or `defaultMapper: Partial<{T}>`.
|
|
638
639
|
*/
|
|
639
640
|
avoidCheckingAbstractTypesRecursively?: boolean;
|
|
641
|
+
/**
|
|
642
|
+
* @description If true, add field resolver types to Interfaces.
|
|
643
|
+
* By default, GraphQL Interfaces does not trigger any field resolvers,
|
|
644
|
+
* meaning every implementing type must implement the same resolver for the shared fields.
|
|
645
|
+
*
|
|
646
|
+
* Some tools provide a way to change the default behaviour by making GraphQL Objects inherit
|
|
647
|
+
* missing resolvers from their Interface types. In these cases, it is fine to turn this option to true.
|
|
648
|
+
*
|
|
649
|
+
* For example, if you are using @graphql-tools/schema#makeExecutableSchema with `inheritResolversFromInterfaces: true`,
|
|
650
|
+
* you can make `addInterfaceFieldResolverTypes: true` as well
|
|
651
|
+
* https://the-guild.dev/graphql/tools/docs/generate-schema#makeexecutableschema
|
|
652
|
+
*
|
|
653
|
+
* @exampleMarkdown
|
|
654
|
+
* ```ts filename="codegen.ts"
|
|
655
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
656
|
+
*
|
|
657
|
+
* const config: CodegenConfig = {
|
|
658
|
+
* // ...
|
|
659
|
+
* generates: {
|
|
660
|
+
* 'path/to/file': {
|
|
661
|
+
* plugins: ['typescript', 'typescript-resolver'],
|
|
662
|
+
* config: {
|
|
663
|
+
* addInterfaceFieldResolverTypes: true,
|
|
664
|
+
* },
|
|
665
|
+
* },
|
|
666
|
+
* },
|
|
667
|
+
* };
|
|
668
|
+
* export default config;
|
|
669
|
+
* ```
|
|
670
|
+
*
|
|
671
|
+
* @type boolean
|
|
672
|
+
* @default false
|
|
673
|
+
*/
|
|
674
|
+
addInterfaceFieldResolverTypes?: boolean;
|
|
640
675
|
/**
|
|
641
676
|
* @ignore
|
|
642
677
|
*/
|
|
@@ -16,6 +16,7 @@ export interface ParsedResolversConfig extends ParsedConfig {
|
|
|
16
16
|
defaultMapper: ParsedMapper | null;
|
|
17
17
|
avoidOptionals: NormalizedAvoidOptionalsConfig;
|
|
18
18
|
addUnderscoreToArgsType: boolean;
|
|
19
|
+
addInterfaceFieldResolverTypes: boolean;
|
|
19
20
|
enumValues: ParsedEnumValuesMap;
|
|
20
21
|
resolverTypeWrapperSignature: string;
|
|
21
22
|
federation: boolean;
|
|
@@ -637,6 +638,40 @@ export interface RawResolversConfig extends RawConfig {
|
|
|
637
638
|
* This may not work for cases where provided default mapper types are also nested e.g. `defaultMapper: DeepPartial<{T}>` or `defaultMapper: Partial<{T}>`.
|
|
638
639
|
*/
|
|
639
640
|
avoidCheckingAbstractTypesRecursively?: boolean;
|
|
641
|
+
/**
|
|
642
|
+
* @description If true, add field resolver types to Interfaces.
|
|
643
|
+
* By default, GraphQL Interfaces does not trigger any field resolvers,
|
|
644
|
+
* meaning every implementing type must implement the same resolver for the shared fields.
|
|
645
|
+
*
|
|
646
|
+
* Some tools provide a way to change the default behaviour by making GraphQL Objects inherit
|
|
647
|
+
* missing resolvers from their Interface types. In these cases, it is fine to turn this option to true.
|
|
648
|
+
*
|
|
649
|
+
* For example, if you are using @graphql-tools/schema#makeExecutableSchema with `inheritResolversFromInterfaces: true`,
|
|
650
|
+
* you can make `addInterfaceFieldResolverTypes: true` as well
|
|
651
|
+
* https://the-guild.dev/graphql/tools/docs/generate-schema#makeexecutableschema
|
|
652
|
+
*
|
|
653
|
+
* @exampleMarkdown
|
|
654
|
+
* ```ts filename="codegen.ts"
|
|
655
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
656
|
+
*
|
|
657
|
+
* const config: CodegenConfig = {
|
|
658
|
+
* // ...
|
|
659
|
+
* generates: {
|
|
660
|
+
* 'path/to/file': {
|
|
661
|
+
* plugins: ['typescript', 'typescript-resolver'],
|
|
662
|
+
* config: {
|
|
663
|
+
* addInterfaceFieldResolverTypes: true,
|
|
664
|
+
* },
|
|
665
|
+
* },
|
|
666
|
+
* },
|
|
667
|
+
* };
|
|
668
|
+
* export default config;
|
|
669
|
+
* ```
|
|
670
|
+
*
|
|
671
|
+
* @type boolean
|
|
672
|
+
* @default false
|
|
673
|
+
*/
|
|
674
|
+
addInterfaceFieldResolverTypes?: boolean;
|
|
640
675
|
/**
|
|
641
676
|
* @ignore
|
|
642
677
|
*/
|