Created
January 6, 2018 13:12
-
-
Save grrinchas/2e689c13be097d3578af6e9ab57cc3b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
graphcool: String | |
graphcool = "https://api.graph.cool/simple/v1/cjbm8w2980rge0186pld48aan" | |
fetchPosts: Cmd Msg | |
fetchPosts = | |
Http.post graphcool (jsonBody <| Encoders.postsQuery) decodePosts | |
|> RemoteData.sendRequest | |
|> Cmd.map Messages.OnFetchPosts | |
createRequest : Form -> String -> Http.Request Post | |
createRequest form token = | |
Http.request | |
{ method = "POST" | |
, headers = [ Http.header "Authorization" <| "Bearer " ++ token ] | |
, url = graphcool | |
, body = Http.jsonBody <| Encoders.createPost form | |
, expect = Http.expectJson Decoders.decodePost | |
, timeout = Nothing | |
, withCredentials = False | |
} | |
createPost : Form -> String -> Cmd Msg | |
createPost form token = | |
createRequest form token | |
|> RemoteData.sendRequest | |
|> Cmd.map Messages.OnCreatePost | |
authenticate: Token -> Cmd Msg | |
authenticate token = | |
Http.post graphcool (jsonBody <| Encoders.authenticate token) decodeGraphcoolToken | |
|> RemoteData.sendRequest | |
|> Cmd.map Messages.OnFetchGraphcoolToken |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment