Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/helpers/build-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 4 additions & 9 deletions src/helpers/build-type-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -48,7 +47,6 @@ export function buildTypeMetadata(
defaultValue,
isNullable,
};
const defaultTypeName = schemaType.name;

if (isScalarType(schemaType)) {
const scalars = [...KOTLIN_SCALARS, ...(config.extraScalars ?? [])];
Expand All @@ -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),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down