Relay.Store.commitUpdate 从不承诺

Relay.Store.commitUpdate never commits

我最近开始在我的 React Native 应用程序上使用 Relay,但突变似乎从未发生过(我不明白来自 success/fail 回调的任何日志记录),我也没有在我的 GraphQL 实现的 resolve 函数中的 console.log 中得到任何东西。

我的应用程序的根组件中有以下代码。 我实际上不需要在我的应用程序中显示更新后的名称,它只是为了更新数据库。

class App extends Component {
    componentDidMount() {
        Relay.Store.commitUpdate(new DogMutation({name: 'Stack'}, {
            onSuccess: () => console.log("success"),
            onFailure: (transaction) => console.error(transaction)
        ))
    }
}

突变 class 看起来像这样:

export default class DogMutation extends Mutation {
    getFatQuery() {
        return Relay.QL`
            fragment on Dog {
                name
            }
        `
    }

    getMutation() {
        return Relay.QL`mutation {renameDog}`
    }

    getVariables() {
        return {
            name: this.props.name
        }
    }

    getConfigs() {
        return []
    }
}

GraphQL 侧突变代码如下所示:

export const renameDog = {
    type: Dog,
    description: `Rename a dog.`,
    args: {
        input: {
            type: new GraphQLInputObjectType({
                name: `DogInput`,
                fields: {
                    name: {
                        type: GraphQLString,
                    }
                }
            })
        }
    },
    async resolve (obj, args) {
        console.log(args) <- Which never outputs
    }
}

当我调用 Relay.Store.commitUpdate() 时,我得到:

RelayMutationQueue.js:390 Optimistic query for `renameDog`
RelayMutationQueue.js:454 Mutation query for `renameDog`

在我的 React Native Chrome 调试器中。

我的代码有什么问题吗?我阅读的多篇文章中是否可能遗漏了某些内容? 我的直觉是我直接使用 Relay.Store 而不是在某处创建一个并将其作为 props 传递,但请理解这是它的一个全局实例。

所以我使用了 graphql-relaymutationWithClientMutationId 函数,它似乎确实提交了消息,但仍然没有从突变中回调。

所以这个问题很简单,我花了很长时间才找到 josephsavona helped me in this issue

回调从未被调用,因为它们不属于突变的初始化,而是 commitUpdate 函数的第二个参数。