【发布时间】:2019-03-24 15:26:03
【问题描述】:
我正在使用 Apollo Angular 并托管一个支持 GraphQL 的服务器。 我试图实现的要求很简单。我需要传递一个对象作为我的请求的查询参数。这是我的要求:
return this.apollo
.watchQuery({
query: this.ListQuery,
variables: {
boundaries: {
east: boundaries.east,
west: boundaries.west,
north: boundaries.north,
south: boundaries.south,
}
},
fetchPolicy: 'no-cache',
})
.valueChanges.pipe(
map(({data}: any) => data.spots ? data.spots.map((spot) => new Spot(spot)) : [])
);
查询定义为:
query SpotList($boundaries: Boundaries) {
spots (boundaries: $boundaries) {
...
我在服务器上的架构定义为:
type Query {
spot(id: String!): Spot
spots(boundaries: Boundaries): [Spot!]!
}
input Boundaries {
east: Float
north: Float
south: Float
west: Float
}
当我的解析器函数
@Query()
async spots(boundaries) {
console.log(boundaries) //return undefined
我想知道是否允许输入作为查询中的参数,如果不允许,我应该使用哪种模式或实践。
如果可能,我不希望我的 query 在代码中明确包含每个参数。
谢谢!
编辑:已解决,来自 Nest Query 装饰器的解析器函数中的行为,它的解析器函数具有(对象、参数、上下文、信息)模式。
【问题讨论】:
-
您使用的是 Nest 服务器端吗?如果没有,您使用的是哪些库和/或框架?从您的代码中不清楚。
-
@DanielRearden 是的,它是 Nest,我认为 Nest 在这里不会成为问题,但问题是解析器函数的签名。
标签: angular rest graphql typeorm