Skip to content

Allow custom types created using @GraphQLType annotation be part of Lists #1326

Open
@srinikethr

Description

@srinikethr

Is your feature request related to a problem? Please describe.
The @GraphQLType annotation currently helps add a custom type by providing a typename and defining the type in the config when generating the schema. This works well when the custom type is used as the return type of a function/field. We're unable to use the custom type as part of a list return type at the moment.

what works:

data class SomeClass(
    @GraphQLType("CustomProperty")
    val property: Any
)

what doesn't:

data class SomeClass(
    @GraphQLType("CustomProperty")
    val property: List<Any>
)

While generating GraphQL types, the code checks for the @GraphQLType annotation and returns.

private fun getGraphQLType(
    generator: SchemaGenerator,
    kClass: KClass<*>,
    type: KType,
    typeInfo: GraphQLKTypeMetadata
): GraphQLType {
    val customTypeAnnotation = typeInfo.fieldAnnotations.getCustomTypeAnnotation()
    if (customTypeAnnotation != null) {
        return GraphQLTypeReference.typeRef(customTypeAnnotation.typeName)
    }

    return when {
        kClass.isEnum() -> @Suppress("UNCHECKED_CAST") (generateEnum(generator, kClass as KClass<Enum<*>>))
        kClass.isListType() -> generateList(generator, type, typeInfo)
        kClass.isUnion(typeInfo.fieldAnnotations) -> generateUnion(generator, kClass, typeInfo.fieldAnnotations.getUnionAnnotation())
        kClass.isInterface() -> generateInterface(generator, kClass)
        typeInfo.inputType -> generateInputObject(generator, kClass)
        else -> generateObject(generator, kClass)
    }
}

Describe the solution you'd like
The check for the custom type generation could perhaps be moved after the check for the list type generation (just like unions) thereby solving for the list of custom types use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: generatorIssue affects the schema generator and federation codetype: enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions