问题描述
谁能建议为什么我的突变不起作用。我的应用是 keystone-next 后端、apollo-boost 和 next.js。我有处于状态的字段并将它们设置为变量,但它们不会发送到后端。我确定这以前有效。
keystone 中的后端自定义变更
async function locate(
root: any,{ userId }: { userId: string },context: KeystoneContext
): Promise<LocationCreateInput> {
// 1. Query the current user see if they are signed in
const sesh = context.session as Session;
if (!sesh.itemId) {
throw new Error('You must be logged in to do this!');
}
// 2. Create the location object
return await context.lists.Location.createOne({
data: {
user: { connect: { id: sesh.itemId }},}
})
}
export default locate;
和 next.js 中的前端
const LOCATE_MUTATION = gql`
mutation LOCATE_MUTATION(
$address: String
$lat: String
$lng: String
) {
locate(data:{ address: $address,lat: $lat,lng: $lng }) {
id
address
lat
lng
user {
id
name
}
}
}
`;
const [locate,{ error }] =
useMutation(LOCATE_MUTATION,{
variables: {address: location,lat: slat,lng: slng}
})
<button onClick={locate}>Set my Location</button>
最后,我在 apollo 开发工具中显示的突变
Variables
address "Cambridge CB1,UK"
lat "52.1964114"
lng "0.1746102"
▾Mutation string
mutation LOCATE_MUTATION($address: String,$lat: String,$lng: String) {
locate(data: {address: $address,lng: $lng}) {
id
address
lat
lng
user {
id
name
__typename
}
__typename
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)