【发布时间】:2020-01-08 12:12:04
【问题描述】:
我刚开始探索 graphql,所以在使用该框架时遇到了最初的问题。这篇文章中使用的代码托管在 github @https://github.com/samshers/graphQL-Starter
我的 api 的 graphql 架构如下:
schema {
query: Query
}
type Query {
allCities: [City]
city(name: String): City
state(name: String): State
}
type City {
name: String
population: String
state: State
}
type State {
name: String
population: String
country: Country
cities : [City]
}
type Country {
name: String
population: String
}
我要执行的查询是 -
{
city(name: "BayArea") {
name
population
state {
name
population
cities {
name
}
country {
name
population
}
}
}
}
我得到的结果是 -
{
"errors": [],
"data": {
"city": {
"name": "BayArea",
"population": "7200000",
"state": {
"name": "CA",
"population": "39900000",
"cities": [],
"country": {
"name": "USA",
"population": "330000000"
}
}
}
},
"extensions": null
}
问题在于这部分结果 -
“人口”:“39900000”,
“城市”:[],
“国家”:{
我确实希望城市数组会相应地填充特定州的所有可用城市。
如果有人能指出问题是否与架构/查询或 jpa 映射有关,将不胜感激。如前所述,代码托管在 github @https://github.com/samshers/graphQL-Starter
【问题讨论】:
-
我看到您使用的是古代版本的 graphql-java-tools 及其 Spring Boot starter。这些工件的命名完全是一团糟……但新版本位于
com.graphql-java-kickstartgroup id 下,因此您应该改用它们。请注意,Kickstarter 项目独立于 graphql-java(核心 Java 库)团队,以及他们自己的 Spring Boot starter。此外,您标记了 graphql-spqr 但您根本没有使用它。
标签: spring-boot spring-data-jpa graphql graphql-java