A ELM library to use the GraphQL API.
To install the library:
> elm-package install gribouille/elm-graphqlauthorization header:config : String -> GraphQL.Config
config token =
GraphQL.Config [ ("authorization", "Bearer " ++ token) ] "/api/graphql"cmd and exec:getUsers : String -> (GraphQL.Purpose Users -> msg) -> Cmd msg
getUsers token resultCallback =
GraphQL.cmd (myRequest token) resultCallback
myRequest : String -> Http.Request (GraphQL.Response Users)
myRequest token =
GraphQL.exec (config token) "users"
|> GraphQL.query myQuery
|> GraphQL.variabes Encode.null
|> GraphQL.decoder User.usersDecoder
myQuery : String
myQuery =
"""
query {
users { id login firstname lastname email }
}
"""update function:type Msg
= GetUsers -- msg to execute the request
| OnGetUsers (GraphQL.Purpose Users) -- msg to receive the data
...
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
GetUsers -> getUsers "myToken" OnGetUsers
OnGetUsers res -> GraphQL.response model res
(\users -> { model | ... } ! [ ... ] ) -- if success
(\error -> { model | ... } ! [ ... ] ) -- if errorThe API documentation is available here.
To run the examples:
$ cd test
$ npm install
$ npm run server
$ npm run devOpen localhost:8080.
Feedback and contributions are very welcome.
This project is licensed under Mozilla Public License Version 2.0.