【问题标题】:FormData with graphql-request带有graphql请求的FormData
【发布时间】:2018-09-28 16:09:10
【问题描述】:

我在前端部分(react)使用graphql-request 进行graphQL 查询。服务器端使用 express-graphql。我有一些想法可以在后端处理这个问题(您的建议也会受到赞赏),但正在搜索如何处理前端部分。

是否可以在graphql-request 查询中发送 FormData(在我的情况下为图像)?有什么例子吗?

【问题讨论】:

    标签: javascript graphql form-data express-graphql


    【解决方案1】:

    根据their documentation,格式如下:

    const client = new GraphQLClient(endpoint, { headers: {} })
    client.request(query, variables).then(data => console.log(data))
    

    GraphQL 不能轻松处理图片上传,upload them elsewhere and send the image URL to your graphql server 可能会更容易。

    你可以这样做:

    yourClient.request(query, { id:1, imgURL:'http://foobar.com' })
    .then(data => doSomethingWithData(data))
    

    【讨论】:

    • 也在考虑这样的解决方案。直接通过graphQL上传图片问题太多。感谢您的回答!
    猜你喜欢
    • 2020-10-01
    • 1970-01-01
    • 2022-08-22
    • 2018-10-26
    • 2018-11-14
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 2014-01-17
    相关资源
    最近更新 更多