Skip to content

Instantly share code, notes, and snippets.

@shapr
Created November 21, 2019 22:36
Show Gist options
  • Select an option

  • Save shapr/62fc7be5088409b24da38a171ffeec12 to your computer and use it in GitHub Desktop.

Select an option

Save shapr/62fc7be5088409b24da38a171ffeec12 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.ByteString.Lazy.Char8 (ByteString)
import Data.Either (fromRight)
import Data.Maybe (catMaybes, fromJust)
import Data.Morpheus.Client (defineByDocumentFile, fetch, gql)
import Data.Morpheus.Types
import Data.Text (Text)
import Network.HTTP.Req
defineByDocumentFile
"schema.gql"
[gql| query URI { viewer { following(first: 100) { totalCount nodes { repository(name: "flmdata") { url } } } } } |]
resolver :: ByteString -> IO ByteString
resolver b = runReq defaultHttpConfig $ do
let headers = header "Content-Type" "application/json"
`mappend` header "Authorization" "bearer 8989898798798798798"
`mappend` header "User-Agent" "fermatslastmargin/1.0"
request = req POST (https "api.github.com" /: "graphql") (ReqBodyLbs b) lbsResponse headers
responseBody <$> request
fetchUris :: IO (Either String URI)
fetchUris = fetch resolver ()
-- let repos = catMaybes $ map repository $ catMaybes $ fromJust . nodes . following . viewer $ top
main :: IO ()
main = do
putStrLn "Hello, Haskell!"
res <- fetchUris
let actualURLs = map unstring $ map url $ catMaybes $ map repository $ catMaybes $ fromJust . nodes . following . viewer $ fromRight undefined res
print actualURLs
unstring (String s) = s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment