2017-10-16 7 views
0

J'essaye d'obtenir que mon client d'orme (v: 0.18) parle avec mon back-end via graphql. J'essaie d'éviter les bibliothèques elm-graphql pour l'instant, et le module de base de l'orme HttpBuilder.Envoi de mutations graphql par l'intermédiaire d'elm

La commande de connexion ressemble à ceci:

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 

Le problème est lié à la fonction withStringBody. Le compilateur me envoie ceci:

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 

Je ne sais pas quel est le problème, étant donné que le HttpBuilder docs dire qu'il est de type withStringBody : String -> RequestBuilder -> RequestBuilder, et utilise comme un exemple:

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

Qu'est-ce que je fais mal ici?

+2

@P Ackerman est correct. Le lien de votre documentation provient d'une ancienne version. En haut de la page, il donne un avertissement. – absynce

Répondre

3

Selon les docs, withStringBody prend effectivement String -> String -> RequestBuilder a, alors je vous dirais besoin d'ajouter une chaîne de contenu avant la chaîne graphql, quelle que soit serait approprié pour votre back-end graphql.

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