我开始使用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端点的查询或您的类型定义有关......提供这些信息可能有助于指出问题所在。 –
对不起,我忘记报告错误。我会更新我的问题 –