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
}
}
它的工作,但我敢肯定这是你更好的解决方案。