升级 graphql-spqr API 时 groovy.lang.MetaClass 上出现 TypeMappingException

问题描述 投票:0回答:1

我正在将 Groovy 项目从 Spring Boot 2.6.13 升级到 3.3.2,并将 graphql-spqr-spring-boot-starter 从 0.0.6 更新到 1.0.1。但是升级导致应用程序启动时出现以下错误。

核心问题似乎是graphql-spqr正在尝试检查groovy的内置metaClass属性的类型,并且不喜欢泛型类型。

链接的帮助页面可能意味着链接到此维基标题。但该帮助页面主要引用了 schemaGenerator,我认为我们的

@GraphQLApi
带注释的控制器不需要它。此外,我什至不知道如何指示元类类型,只是想忽略它。

@GraphQLApi
@Service
class GraphQLItemController {

    @Autowired
    ItemRepository itemRepository

    @GraphQLQuery
    ItemResponse fetchItems(@GraphQLArgument(name = "status") String status,
                                           @GraphQLArgument(name = "startDate") LocalDate startDate) {
        return itemRepository.getItemByStatusAndStartDate(status, startDate);
    }

堆栈跟踪:

Error creating bean with name 'graphQLExecutableSchema' defined in class path resource [io/leangen/graphql/spqr/spring/autoconfigure/BaseAutoConfiguration.class]: Failed to instantiate [io.leangen.graphql.ExecutableSchema]: Factory method 'graphQLExecutableSchema' threw exception with message: The type of member "getTheClass" belonging to groovy.lang.MetaClass is missing generic type parameters and can not be mapped. For details and possible solutions see https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLExecutableSchema' defined in class path resource [io/leangen/graphql/spqr/spring/autoconfigure/BaseAutoConfiguration.class]: Failed to instantiate [io.leangen.graphql.ExecutableSchema]: Factory method 'graphQLExecutableSchema' threw exception with message: The type of member "getTheClass" belonging to groovy.lang.MetaClass is missing generic type parameters and can not be mapped. For details and possible solutions see https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type
    at app//org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
    at app//org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355)
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185)
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
    at app//org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
    at app//org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at app//org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
    at app//org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
    at app//org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971)
    at app//org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)
    at app//org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at app//org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
    at app//org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at app//org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)
    at app//org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
    at app//org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
    at app//org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1463)
    at app//org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:553)
    at app//org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)
    at app//org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)
    at app//org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)
    at app//org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:152)
    at app//org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)
    at app//org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:191)
    at app//org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:130)
    at app//org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
    at app//org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:163)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$10(ClassBasedTestDescriptor.java:378)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:383)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$11(ClassBasedTestDescriptor.java:378)
    at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at [email protected]/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
    at [email protected]/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
    at [email protected]/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
    at [email protected]/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:377)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$instantiateAndPostProcessTestInstance$6(ClassBasedTestDescriptor.java:290)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:289)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:279)
    at [email protected]/java.util.Optional.orElseGet(Optional.java:364)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:278)
    at app//org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)
    at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:106)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:105)
    at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:69)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)
    at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1511)
    at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1511)
    at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
    at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at app//org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
    at app//org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
    at app//org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:124)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:99)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:94)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
    at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at [email protected]/java.lang.reflect.Method.invoke(Method.java:568)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:92)
    at jdk.proxy2/jdk.proxy2.$Proxy6.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:200)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:132)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:103)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:63)
    at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:121)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
    at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
    at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.leangen.graphql.ExecutableSchema]: Factory method 'graphQLExecutableSchema' threw exception with message: The type of member "getTheClass" belonging to groovy.lang.MetaClass is missing generic type parameters and can not be mapped. For details and possible solutions see https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type
    at app//org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178)
    at app//org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
    ... 110 more
