1

私はRelayにかなり慣れていないので、おそらく非常にばかげたエラーです。

defectaに 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が空のオブジェクトであることです

4

1 に答える 1

1

変数titleがミューテーション コンストラクターに正しく渡されていません。Relay.Store.commitUpdate関数呼び出しで、次のように変更{photoId: this.props.pictureId, this.props.title})します

{photoId: this.props.pictureId, title: this.props.title})
于 2016-05-10T20:58:21.213 に答える