Skip to content

Cannot find field from parent interface #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yukchan opened this issue Oct 3, 2018 · 2 comments
Closed

Cannot find field from parent interface #188

yukchan opened this issue Oct 3, 2018 · 2 comments
Labels
Milestone

Comments

@yukchan
Copy link

yukchan commented Oct 3, 2018

a FieldResolverError is thrown when the field is defined at parent interface

at com.coxautodev.graphql.tools.FieldResolverScanner.missingFieldResolver(FieldResolverScanner.kt:55)
at com.coxautodev.graphql.tools.FieldResolverScanner.findFieldResolver(FieldResolverScanner.kt:46)
at com.coxautodev.graphql.tools.SchemaClassScanner.scanResolverInfoForPotentialMatches(SchemaClassScanner.kt:231)
@yukchan
Copy link
Author

yukchan commented Oct 3, 2018

I guess getAllMethod should get the methods from interfaces as well:

internal class FieldResolverScanner(val options: SchemaParserOptions) {

private val allowedLastArgumentTypes = listOfNotNull(DataFetchingEnvironment::class.java, options.contextClass)

companion object {
    private val log = LoggerFactory.getLogger(FieldResolverScanner::class.java)

    fun getAllMethods(type: JavaType) =
            (type.unwrap().declaredMethods.toList()
                    + ClassUtils.getAllInterfaces(type.unwrap()).flatMap { it.methods.toList() }
                    + ClassUtils.getAllSuperclasses(type.unwrap()).flatMap { it.methods.toList() })
                    .asSequence()
                    .filter { !it.isSynthetic }
                    .filter { !Modifier.isPrivate(it.modifiers) }
                    // discard any methods that are coming off the root of the class hierarchy
                    // to avoid issues with duplicate method declarations
                    .filter { it.declaringClass != Object::class.java }
                    .toList()
}

}

@yukchan
Copy link
Author

yukchan commented Nov 2, 2018

It is at line 24 of FieldResolverScanner.kt

Consider the following case:
[java]
public interface A { int getX(); }
public interface B extends A { int getY(); }

[graphql]
type A {
x: Int
y: Int
}

If we define B in graphql schema, the library cannot read getX() from interface A and throw FieldResolverError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants