Skip to content

Resolver parameter typed by the resolver's own type variable fails on every query #880

Closed

Description

@oryan-block

A resolver method inherited from a generic class, whose parameter is the class's type variable, builds fine but fails on every query.

type Query {
    generic(input: GreetingInput!): String!
    plain(input: GreetingInput!): String!
}

input GreetingInput {
    name: String!
}
data class GreetingInput(val name: String)

abstract class InputResolver<I> : GraphQLQueryResolver {
    fun generic(input: I): String = "generic got $input"
}

class GreetingQuery : InputResolver<GreetingInput>() {
    fun plain(input: GreetingInput): String = "plain got $input"
}

{ plain(input: { name: "a" }) } returns plain got GreetingInput(name=a), but { generic(input: { name: "a" }) } fails with:

Exception while fetching data (/generic) : class sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to class java.lang.Class

Same on graphql-java 26.1 and 25.1, on current master.

The scanner resolves I to GreetingInput through the type resolver, which is why the build works. The data fetcher doesn't. MethodFieldResolver#createDataFetcher keeps method.genericParameterTypes[i] as is (the ?.apply { typeResolver.getRawClass(this) } throws the resolved type away), then shouldValueBeConverted calls JavaType.unwrap(), which does this as Class<*>. ArgumentConverter is built with the unresolved I too, so I think fixing only the cast would hand the method a Map.

Not the same as #333 / #468, those were generic input classes (A<B>) failing at scan time.

Found by the every-field check in #879, which excludes Query.generic in UnmappedInputFieldsTest until this is fixed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions