【问题标题】:Sending graphql mutations through elm通过 elm 发送 graphql 突变
【发布时间】:2017-10-17 06:40:18
【问题描述】:

我正在尝试让我的 elm (v: 0.18) 客户端通过 graphql 与我的后端对话。我现在试图避免使用 elm-graphql 库,以及基本的 elm HttpBuilder 模块。

登录命令如下所示:

loginCmd : Model -> Cmd Msg
loginCmd model =
    let
        graphiql =
            """
              mutation {
                login(email: "me@myapp.com", password: "password") {
                  token
                }
              }
            """
    in
        HttpBuilder.post ("http://localhost:4000/api")
            |> HttpBuilder.withStringBody graphiql
            |> HttpBuilder.withExpect (Http.expectJson myJsonDecoder)
            |> HttpBuilder.send GetTokenCompleted

问题在于withStringBody 函数。编译器发给我这个:

The right side of (|>) is causing a type mismatch.

101|         HttpBuilder.post ("http://localhost:4000/api")
102|>            |> HttpBuilder.withStringBody graphiql

(|>) is expecting the right side to be a:

    RequestBuilder () -> a

But the right side is:

    String -> RequestBuilder a -> RequestBuilder a

我不确定问题是什么,因为HttpBuilder docs 说它是withStringBody : String -> RequestBuilder -> RequestBuilder 类型,并以此为例:

post "https://example.com/api/items/1"
  |> withHeader "Content-Type" "application/json"
  |> withStringBody """{ "sortBy": "coolness", "take": 10 }"""

我在这里做错了什么?

【问题讨论】:

  • @P 阿克曼是正确的。您的文档链接来自旧版本。在页面顶部它会给出警告。

标签: graphql elm


【解决方案1】:

根据文档,withStringBody 实际上需要String -> String -> RequestBuilder a,所以我想说您需要在graphql 字符串之前添加一个内容字符串,无论您的graphql 后端是否合适。

|> HttpBuilder.withStringBody "text/plain" """{ "sortBy": "coolness", "take": 10 }"""

【讨论】:

    猜你喜欢
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 2019-08-04
    • 2018-04-19
    • 2019-12-18
    • 2018-09-10
    • 1970-01-01
    相关资源
    最近更新 更多