[英]How do you insert a filter into a graphql query string?
不幸的是,據我所知,文檔中沒有任何關於如何將變量傳遞給過濾器的好例子。 以下是在 App Sync 中工作的查詢示例:
query listPayments {
listPayments(filter: {residentId: {contains: "some_random_id"}}) {
items {
timestamp
totalAmount
feeAmount
transactionId
paymentTraceId
paymentReferenceId
paymentMethodId
}
}
}
但我不知道如何將它傳遞到我的 function 然后與模板字符串交互:
export const getResidentPayments = async (residentId) => {
console.log('getting payments...')
try {
paymentHistoryResponse = (await API.graphql(
graphqlOperation(listPayments, {
input: {id: residentId}
}),
)).data
console.log('payment history res', paymentHistoryResponse);
paymentHistoryResponse = JSON.parse(paymentHistoryResponse);
return paymentHistoryResponse
} catch (error) {
console.log('got payment history err', error);
throw error;
}
}
const listPayments = ` query listPayments ($residentId: id ) {
listPayments(filter: {residentId: {contains: $residentId}}) {
items {
timestamp
totalAmount
feeAmount
transactionId
paymentTraceId
paymentReferenceId
paymentMethodId
}
}
}
`;
如果有人能告訴我我做錯了什么,將不勝感激,因為這可能是一個相當明顯的新手錯誤。 我很震驚 graphql 沒有這方面的文檔示例,除非我也弄錯了。
AppSync 為您構建了許多功能。 listPayments
的類型定義是什么?
您是否為帶有字段和字符串的listPayments
進行了過濾輸入?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.