我想搜索、过滤、排序内存中的结果,该结果是从本地数据库的数据和外部 api 的数据聚合而成的。
这是我的示例解析器。
const resolver = {
Query: {
allDevices: (_, args: QueryArgs, context: CustomContext) =>
readAllDevices() // from local database
.then(searchFilterOrderAndPaginate(["name"], args))
// additionalDataFromOtherMicroservice is not yet resolved
// -> no search possible over all properties
},
Mutation: {},
Device: {
additionalDataFromOtherMicroservice: () => Promise.resolve("" + Math.random())
// simulates an http request to another microservice api
}
};
Run Code Online (Sandbox Code Playgroud)
这是我的示例架构。
const schema = gql`
type Device {
id: ID
number: ID
name: String
additionalDataFromOtherMicroservice: String
}
type Query { …Run Code Online (Sandbox Code Playgroud)