当我尝试使用 Relay Mutations 更新 Relay 中的记录时,我收到这样的错误。
没有字段“clientMutationId”
但是我没有在我的 GraphQL 模式中声明任何 clientMutationId。这是我在 Relay 中的代码
function updateZipdata1(){
console.log("update zip");
return new Promise((resolve, reject) => {
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
var config = {
userName: 'xxx',
password: 'xxxx',
server: 'xxxx',
options: {
database: 'xxxx'
}
}
var results = [];
var connection = new Connection(config);
connection.on('connect', (err)=> {
if (err) {
console.log(err)
reject(err);
}
var ZipCode="123456";
var RecNo="789456";
var sql = "update dbo.xrxZip set ZipCode='"+ZipCode+"' where RecNo='"+RecNo+"'";
var request = new Request(sql,
(err, rowCount)=> {
if (err) {
console.log('SQLError');
connection.close();
reject(err);
}
else {
console.log("sql:"+rowCount)
connection.close();
resolve(results);
}
});
request.on('row', (columns)=> {
var row = {};
columns.forEach((column)=> {
if (column.isNull) {
row[column.metadata.colName] = null;
} else {
row[column.metadata.colName] = column.value;
}
});
console.log("hai:"+results)
results.push(row);
});
connection.execSql(request);
})
})
};
我的 GraphQL 架构:
var zipType = new GraphQLObjectType({
name: 'Zipcode',
fields: () => ({
ZipCode: {type: GraphQLString},
City: {type: GraphQLString},
ShortCode:{type: GraphQLString},
State:{type: GraphQLString},
Phone:{type: GraphQLString},
TaxCode:{type: GraphQLString},
Tax:{type: GraphQLString},
RecNo:{type: GraphQLString}
}),
});
var zipCodeType = new GraphQLObjectType({
name: 'Zip',
fields: () => ({
zipcodes: {type: new GraphQLList(zipType)},
}),
});
export var Schema = new GraphQLSchema({
mutation: new GraphQLObjectType({
name: "Mutation",
fields: () => ({
UpdateZipcode:{
type: zipCodeType,
args: {
ZipCode: {type: GraphQLString}
},
resolve: (root,{ZipCode}) =>updateZipdata,
}
})
})
})
const updateZipdata = {
zipcodes: updateZipdata1(), // Calling the function
};
当我在终端中为硬编码的 ZipCode 和 RecNo 运行它时,它可以正常工作,没有任何错误。但是当我尝试在 Relay 中执行时,我收到了如上所述的错误。
听到是我的中继代码:
这是 Relay 中用于突变的子类。
export default class updateZipMutation extends Relay.Mutation {
getMutation() {
alert("getMutation");
return Relay.QL`mutation{UpdateZipcode}` ;
}
getVariables() {
alert("getVariables");
return { RecNo: this.props.data.RecNo,ZipCode:this.props.data.ZipCode,City:this.props.data.City,Phone:this.props.data.Phone,ShortCode:this.props.data.ShortCode,Tax:this.props.data.Tax,TaxCode:this.props.data.TaxCode,State:this.props.data.State};
}
getFatQuery() {
alert("getFatQuery")
return Relay.QL`
fragment on Zipcode {
RecNo,
ZipCode,
City,
Phone,
ShortCode,
Tax,
TaxCode,
State
}
`;
}
getConfigs() {
alert("getConfigs");
return [{
type: 'zipCodeType',
fieldIDs:{
RecNo: this.props.data.RecNo
},
}];
}
}
这是我在 Relay 中调用突变子类的主类:
export default class zips extends React.Component {
Relay.Store.update(
new updateZipMutation({ //I am getting the data from form
data: { RecNo, ZipCode,City,Phone,ShortCode,Tax,TaxCode,State},
})
);
}
}
任何人请给我建议如何解决它,以及如何处理突变。非常感谢任何帮助。