【发布时间】:2019-04-27 14:17:53
【问题描述】:
所以我在 kotlin 中有这门课:
@Component
class UserResolver @Autowired
constructor(private val userService: UserService): GraphQLMutationResolver, GraphQLQueryResolver {
fun createUser(user: User): User {
userService.save(user)
return user
}
fun users(): Page<User> {
val pageable = QPageRequest(0, 10)
return userService.all(pageable)
}
}
我希望方法用户返回 Page 对象,我对 graphql 完全陌生。我尝试过这样的事情:
type Page {
number: Int
size: Int
numberOfElements: Int
content: []
hasContent: Boolean
isFirst: Boolean
isLast: Boolean
hasNext: Boolean
hasPrevoius: Boolean
totalPages: Int
totalElements: Float
}
但是我的 Spring Boot 应用程序无法启动,我不知道我的此类 https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html 的架构定义应该是什么样子。有人有想法吗?
编辑:错误是:
通过工厂方法实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化 [com.coxautodev.graphql.tools.SchemaParser]:工厂 方法“schemaParser”抛出异常;嵌套异常是 com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException: 类型 org.springframework.data.domain.Page
不能映射到 GraphQL 类型!由于 GraphQL-Java 交易 在运行时擦除类型,只有非参数化的类可以 表示一个 GraphQL 类型。这允许通过java进行反向查找 接口和联合类型中的类。
【问题讨论】:
-
你能分享日志中的错误输出吗?
-
@pipo_dev 已编辑
标签: kotlin spring-data graphql graphql-java