0
我使用了koa2,sequelize和graphql的堆棧。我不想使用graphql變化來更改用戶模型的狀態字段,並返回已更改的對象。與GraphQl一起使用:如何使用變異更新字段
目前我突變看起來是這樣的:
mutation: new GraphQLObjectType({
name: 'Mutation',
fields: {
setState: {
type: userType,
args: {
input: {
type: userStateInputType
}
},
resolve: resolver(db.user, {
before: async (findOptions, {input}) => {
const {uuid, state} = input;
await db.user.update(
{state},
{where: {uuid}}
);
findOptions.where = {
uuid
};
return findOptions;
}
})
}
}
})
而這相應的查詢:
mutation setstate{
setState(input: {uuid: "..UUID..", state: "STATE"}) {
uuid
state
}
}
它的工作,但我敢肯定這是你更好的解決方案。