我尝试对graphql进行更改以更新现有数据库中的项目。当我尝试执行此突变时,仍然出现错误。
我在项目中添加了“接受”:
我尝试部署架构,但没有任何效果。
% Little function to edit multiple XML files
% New files are copied into the Modified_XML_Files folder
% and original files are not overwritten
% Creation of a new folder
Modified_XML_Files = fullfile(pwd, 'Modified_XML_Files')
if exist([pwd '\Modified_XML_Files'])~=7
mkdir(Modified_XML_Files);
end
% Copy XML files and move to new folder
copyfile('*.xml', 'Modified_XML_Files')
cd Modified_XML_Files
% List of XML files to modify
XML_Files = dir(fullfile('*.xml'));
XML_Files_Names = {XML_Files.name};
% Loop and delete text between xmlns= and the next space inclusively
for k = 1 : length(XML_Files)
Old_File = XML_Files_Names{k};
file_text = textread(Old_File, '%s', 'delimiter', '\n', 'whitespace', '');
file_text = eraseBetween(file_text, "xmlns=", " ", 'Boundaries', 'inclusive');
New_File = fopen(Old_File, 'w');
for i=1:length(file_text)
fprintf(New_File, '%s\n', file_text{i});
end
New_File = fclose(New_File);
end
此后,我进行了突变:
type Item {
id: ID! @id
title: String!
image: String
largeImage: String
price: Int!
user: User!
accepted: String!
}
然后我写了解析器:
type Mutation {
updateAccepted(id: ID!): Item!
}
当我在操场上执行此功能时,出现此错误
async updateAccepted(parent, args, ctx, info) {
// 1. Check if the person is logged in
const { userId } = ctx.request;
if (!userId) {
throw new Error('You must be signed in');
}
// 2. find the item
const item = await ctx.db.mutation.updateAccepted(
{
where: { id: args.id },
data: {
accepted: 1
}
},
info
);
// 3. Return the item
return item;
},
Kinda无能的atm,请帮助有需要的开发人员:)
答案 0 :(得分:0)
问题解决了。问题是我不得不打电话给updateItem
而不是updateAccepted
。突变类型为Item
...而不是accepted
..
async updateAccepted(parent, args, ctx, info) {
const { id, accepted } = args;
// 1. Check if the person is logged in
const { userId } = ctx.request;
if (!userId) {
throw new Error('You must be signed in');
}
// 2. find the item
return ctx.db.mutation.updateItem(
{
data: { accepted },
where: { id: args.id }
},
info
);
},
快乐的日子