我正在使用阿波罗角和托管一个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查询装饰器,它有一个(对象,参数,上下文,信息)模式到它的解析器功能。
发布于 2018-10-19 18:02:16
正如我在问题中提到的,我使用的是Nest服务器端,@nestjs/graphql引入的Decorator @Query为解析器函数提供了一个特殊的签名。
https://stackoverflow.com/questions/52897403
复制相似问题