【问题标题】:Check if GraphQL query returned any row检查 GraphQL 查询是否返回任何行
【发布时间】:2021-09-12 23:43:52
【问题描述】:

我在 GraphQL 中有以下简单的选择查询,它检查 dataDictionary 表中是否存在名称字段为 dataDict101 的任何记录。

query dataDictionary($where : DataDictionaryWhereUniqueInput!){
  dataDictionary(where: $where){
    id
  }
}
,
variables: {
data: {
       "where" : {
            "name": "dataDict101"
            } 
      }
}

如何确定上述查询是否返回任何行? 例如与 SQL 查询类似,如果找到记录,则在游标的情况下返回 SQLCODE=0 或 SQL%ROWCOUNT>0。

【问题讨论】:

  • 回复中dataDictionary的存在不是已经告诉你了吗?

标签: graphql resolver prisma-graphql


【解决方案1】:
    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 的非空值,我能够确定是否返回了行。

【讨论】:

    猜你喜欢
    • 2014-02-15
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2017-11-19
    • 2021-01-15
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多