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
init : Maybe Token -> Location -> ( Model, Cmd Msg ) | |
init token location = | |
let model = | |
{ initialModel | |
| token = Maybe.map RemoteData.succeed token |> Maybe.withDefault RemoteData.NotAsked | |
, route = parseLocation location | |
} | |
in | |
fetchPosts model | |
|> andThen fetchUser |
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
landing : Model -> Html Msg | |
landing model = | |
case model.posts of | |
NotAsked -> | |
div [] [] | |
Loading -> | |
withLoader (div [] []) | |
Success posts -> | |
RemoteData.map userHeader model.user | |
|> RemoteData.withDefault authHeader |
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 |
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
decodePosts : Decoder.Decoder (List Post) | |
decodePosts = | |
Decoder.list decodePost | |
|> Decoder.field "allPosts" | |
|> Decoder.field "data" | |
decodeGraphcoolToken : Decoder.Decoder String | |
decodeGraphcoolToken = | |
Decoder.string | |
|> Decoder.field "token" |
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
postsQuery : Encoder.Value | |
postsQuery = | |
Encoder.object | |
[ ( "query", Encoder.string "query {allPosts(orderBy: createdAt_DESC){id title body}}" ) ] | |
authenticate : Token -> Encoder.Value | |
authenticate token = | |
let | |
query = | |
"mutation {authenticate (accessToken: \"" ++ token.accessToken ++ "\"){token}}" |
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
{ | |
"name": "elm-blog", | |
"version": "1.0.0", | |
"description": "An example of Elm blog.", | |
"devDependencies": { | |
"graphcool-lib": "^0.1.4", | |
"isomorphic-fetch": "^2.2.1", | |
"jsonwebtoken": "^8.1.0", | |
"jwks-rsa": "^1.2.1" | |
} |
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
type AuthenticationPayload { | |
id: String! | |
token: String! | |
} | |
extend type Mutation { | |
authenticate(accessToken: String!) : AuthenticationPayload | |
} |
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
types: ./types.graphql | |
functions: | |
authenticate: | |
type: resolver | |
schema: ./src/authentication.graphql | |
handler: | |
code: | |
src: ./src/resolvers/authenticate.js | |
environment: | |
AUTH0_DOMAIN: nookit.eu.auth0.com |
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
type User @model { | |
id: ID! @isUnique | |
createdAt: DateTime! | |
updatedAt: DateTime! | |
auth0UserId: String! @isUnique | |
email: String! @isUnique | |
} | |
type Post @model { | |
id: ID! @isUnique |
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/ | |
-+ node_modules/ | |
-- src/ | |
| -- resolvers/ | |
| | -- authenticate.js | |
| -- authentication.graphql | |
-- .graphcoolrc | |
-- graphcool.yml | |
-- package.json |
NewerOlder