Type-safe GraphQL queries using functional dependencies.
Go to file
2023-06-19 14:58:51 +03:00
.github/workflows Adds tests to the pipeline 2023-06-19 14:58:51 +03:00
src Updates naming conventions 2023-06-19 14:54:03 +03:00
test Updates naming conventions 2023-06-19 14:54:03 +03:00
.gitignore Adds monad aff binding 2023-06-19 12:08:43 +03:00
LICENSE Create LICENSE 2021-05-19 12:40:08 +03:00
package-lock.json Adds better error handler 2023-06-19 14:48:46 +03:00
package.json Adds better error handler 2023-06-19 14:48:46 +03:00
packages.dhall Initial commit 2021-05-19 12:34:42 +03:00
README.md Adds readme 2021-05-19 12:38:17 +03:00
spago.dhall Updates naming conventions 2023-06-19 14:54:03 +03:00
test.dhall Initial commit 2021-05-19 12:34:42 +03:00

purescript-graphql-fundeps

Type-safe graphql queries using functional dependencies.

Use the GraphQLReqRes class to define expected input and output. Then, create a client and use it to interact with your API.

endpoint = "https://api.react-finland.fi/graphql" :: String

foreign import data ReactFinlandConferences :: GraphQL

instance graphqlReactFinlandConferences ::
  GraphQLReqRes ReactFinlandConferences """query {
  conferences {
    name
    id
  }
}
""" () ( conferences :: Array { name :: String, id :: String } )

foreign import data ReactFinlandConference :: GraphQL

instance graphqlReactFinlandConference ::
  GraphQLReqRes ReactFinlandConference """query($id:ID!) {
  conference(id:$id) {
    year
    websiteUrl
    speakers {
      firstName
      lastName
    }
  }
}
""" ( id :: String ) ( conference ::
        { year :: String
        , websiteUrl :: String
        , speakers ::
            Array
              { firstName :: String
              , lastName :: String
              }
        }
    )

client :: GraphQLClient
client = graphQL "https://api.react-finland.fi/graphql" []

main ∷ Effect Unit
main =
  launchAff_  do
    { conferences } <- client (Gql :: Gql ReactFinlandConferences) {}
    for_ conferences \{ id } -> do
      { conference: { websiteUrl, speakers } } <- client (Gql :: Gql ReactFinlandConference) { id }
      Log.info websiteUrl
      Log.info $ show speakers

You can check out the test for a full example.