【问题标题】:How to replace GraphQL variable if not available?如果不可用,如何替换 GraphQL 变量?
【发布时间】:2019-04-26 06:16:38
【问题描述】:

我有一个奇怪的问题,正在对我正在尝试执行的查询请求进行重新分级。

因此,虽然 b_id 变量未定义,但我想在以下示例中替换为 null。我尝试添加props.business.getUserBusiness[0]._id || null,但仍然返回未定义的错误。

export default compose(
    withApollo,
    graphql(GET_ME, { name: "getMe" }),
    graphql(GET_USER_BUSINESS, { name: "business" }),
    graphql(GET_BUSINESS_JOBS,
        {
            name: "businessJobs",
            skip: (props) => !props.business || !props.business.getUserBusiness, 
            options: (props) => (
                {
                    variables:
                    {
                        b_id: props.business.getUserBusiness[0]._id
                    }
                }
            )
        }),
)(Dashboard);

【问题讨论】:

    标签: react-native graphql


    【解决方案1】:

    props.business.getUserBusiness 可以定义,props.business.getUserBusiness[0] 可以不定义

    从前面的问题(查询)...你不会得到一个数组而是对象,试试

            skip: (props) => !props.business || !props.business.getUserBusiness._id, 
            options: (props) => (
                {
                    variables:
                    {
                        b_id: props.business.getUserBusiness._id
                    }
                }
            )
    

    为未使用(跳过)的查询定义一个变量是不是没用?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2021-05-03
      • 1970-01-01
      • 2018-09-09
      • 2016-06-05
      • 1970-01-01
      相关资源
      最近更新 更多