Caused by: io.leangen.graphql.metadata.exceptions.TypeMappingException: The type of member "getTheClass" belonging to groovy.lang.MetaClass is missing generic type parameters and can not be mapped. For details and possible solutions see https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type
    at app//io.leangen.graphql.metadata.exceptions.TypeMappingException.ambiguousMemberType(TypeMappingException.java:34)
    at app//io.leangen.graphql.metadata.strategy.query.AbstractResolverBuilder.getReturnType(AbstractResolverBuilder.java:82)
    at app//io.leangen.graphql.metadata.strategy.query.PublicResolverBuilder.lambda$buildMethodInvokers$4(PublicResolverBuilder.java:116)
    at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at [email protected]/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at [email protected]/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at app//io.leangen.graphql.metadata.strategy.query.PublicResolverBuilder.buildMethodInvokers(PublicResolverBuilder.java:130)
    at app//io.leangen.graphql.metadata.strategy.query.PublicResolverBuilder.buildQueryResolvers(PublicResolverBuilder.java:85)
    at app//io.leangen.graphql.generator.OperationRegistry.lambda$buildQueryResolvers$16(OperationRegistry.java:164)
    at app//io.leangen.graphql.generator.OperationRegistry.lambda$buildResolvers$19(OperationRegistry.java:184)
    at [email protected]/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
    at [email protected]/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at [email protected]/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
    at [email protected]/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
    at [email protected]/java.util.Collections$2.tryAdvance(Collections.java:4853)
    at [email protected]/java.util.Collections$2.forEachRemaining(Collections.java:4861)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at [email protected]/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at app//io.leangen.graphql.generator.OperationRegistry.buildResolvers(OperationRegistry.java:186)
    at app//io.leangen.graphql.generator.OperationRegistry.buildQueryResolvers(OperationRegistry.java:163)
    at app//io.leangen.graphql.generator.OperationRegistry.buildNestedQueries(OperationRegistry.java:159)
    at app//io.leangen.graphql.generator.OperationRegistry.getNestedQueries(OperationRegistry.java:135)
    at app//io.leangen.graphql.generator.OperationRegistry.getChildQueries(OperationRegistry.java:141)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.getFields(ObjectTypeMapper.java:97)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.toGraphQLType(ObjectTypeMapper.java:42)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.toGraphQLType(ObjectTypeMapper.java:32)
    at app//io.leangen.graphql.generator.mapping.common.CachingMapper.toGraphQLType(CachingMapper.java:31)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLType(OperationMapper.java:202)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLType(OperationMapper.java:187)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLField(OperationMapper.java:147)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLField(OperationMapper.java:178)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.lambda$getFields$5(ObjectTypeMapper.java:98)
    at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at [email protected]/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at [email protected]/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.getFields(ObjectTypeMapper.java:99)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.toGraphQLType(ObjectTypeMapper.java:42)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.toGraphQLType(ObjectTypeMapper.java:32)
    at app//io.leangen.graphql.generator.mapping.common.CachingMapper.toGraphQLType(CachingMapper.java:31)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLType(OperationMapper.java:202)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLType(OperationMapper.java:187)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLField(OperationMapper.java:147)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLField(OperationMapper.java:178)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.lambda$getFields$5(ObjectTypeMapper.java:98)
    at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at [email protected]/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at [email protected]/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.getFields(ObjectTypeMapper.java:99)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.toGraphQLType(ObjectTypeMapper.java:42)
    at app//io.leangen.graphql.generator.mapping.common.ObjectTypeMapper.toGraphQLType(ObjectTypeMapper.java:32)
    at app//io.leangen.graphql.generator.mapping.common.CachingMapper.toGraphQLType(CachingMapper.java:31)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLType(OperationMapper.java:202)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLType(OperationMapper.java:187)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLField(OperationMapper.java:147)
    at app//io.leangen.graphql.generator.OperationMapper.toGraphQLField(OperationMapper.java:178)
    at app//io.leangen.graphql.generator.OperationMapper.lambda$generateQueries$0(OperationMapper.java:84)
    at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at [email protected]/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at [email protected]/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at [email protected]/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at app//io.leangen.graphql.generator.OperationMapper.generateQueries(OperationMapper.java:85)
    at app//io.leangen.graphql.generator.OperationMapper.<init>(OperationMapper.java:65)
    at app//io.leangen.graphql.GraphQLSchemaGenerator.generateExecutable(GraphQLSchemaGenerator.java:953)
    at app//io.leangen.graphql.spqr.spring.autoconfigure.BaseAutoConfiguration.graphQLExecutableSchema(BaseAutoConfiguration.java:265)
    at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at [email protected]/java.lang.reflect.Method.invoke(Method.java:568)
    at app//org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
    ... 111 more
Caused by: io.leangen.graphql.metadata.exceptions.TypeMappingException: Type java.lang.Class is unbounded or missing generic type parameters
    at app//io.leangen.graphql.metadata.exceptions.TypeMappingException.ambiguousType(TypeMappingException.java:30)
    at app//io.leangen.graphql.util.ClassUtils.completeGenerics(ClassUtils.java:662)
    at app//io.leangen.graphql.metadata.strategy.type.DefaultTypeTransformer.transform(DefaultTypeTransformer.java:28)
    at app//io.leangen.graphql.metadata.strategy.query.AbstractResolverBuilder.getReturnType(AbstractResolverBuilder.java:80)
    ... 204 more
groovy graphql-spqr graphql-spqr-spring-boot-starter
1个回答
0
投票

我通过设置自定义包含策略来解决这个问题。这扩展了使用

@GraphQLIgnore
注释进行过滤的现有逻辑,以使库忽略 Groovy 方法。

import groovy.util.logging.Slf4j
import io.leangen.graphql.metadata.strategy.DefaultInclusionStrategy
import io.leangen.graphql.metadata.strategy.InclusionStrategy
import io.leangen.graphql.spqr.spring.autoconfigure.SpqrProperties
import org.codehaus.groovy.ast.ClassNode
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

import java.lang.reflect.AnnotatedElement
import java.lang.reflect.Method

@Slf4j
@Configuration
class GraphQLConfig {
    class CustomInclusionStrategy extends DefaultInclusionStrategy {
        CustomInclusionStrategy(SpqrProperties spqrProperties) {
            super(spqrProperties.getBasePackages());
        }

        @Override
        protected boolean isIgnored(AnnotatedElement element) {
            return super.isIgnored(element) || isIgnoredType(element)
        }

        protected boolean isIgnoredType(AnnotatedElement element) {
            return (element instanceof Method) && [
                    MetaClass.class,
                    ClassNode.class
            ].contains(((Method) element).getReturnType());
        }
    };

    @Bean
    InclusionStrategy inclusionStrategy(SpqrProperties spqrProperties) {
        return new CustomInclusionStrategy(spqrProperties);
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.