我对 Relay 很陌生,所以也许这是一个非常愚蠢的错误。
我正在尝试制作一个简单的突变,将 a 添加defect
到 a photo
。
这是我的 Relay.Mutation 对象:
AddDefectMutation.js
export default class AddDefectMutation extends Relay.Mutation {
getMutation() {
return Relay.QL`mutation { addDefect }`;
}
getVariables() {
return{
photoId: this.props.photoId,
title: this.props.title
}
}
getFatQuery() {
return Relay.QL`
fragment on AddDefectMutationPayload {
updatedPhoto {
issues
}
}
`
}
getConfigs() {
return [{
type : 'FIELDS_CHANGE',
fieldIDs : {
updatedPhoto : this.props.photoId
}
}]
}
}
这是 GraphQl 模式的一部分
const AddDefectMutation = mutationWithClientMutationId({
name: 'AddDefectMutation',
description: 'Add a new defect and return all the defects.',
inputFields: {
photoId: {
description: 'Photo of this defect',
type: new GraphQLNonNull(GraphQLString)
},
title: {
description: 'A short description of the defect',
type: GraphQLString
}
},
outputFields: {
updatedPhoto: {
type: PhotoGraphQLType,
resolve: ({localIdIssue}) => driver.getIssuePhoto(localIdIssue)
}
},
mutateAndGetPayload: ({photoId, title}) =>
driver.addIssue(photoId, title).then(localIdIssue => ({localIdIssue}))
})
const MutationGraphQLType = new GraphQLObjectType({
name: 'Mutation',
fields: () => ({
addDefect: AddDefectMutation
})
})
我的问题是当我拨打这个电话时:
Relay.Store.commitUpdate(new AddDefectMutation(
{photoId: this.props.pictureId, title: this.props.title}), {
onSuccess: ()=> console.log("Mutation Success !"),
onFailure: transaction => console.error(transaction.getError() || new Error('Mutation failed.'))
})
中继毫无问题地生成良好的变异查询,但它不会将给定的变量放在构造函数中。
编辑:这里是中继生成的突变片段
mutation AddDefect($input_0:AddDefectMutationInput!) {
addDefect(input:$input_0) {
...F4,
clientMutationId
}
}
问题是这$input_0
是一个空对象