【发布时间】:2016-09-05 23:00:18
【问题描述】:
我对 Relay 很陌生,所以也许这是一个非常愚蠢的错误。
我正在尝试做一个简单的突变,将defect 添加到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.'))
})
Relay 生成好的突变查询没有问题,但它没有将给定的变量放在构造函数中。
编辑:这里是中继生成的突变片段
mutation AddDefect($input_0:AddDefectMutationInput!) {
addDefect(input:$input_0) {
...F4,
clientMutationId
}
}
问题是$input_0 是一个空对象
【问题讨论】:
标签: reactjs graphql relayjs relay