Skip to content

Throw at build for resolvers that can't be called on their JDK dynamic proxy in 15.0.0 #868

Open

Description

@oryan-block

Since #853, tools warns at build when a resolver is a JDK dynamic proxy (e.g. Spring AOP with proxyTargetClass = false) and a field resolves to a method or public field the proxy can't call. Spring4AopProxyHandler makes the scanner match fields against the target class, but the proxy only implements the target's interfaces, so every query of those fields fails:

class ProxiedQuery : GraphQLQueryResolver {
    fun test() = "ok"
}

val resolver = ProxyFactory(ProxiedQuery()).proxy as GraphQLQueryResolver

object of type jdk.proxy2.$Proxy2 is not an instance of ProxiedQuery

For a public field it's Can not get final int field ProxiedQuery.count on jdk.proxy2.$Proxy2. For a field, the message says to add a getter as well, since class-based proxies don't pass field reads to the target either. The build logs this once per field:

Field 'Query.test' resolves to scenarios.ProxiedQuery.test, but the resolver is a jdk.proxy2.$Proxy2, which isn't a scenarios.ProxiedQuery, so every query of the field will fail. This happens with JDK dynamic proxies, which only implement interfaces. Use class-based proxies instead, e.g. proxyTargetClass = true in Spring.

A field that can never work should fail the build. But a schema whose broken field is never queried builds and runs fine today, so throwing has to wait for a major release.

What to change

  • replace the warning in SchemaClassScanner#warnIfNotCallableOnResolver with a FieldResolverError that keeps the same message
  • throw it even with allowUnimplementedResolvers or missingResolverDataFetcher set, since the resolver exists but can't be called
  • turn SchemaParserTest."parser handles spring AOP proxied resolvers by default", which only builds today, into a test for the error
  • mention it in the 15.0.0 release notes

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