阿波罗服务器从阿波罗上传客户端接收空对象

时间:2019-04-29 04:50:04

标签: apollo apollo-client

我使用apollo serverapollo upload client

这是我发送文件的客户端代码:

const updateMarketing = gql`
    mutation UpdateMarketing(
        $file1: Upload
        $file2: Upload
        $file3: Upload
        $payload: MarketingInput!
    ) {
        updateMarketing(
            file1: $file1
            file2: $file2
            file3: $file3
            payload: $payload
        ) {
            isSuccess
            error
            data
        }
    }
`;

以及此突变代码:

<Mutation mutation={updateMarketing}>
                        {(
                            updateMarketing,
                            { data, loading, error }
                        ) => (
                            <div>
                                <form
                                    onSubmit={e => {
                                        e.preventDefault();
                                        console.log(e.target.file1.files[0]);
                                        updateWmsSkuTicketMarketing({
                                            variables: {
                                                file1: e.target.file1.files[0],
                                                file2: e.target.file2.files[0],
                                                file3: e.target.file3.files[0],
                                                payload: {
                                                    id: e.target.id.value,
                                                    jobId: e.target.jobId.value
                                                }
                                            }
                                        });
                                    }}
                                >
                                    <input
                                        type="text"
                                        id="id"
                                        name="id"
                                        placeholder="id"
                                    />
                                    <br />
                                    <input
                                        type="text"
                                        id="jobId"
                                        name="jobId"
                                        placeholder="job id"
                                    />
                                    <br />
                                    <input
                                        type="file"
                                        id="file1"
                                        name="file1"
                                    />
                                    <br />
                                    <input
                                        type="file"
                                        id="file2"
                                        name="file2"
                                    />
                                    <br />
                                    <input
                                        type="file"
                                        id="file3"
                                        name="file3"
                                    />
                                    <br />
                                    <button type="submit">
                                        update  marketing
                                    </button>
                                </form>
                                {loading && (
                                    <div>Updating for marketing</div>
                                )}
                                {data && (
                                    <div>
                                        Update  markting Proccess
                                        is finished
                                    </div>
                                )}
                                {error && (
                                    <div>
                                        Error update marketing…
                                    </div>
                                )}
                            </div>
                        )}
                    </Mutation>

在服务器上,我试图获取文件:

const updateMarketing = ({ payload, token, file1, file2, file3 }) =>
        new Promise((resolve, reject) => {
            try {

                console.log(file1, payload);
                file1
                    .then(({ stream, filename }) => {
                         //get stream
                     });
            }
            // catch

但发生错误:file1.then is not a function

console.log(file1)在服务器上:{}

可能是我在客户端中写错了,但是我找不到。

请帮助我,我哪里写错了以及如何解决?

1 个答案:

答案 0 :(得分:0)

updateMarketing是解析器吗?

您的突变args位于第二个解析器函数参数中

apollo upload client的示例中,它也使用第二个参数来获取文件。

请参见docs

还有example