【发布时间】: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 阿克曼是正确的。您的文档链接来自旧版本。在页面顶部它会给出警告。