kowainik / github-graphql

🕸️ GraphQL bindings to GitHub API
https://kowainik.github.io/projects/github-graphql
Mozilla Public License 2.0
7 stars 0 forks source link

[#13] Implement endpoint that will take Query and call the real API #17

Closed chshersh closed 3 years ago

chshersh commented 3 years ago

Resolves #13

Managed to write working code somehow... Just glued multiple pieces together. But any suggestions (especially naming ones) are really appreciated!).

Strictly speaking, dependency on aeson is not really necessary, and the API can return ByteString. But users of github-graphql will need to use aeson anyway, so I've decided to depend on it and provide several utilities (like the Data newtype).

I checked, that it works and calls the API (with the temporary version that returns ByteString):

λ: token = GitHubToken "1f777a210889b833815a0175c5c0d886839091f0"
λ: callGitHub token (repositoryToAst exampleQuery)
The status code was: Status {statusCode = 200, statusMessage = "OK"}
"{"data":{"repository":{"issues":{"nodes":[{"title":"Use 'git stash push' and handle optional argument to 'hit stash' to stash individual files","author":{"login":"chshersh"}},{"title":"Add --color-moved to hit diff","author":{"login":"vrom911"}},{"title":"[RFC] Warn about suspicious files","author":{"login":"vrom911"}}]},"pullRequests":{"nodes":[]}}}}"

But it also works now with Aeson types! Now users of github-graphql only need to write manual FromJSON instances for their types:

λ: callGitHub token (repositoryToAst exampleQuery) :: IO Value
Object
    ( fromList
        [
            ( "repository"
            , Object
                ( fromList
                    [
                        ( "pullRequests"
                        , Object
                            ( fromList
                                [
                                    ( "nodes"
                                    , Array []
                                    )
                                ]
                            )
                        )
...