0
我想讓我的elm(v:0.18)客戶端通過graphql與我的後端進行通信。我正試圖避免現在的elm-graphql庫,以及基本的elm HttpBuilder模塊。通過elm發送graphql突變
login命令如下:
loginCmd : Model -> Cmd Msg
loginCmd model =
let
graphiql =
"""
mutation {
login(email: "[email protected]", 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阿克曼是正確的。您的文檔鏈接來自舊版本。在頁面頂部,它會發出警告。 – absynce