Skip to content

Kotlin isX properties access #3010

@turboezh

Description

@turboezh

Related: #130, #2991, #2994.

Describe the bug

If some boolean GraphQL field named isX and backed by DTO isX() getter, PropertyFetchingImpl fails to find such a getter.
Instead it tries isIsX().

Why (boolean) getter named so?

The problem is related to Kotlin properties:

If the name of the property starts with is, a different name mapping rule is used: the name of the getter will be the same as the property name... This rule applies for properties of any type, not just Boolean.

https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties

How to fix

Property fetcher should not add is prefix if a field already prefixed with it.
Or more general way: it should try getter without a prefix at all (getter name == field name) as a last resort.

To Reproduce

Schema:

type TheType {
    isAwesome: Boolean
}

Kotlin:

/**
 * DTO
 */
class TheType(
    val isAwesome: Boolean?
)

Java:

/**
 * DTO
 */
public class TheType {
    private Boolean isAwesome;

    public TheType(Boolean isAwesome) {
        this.isAwesome = isAwesome;
    }

    public Boolean isAwesome() {
        return isAwesome;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions