Skip to content
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

[Question] Help with FieldResolverError on classes from external libraries #407

Closed
gpabon-carecloud opened this issue Jun 17, 2020 · 2 comments
Labels

Comments

@gpabon-carecloud
Copy link

gpabon-carecloud commented Jun 17, 2020

I am trying to use graphql-java-tools to wrap classes that are provided by an external library (In this case HAPI FHIR models). My intent is to provide some queries that will return objects that are structured based on an external library, but the FieldResolver is failing in identifying correctly the inheritance for those classes.

Given I'm using an external library I'm not able to modify the structure of those models. At some point, the resolver decides to look for methods on an interface instead of a parent class.

dependencies

<dependency>
	<groupId>com.graphql-java-kickstart</groupId>
	<artifactId>graphql-spring-boot-starter</artifactId>
	<version>7.0.1</version>
	<scope>runtime</scope>
</dependency>
<dependency>
	<groupId>com.graphql-java-kickstart</groupId>
	<artifactId>graphql-java-tools</artifactId>
	<version>6.0.2</version>
</dependency>
<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-structures-dstu3</artifactId>
	<version>5.0.2</version>
</dependency>

schema.graphqls (Simplified to only 1 property)

type Meta {
    id: String
}

type Device {
    meta: Meta
}

type Query {
    hello: Device!
}

Resolver:

package com.example.demo;

import graphql.kickstart.tools.GraphQLQueryResolver;
import org.hl7.fhir.dstu3.model.Device;
import org.springframework.stereotype.Component;

@Component
public class DeviceResolver implements GraphQLQueryResolver {
    public Device getHello() {
        return new Device();
    }
}

The error this generates:

Caused by: graphql.kickstart.tools.FieldResolverError: No method or field found as defined in schema <unknown>:2 with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:

  org.hl7.fhir.instance.model.api.IBaseMetaType.id()
  org.hl7.fhir.instance.model.api.IBaseMetaType.getId()
  org.hl7.fhir.instance.model.api.IBaseMetaType.id
	at graphql.kickstart.tools.FieldResolverScanner.missingFieldResolver(FieldResolverScanner.kt:59) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.FieldResolverScanner.findFieldResolver(FieldResolverScanner.kt:50) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.SchemaClassScanner.scanResolverInfoForPotentialMatches(SchemaClassScanner.kt:244) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.SchemaClassScanner.scanQueueItemForPotentialMatches(SchemaClassScanner.kt:238) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.SchemaClassScanner.scanQueue(SchemaClassScanner.kt:90) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.SchemaClassScanner.scanForClasses(SchemaClassScanner.kt:68) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.SchemaParserBuilder.scan(SchemaParserBuilder.kt:166) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.SchemaParserBuilder.build(SchemaParserBuilder.kt:207) ~[graphql-java-tools-6.0.2.jar:na]
	at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration.schemaParser(GraphQLJavaToolsAutoConfiguration.java:146) ~[graphql-kickstart-spring-boot-autoconfigure-tools-7.0.1.jar:na]
	at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$f9bbdd4.CGLIB$schemaParser$3(<generated>) ~[graphql-kickstart-spring-boot-autoconfigure-tools-7.0.1.jar:na]
	at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$f9bbdd4$$FastClassBySpringCGLIB$$10a413ad.invoke(<generated>) ~[graphql-kickstart-spring-boot-autoconfigure-tools-7.0.1.jar:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$f9bbdd4.schemaParser(<generated>) ~[graphql-kickstart-spring-boot-autoconfigure-tools-7.0.1.jar:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	... 139 common frames omitted

This makes sense, given that property is in the parent class of Meta, but this seems to be looking into the interface instead (IBaseMeta). Both the Device class and the Meta class are correct, and I'm able to see the methods from the class correctly:

Screen Shot 2020-06-17 at 5 04 47 PM

I created a sample repository with the offending code: https://github.com/gpabon-carecloud/graphql-fhir

This commit contains all the modifications from a base Initialz project: gpabon-carecloud/graphql-fhir@68a6d31

@vojtapol vojtapol added the bug label Jun 17, 2020
@vojtapol
Copy link
Member

This could be a bug indeed. We welcome contributions, even partial PRs are fine.

KammererTob added a commit to KammererTob/graphql-java-tools that referenced this issue Jul 12, 2020
KammererTob added a commit to KammererTob/graphql-java-tools that referenced this issue Jul 12, 2020
KammererTob added a commit to KammererTob/graphql-java-tools that referenced this issue Jul 12, 2020
…raphql-java-kickstart#407

# Conflicts:
#	src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
#	src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy
@KammererTob KammererTob mentioned this issue Jul 12, 2020
2 tasks
@vojtapol
Copy link
Member

Fixed by 647885c

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

Successfully merging a pull request may close this issue.

2 participants