如果不可用,如何替换GraphQL变量?

时间:2018-11-23 16:19:03

标签: react-native graphql

我有一个奇怪的问题,在重新整理我要执行的查询请求。

因此,在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);

1 个答案:

答案 0 :(得分:0)

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

从前面的问题(查询)开始……您不会得到数组,而是对象,请尝试

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

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