@@ -16,16 +16,19 @@ import { buildAnnotations } from "../helpers/build-annotations";
1616import { indent } from "@graphql-codegen/visitor-plugin-common" ;
1717import { buildTypeMetadata } from "../helpers/build-type-metadata" ;
1818import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-definition" ;
19- import { getDependentInterfaceNames } from "../helpers/dependent-type-utils" ;
19+ import {
20+ getDependentInterfaceNames ,
21+ getDependentUnionsForType ,
22+ } from "../helpers/dependent-type-utils" ;
2023import { isResolverType } from "../helpers/is-resolver-type" ;
2124import { buildFieldDefinition } from "../helpers/build-field-definition" ;
2225import { isExternalField } from "../helpers/is-external-field" ;
23- import { CodegenConfig } from "../plugin " ;
26+ import { CodegenConfigWithDefaults } from "../helpers/build-config-with-defaults " ;
2427
2528export function buildObjectTypeDefinition (
2629 node : ObjectTypeDefinitionNode ,
2730 schema : GraphQLSchema ,
28- config : CodegenConfig ,
31+ config : CodegenConfigWithDefaults ,
2932) {
3033 if ( ! shouldIncludeTypeDefinition ( node , config ) ) {
3134 return "" ;
@@ -36,33 +39,38 @@ export function buildObjectTypeDefinition(
3639 definitionNode : node ,
3740 } ) ;
3841 const name = node . name . value ;
39- const interfacesToInherit = getDependentInterfaceNames ( node ) ;
42+ const dependentInterfaces = getDependentInterfaceNames ( node ) ;
43+ const dependentUnions = getDependentUnionsForType ( schema , node ) ;
44+ const interfacesToInherit =
45+ config . unionGeneration === "MARKER_INTERFACE"
46+ ? dependentInterfaces . concat ( dependentUnions )
47+ : dependentInterfaces ;
4048 const interfaceInheritance = `${ interfacesToInherit . length ? ` : ${ interfacesToInherit . join ( ", " ) } ` : "" } ` ;
4149
4250 if ( isResolverType ( node , config ) ) {
4351 return `${ annotations } @GraphQLIgnore\ninterface ${ name } ${ interfaceInheritance } {
44- ${ getClassMembers ( { node, schema, config } ) }
52+ ${ getDataClassMembers ( { node, schema, config } ) }
4553}
4654
4755${ annotations } @GraphQLIgnore\ninterface ${ name } CompletableFuture {
48- ${ getClassMembers ( { node, schema, config, completableFuture : true } ) }
56+ ${ getDataClassMembers ( { node, schema, config, completableFuture : true } ) }
4957}` ;
5058 }
5159
5260 return `${ annotations } data class ${ name } (
53- ${ getClassMembers ( { node, schema, config } ) }
61+ ${ getDataClassMembers ( { node, schema, config } ) }
5462)${ interfaceInheritance } ` ;
5563}
5664
57- function getClassMembers ( {
65+ function getDataClassMembers ( {
5866 node,
5967 schema,
6068 config,
6169 completableFuture,
6270} : {
6371 node : ObjectTypeDefinitionNode ;
6472 schema : GraphQLSchema ;
65- config : CodegenConfig ;
73+ config : CodegenConfigWithDefaults ;
6674 completableFuture ?: boolean ;
6775} ) {
6876 const resolverType = isResolverType ( node , config ) ;
0 commit comments