我最近开始在我的 React Native 应用上使用 Relay ,但突变似乎永远不会提交(我没有从成功/失败回调中获取任何记录),我的 GraphQL 实现的console.log
函数中的resolve
也没有任何内容。
我的应用程序的根组件中有以下代码。 我实际上不需要在我的应用程序中显示更新的名称,它仅用于更新数据库。
class App extends Component {
componentDidMount() {
Relay.Store.commitUpdate(new DogMutation({name: 'Stack'}, {
onSuccess: () => console.log("success"),
onFailure: (transaction) => console.error(transaction)
))
}
}
突变类看起来像这样:
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
传递,但要明白这是它的全局实例。
答案 0 :(得分:0)
所以我使用了graphql-relay的mutationWithClientMutationId
函数,它似乎实际上提交了消息,但仍然没有来自变异的回调。
答案 1 :(得分:0)
所以问题是一个简单的问题,我需要花费很长时间才能找到josephsavona帮助我issue。
从未调用回调因为那些不属于变异的初始化,而是它是commitUpdate
函数的第二个参数。