diff --git a/src/helpers/build-annotations.ts b/src/helpers/build-annotations.ts index f0e6b95..f396ac2 100644 --- a/src/helpers/build-annotations.ts +++ b/src/helpers/build-annotations.ts @@ -21,7 +21,6 @@ import { import { buildDirectiveAnnotations } from "./build-directive-annotations"; import { CodegenConfig } from "../plugin"; import { TypeMetadata } from "./build-type-metadata"; -import { dependentTypeIsInScope } from "./dependent-type-is-in-scope"; export type DefinitionNode = | TypeDefinitionNode @@ -56,11 +55,9 @@ export function buildAnnotations({ const directiveAnnotations = definitionNode ? buildDirectiveAnnotations(definitionNode, config, description) : ""; - const unionAnnotation = - resolvedType?.baseType && - dependentTypeIsInScope(resolvedType.baseType, config) - ? `@${resolvedType.baseType}\n` - : ""; + const unionAnnotation = resolvedType?.annotation + ? `@${resolvedType.annotation}\n` + : ""; const annotations = [ unionAnnotation, diff --git a/src/helpers/build-type-metadata.ts b/src/helpers/build-type-metadata.ts index 1f6572d..4509ae9 100644 --- a/src/helpers/build-type-metadata.ts +++ b/src/helpers/build-type-metadata.ts @@ -21,12 +21,11 @@ import { } from "graphql"; import { getBaseTypeNode } from "@graphql-codegen/visitor-plugin-common"; import { wrapTypeWithModifiers } from "@graphql-codegen/java-common"; -import { dependentTypeIsInScope } from "./dependent-type-is-in-scope"; import { CodegenConfig } from "../plugin"; export interface TypeMetadata { typeName: string; - baseType?: string; + annotation?: string; defaultValue: string; isNullable: boolean; } @@ -48,7 +47,6 @@ export function buildTypeMetadata( defaultValue, isNullable, }; - const defaultTypeName = schemaType.name; if (isScalarType(schemaType)) { const scalars = [...KOTLIN_SCALARS, ...(config.extraScalars ?? [])]; @@ -61,18 +59,15 @@ export function buildTypeMetadata( typeName: buildListType(typeNode, scalarTypeName), }; } else if (isUnionType(schemaType)) { - const unionTypeName = dependentTypeIsInScope(defaultTypeName, config) - ? "Any" - : defaultTypeName; return { ...commonMetadata, - baseType: defaultTypeName, - typeName: buildListType(typeNode, unionTypeName), + annotation: schemaType.name, + typeName: buildListType(typeNode, "Any"), }; } else { return { ...commonMetadata, - typeName: buildListType(typeNode, defaultTypeName), + typeName: buildListType(typeNode, schemaType.name), }; } } diff --git a/test/unit/should_honor_dependentTypesInScope_config/expected.kt b/test/unit/should_honor_dependentTypesInScope_config/expected.kt index 0777167..bdc46d9 100644 --- a/test/unit/should_honor_dependentTypesInScope_config/expected.kt +++ b/test/unit/should_honor_dependentTypesInScope_config/expected.kt @@ -13,7 +13,8 @@ data class TypeInScope( val field: String? = null, @UnionInScope val unionInScopeField: Any? = null, - val unionOutOfScopeField: UnionOutOfScope? = null + @UnionOutOfScope + val unionOutOfScopeField: Any? = null ) @GraphQLUnion(