我開始使用graphql,我試圖刪除graphql的節點,但我沒有得到它。刪除突變不起作用
這裏是我的解析:
export default {
Query: {
allLinks: async (root, data, { mongo: { Links } }) =>
Links.find({}).toArray()
},
Mutation: {
createLink: async (root, data, { mongo: { Links }, user }) => {
const newLink = Object.assign({ postedById: user && user._id }, data);
const response = await Links.insert(newLink);
return Object.assign({ id: response.insertedIds[0] }, newLink);
},
removeLink: async (root, { id }, { mongo: { Links }, user }) => {
const newLink = Object.assign({ postedById: user && user._id });
const response = await Links.remove(id);
return Object.assign(response, newLink);
},
createUser: async (root, data, { mongo: { Users } }) => {
const newUser = {
name: data.name,
email: data.authProvider.email.email,
password: data.authProvider.email.password
};
const response = await Users.insert(newUser);
return Object.assign({ id: response.insertedIds[0] }, newUser);
},
signinUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.email.email });
if (data.email.password === user.password) {
return { token: `token-${user.email}`, user };
}
}
},
Link: {
id: root => root._id || root.id,
postedBy: async ({ postedById }, data, { dataloaders: { userLoader } }) => {
return await userLoader.load(postedById);
}
},
User: {
id: root => root._id || root.id
}
};
所有突變都工作正常少removeLink。
當我運行removeLink突變我得到這個錯誤:
MongoError: Wrong type for 'q'. Expected a object, got a string.
我知道什麼是錯的,但我不知道是什麼。
你是什麼意思,當你說這是「工作不正常」? GraphQL是否返回任何錯誤?如果是的話,什麼?此外,這個問題可能與您提交給GraphQL端點的查詢或您的類型定義有關......提供這些信息可能有助於指出問題所在。 –
對不起,我忘記報告錯誤。我會更新我的問題 –