【问题标题】:Failed Update data with GraphQL使用 GraphQL 更新数据失败
【发布时间】:2019-04-17 07:40:14
【问题描述】:

现在我正在尝试更新现有数据宽度

const Mutation = new GraphQLObjectType({
    name: 'Mutation',
    fields: {
        updateUser: {
            type: UserType,
            args: {
                id: { type: GraphQLID },
                email: { type: GraphQLString },
            },
            resolve(parent, { id, email }) {
                console.log('email',email)
                const user = User.findById(id)
                user.email = email
                return user
            }
        },
    }
})

我的突变是这样的

 mutation{
   updateUser(id:"5beac69c421c6e2820a0e809", email:"8"){
       id       
        email
   }

 }

我得到的是用户数据, 但是数据库没有变化,请帮忙

【问题讨论】:

  • 你忘记在某处调用 use.save() 了吗?

标签: node.js reactjs graphql react-native-android apollo


【解决方案1】:

@Matan,你在用Mongoose吗?如果是,则必须实际更新此数据,您所做的只是改变对象并返回它。

使用MongoDB(如果您正在使用它),您可以做到:User.findOneAndUpdate({ id }, { email }) 或接近。

如果它是另一个数据库,您必须在某个时候调用.save().update(),否则,您不会更改任何数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 2018-06-30
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    相关资源
    最近更新 更多