중계 변이와 관련된 쿼리가 있습니다. 설정 컬렉션에서 금액 필드를 업데이트하려고하지만 페이지 새로 고침이 필요하지 않습니다. 값이 업데이트되었지만 페이지가 매회 새로 고침됩니다. 누구든지 내게 어떤 제안을 할 수 있습니까?중계 변경이 동적으로 작동하지 않습니다.
다음은 내 EditAmountMutation.js이
import Relay from "react-relay";
class EditAmountMutation extends Relay.Mutation {
static fragments = {
viewer:() => Relay.QL`
fragment on Setting {
amount,
}
`,
};
getMutation() {
return Relay.QL`
mutation { EditAmount }
`;
}
getVariables() {
return {
amount: this.props.amount,
}
}
getFatQuery() {
return Relay.QL`
fragment on EditAmountPayload{
viewer{
id,
amount
}
}
`;
}
getConfigs() {
return [{
type: 'FIELDS_CHANGE',
fieldIDs: {
viewer: this.props.viewer,
},
}]
}
getOptimisticResponse() {
return {
viewer: {
amount: this.props.amount,
},
};
}
}
export default EditAmountMutation;
파일 내 schema.js 아래
var settingType = new GraphQLObjectType({
name: 'Setting',
fields: {
_id: {
type: new GraphQLNonNull(GraphQLID)
},
id: globalIdField('Setting'),
amount: {
type: GraphQLString
},
},
interfaces: [nodeInterface]
});
var Root = new GraphQLObjectType({
name: 'Root',
fields:() => ({
setting: {
type: settingType,
args: {
...connectionArgs,
currency: {type: GraphQLString}
},
resolve: (rootValue, args) => {
return getSetting(args.currency).then(function(data){
return data[0];
}).then(null,function(err){
return err;
});
}
},
})
});
let EditAmountMutation = mutationWithClientMutationId({
name: 'EditAmount',
inputFields: {
amount: { type: new GraphQLNonNull(GraphQLString) },
},
outputFields: {
viewer: {
type: settingType,
resolve:() => {
return getSettingedit().then(function(data){
return data.setting[0]
})
},
},
},
mutateAndGetPayload: ({amount}) => {
return EditAmount({amount}).then(function(data){
return data.setting
})
},
});
export var schema = new GraphQLSchema({
query: Root,
mutation: new GraphQLObjectType({
name: 'Mutation',
fields:() => ({
EditAmount: EditAmountMutation,
})
})
});
그리고를하고 아래 아래에있는 내보기 페이지 Setting.js
import React, { Component } from 'react';
import EditAmountMutation from "../mutations/EditAmountMutation";
import Relay from 'react-relay';
class Setting extends Component {
handleSubmitt = (e) => {
Relay.Store.commitUpdate(
new EditAmountMutation({
viewer: this.props.viewer,
amount: this.refs.amount.value,
}),
);
this.refs.amount.value = "";
}
render() {
let viewer =this.props.viewer;
return (
<div className="col-md-4 col-md-offset-4">
<form onSubmit={this.handleSubmitt} className="settingForm photo-gallry">
<div className="form-group">
<label>Current Amount: </label>
<span>{viewer.amount}</span>
</div>
<div className="form-group">
<label>Change Amount</label>
<input className="form-control" type="text" required placeholder="Amount" ref="amount" />
</div>
<button className="btn btn-primary allbtn-btn" type="submit">Submit</button>
</form>
</div>
);
}
}
export default Relay.createContainer(Setting, {
fragments: {
viewer:() => Relay.QL`
fragment on Setting {
id,
amount,
${EditAmountMutation.getFragment('viewer')}
}
`,
},
});
된다 route.js 파일
아래내 자바 스크립트 콘솔의 database.js 또한
export function getSetting(params) {
// console.log("getSetting",params)
return Setting.find({currency: "USD"})
.exec()
.then(function(setting) {
return setting;
});
}
export function EditAmount(params) {
// console.log(params)
return Setting.findOneAndUpdate({currency: "USD"}, {$set:{amount:params.amount}}, {new: true}, function(err, setting){
if (err) return err;
return setting;
});
}
가지 작업중인/
mutation EditAmountMutation($input:EditAmountInput!) {
EditAmount(input:$input) {
clientMutationId,
viewer{
amount
}
}
}
{
"input": {
"clientMutationId": "32",
"amount": "222"
}
}
으로 graphql 얻은 출력
{
"data": {
"EditAmount": {
"clientMutationId": "32",
"viewer": {
"amount": "222"
}
}
}
}
아래와 같이하지만 네트워크 탭입니다 게시물 요청으로 표시합니다.
크롬에서 업데이트 된 금액이 Firefox에서 업데이트되지 않는 이상한 동작이 발생합니다. – akshay
perfoming update while relay mutation에서 출력 필드가 작동하지 않는다고 생각합니다. – akshay
'Settings' 컨테이너의'amount' 데이터가 업데이트되어'Settings' 컨테이너가 새로 고쳐집니다. 나는 여기에 잘못된 것을 보지 않는다. –