简体   繁体   中英

GraphQL : return new Promise((resolve,object)

I've tried to figure it out myself, and google around, but i can't seem to find the answer anywhere, so I'll try my luck here.

I have this mutation, as below:

Mutation :{

            createFriend: (root,{ input }) => {

                const newFriend = new Friends({

                    firstName: input.firstName,
                    lastName: input.lastName,
                    gender: input.gender,
                    age: input.age,
                    language: input.language,
                    email: input.email,
                    contacts: input.contacts
                });

                newFriend.id = newFriend._id;

                return new Promise((resolve,object) =>{

                    newFriend.save((err) =>{

                        if(err) reject(err)
                        else resolve(newFriend)


                    })


                })
            }

What confuses me is the following snippet:

return new Promise((resolve,object) =>{

                newFriend.save((err) =>{

                    if(err) reject(err)
                    else resolve(newFriend)


                })


            }

What does "return new promise" do, and why does it have an object parameter inside, which i never seems to use?

Would be more than happy if someone could explain me what is going on.

Thank you in advance.

As pointed out by Bergi in the comments, it must be a mistake from teacher from the Lynda.com tutorial.

(resolve,reject) makes sense and it still works, so i'll close this question and say that Bergis answer is the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM