如何解决检查 GraphQL 查询是否返回任何行
我在 GraphQL 中有以下简单的选择查询,它检查 dataDictionary
表中是否存在名称字段为 dataDict101
的任何记录。
query dataDictionary($where : DataDictionaryWhereUniqueInput!){
dataDictionary(where: $where){
id
}
},variables: {
data: {
"where" : {
"name": "dataDict101"
}
}
}
如何确定上述查询是否返回任何行? 例如类似于 sql 查询返回 sqlCODE=0 或 sql%rOWCOUNT>0,如果找到记录,则在游标的情况下。
解决方法
export const FIND_DATA_DICTIONARY = gql`
query dataDictionary($where : DataDictionaryWhereUniqueInput!){
dataDictionary(where: $where){
id
}
}
`;
const result = await client.query({
query: FIND_DATA_DICTIONARY,variables: {
where : {
name: data.name,}
},});
resultData = result;
if(resultData?.data.dataDictionary != null)
console.log('data found');
从结果中检查 data.dataDictionary 的非空值,我能够确定是否返回了行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。