读取使用中使用的变量突变



我有一个Apollo GraphQL突变。此突变接受两个变量。 我想在触发突变后读取这些变量(而不是作为支持的响应(。 我需要知道这些变量,因为我想在onCompleted函数中使用它们。

我的代码:

const [tripleEntity] = useMutation(TRIPLE_ENTITY, {
context: { clientName: 'redzor' },
refetchQueries: ['listProjects']
})

我想要什么:

const [tripleEntity] = useMutation(TRIPLE_ENTITY, {
context: { clientName: 'redzor' },
refetchQueries: ['listsEntities'],
onCompleted(response, variables): {
console.log(variables) // Where "variables" are the input necessary to fire this mutation
myFunction(variables) // This is the function that needs the input variables
}   
})

onComplete仅将突变结果作为参数传递 - 没有其他内容。但是,mutate返回一个承诺,因此不需要使用onCompleted

const [mutate] = useMutation(YOUR_MUTATION, {...})
const doSomething = async (options) => {
const result = await mutate(options)
yourFunction(options.variables)
}

最新更新