@@ -14,12 +14,21 @@ limitations under the License.
1414import { CodegenConfigWithDefaults } from "../config/build-config-with-defaults" ;
1515import { DefinitionNode } from "./build-annotations" ;
1616import { ConstDirectiveNode } from "graphql/language" ;
17- import { Kind } from "graphql" ;
17+ import { GraphQLSchema , isInputObjectType , Kind } from "graphql" ;
18+ import { shouldConsolidateTypes } from "../utils/should-consolidate-types" ;
19+ import { sanitizeName } from "../utils/sanitize-name" ;
1820
1921export function buildDirectiveAnnotations (
2022 definitionNode : DefinitionNode ,
2123 config : CodegenConfigWithDefaults ,
24+ schema : GraphQLSchema ,
2225) {
26+ const name = sanitizeName ( definitionNode . name . value ) ;
27+ const potentialMatchingInputType = schema . getType ( `${ name } Input` ) ;
28+ const typeWillBeConsolidated =
29+ isInputObjectType ( potentialMatchingInputType ) &&
30+ potentialMatchingInputType . astNode &&
31+ shouldConsolidateTypes ( potentialMatchingInputType . astNode , schema , config ) ;
2332 const directives = definitionNode . directives ?? [ ] ;
2433 return directives
2534 . map ( ( directive ) => {
@@ -29,9 +38,17 @@ export function buildDirectiveAnnotations(
2938 if ( federationReplacement ) return federationReplacement + "\n" ;
3039
3140 const directiveReplacementFromConfig = config . directiveReplacements ?. find (
32- ( { directive, definitionType } ) =>
33- directive === directiveName &&
34- ( ! definitionType || definitionType === definitionNode . kind ) ,
41+ ( { directive, definitionType } ) => {
42+ if ( directive !== directiveName ) return false ;
43+ if ( ! definitionType ) return true ;
44+ if ( definitionType !== definitionNode . kind ) return false ;
45+ if (
46+ definitionType !== Kind . INPUT_OBJECT_TYPE_DEFINITION &&
47+ definitionType !== Kind . OBJECT_TYPE_DEFINITION
48+ )
49+ return true ;
50+ return ! typeWillBeConsolidated ;
51+ } ,
3552 ) ;
3653 if ( ! directiveReplacementFromConfig ) return "" ;
3754 const kotlinAnnotations = buildKotlinAnnotations (
0 commit comments