【发布时间】:2018-11-11 02:27:30
【问题描述】:
我在 GraphQL 中进行以下查询:
{
metal(silver_bid_usd_toz: 1) {
silver_bid_usd_toz
}
}
返回
{
"data": {
"metal": {
"silver_bid_usd_toz": 16.45
}
}
}
API 返回的 JSON 对象是平面的:
{
silver_bid_usd_toz: 123,
gold_bid_usd_toz: 123,
copper_bid_usd_toz: 123
}
我不明白我的 graphql 查询中的 int 1 是什么意思 metal(silver_bid_usd_toz: 1)
不管我把它改成什么,它可以是 1 或 355,但它是查询工作所必需的。为什么我不能这样做
{
metal(silver_bid_usd_toz) {
silver_bid_usd_toz
}
}
我的架构如下所示:
module.exports = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
description: '...',
fields: () => ({
metal: {
type: MetalType,
args: {
gold_bid_usd_toz: { type: GraphQLFloat },
silver_bid_usd_toz: { type: GraphQLFloat }
},
resolve: (root, args) => fetch(
`api_url`
)
.then(response => response.json())
}
})
})
});
【问题讨论】:
-
当您发送没有任何参数的查询时究竟会发生什么?