谢谢你的帮助。我正在尝试在没有数据库的情况下在 GraphQL 中执行 AND/OR 运算符。
下面是查询需要在数据集而不是数据库上执行。请理解,我无权连接任何数据库。
{
customVisualsData(_filter: {and: [{expression: {field: "Country", like: "Canada"}},{expression: {field: "Profit", gt: "5000"}}]}) {
Country
DiscountBand
Product
Segment
Profit
}
}
转换数据集/JSON 对象如下所示。
[
{
"Country": "Canada",
"DiscountBand": "High",
"Product": "Paseo",
"Segment": "Government",
"COGS": 1477815,
"GrossSales": 2029256,
"ManufacturingPrice": 70,
"UnitsSold": 12230.5,
"Profit": 300289.99999999994
},
{
"Country": "United States of America",
"DiscountBand": "High",
"Product": "VTT",
"Segment": "Small Business",
"COGS": 1461250,
"GrossSales": 1753500,
"ManufacturingPrice": 750,
"UnitsSold": 5845,
"Profit": 74288
}
]
Schema Builder,我用来创建 GraphQL Query builder。
var schema = buildSchema(`
type customVisualObject {
Country: String
DiscountBand: String
Product: String
Segment: String
COGS: Float
GrossSales: Float
ManufacturingPrice: Int
UnitsSold: Float
Profit: Float
}
type Query {
customVisualsData(_filter: FilterInput): [customVisualObject]
}
input FilterExpressionInput {
field: String!
eq: String
gt: String
gte: String
like: String
}
input FilterInput {
expression: FilterExpressionInput
and: [FilterInput!]
or: [FilterInput]
not: [FilterInput!]
}
`);
如果有人知道如何在graphQL上为此设置解析器,请告诉我?有谁知道 JSON-ata 或 GraphQL 库来对 JSON 对象而不是数据库执行如此复杂的查询?我感谢您的帮助。