Type-safe GraphQL queries using functional dependencies.
Go to file
2023-06-30 09:07:03 +01:00
.github/workflows Adds tests to the pipeline 2023-06-19 14:58:51 +03:00
src use pre-made type to avoid confusion 2023-06-29 10:19:17 +01:00
test Updates to ps15 syntax 2023-06-20 09:43:35 +03:00
.envrc readme update; nix flake; hints on how to run. 2023-06-30 09:07:03 +01:00
.gitignore readme update; nix flake; hints on how to run. 2023-06-30 09:07:03 +01:00
.psc-ide-port Updates to ps15 syntax 2023-06-20 09:43:35 +03:00
flake.lock readme update; nix flake; hints on how to run. 2023-06-30 09:07:03 +01:00
flake.nix readme update; nix flake; hints on how to run. 2023-06-30 09:07:03 +01:00
LICENSE Create LICENSE 2021-05-19 12:40:08 +03:00
package-lock.json Adds back package-lock.json 2023-06-20 09:46:26 +03:00
package.json Updates package set 2023-06-20 09:37:52 +03:00
packages.dhall Updates package set 2023-06-20 09:37:52 +03:00
README.md readme update; nix flake; hints on how to run. 2023-06-30 09:07:03 +01:00
spago.dhall Updates to ps15 syntax 2023-06-20 09:43:35 +03:00
test.dhall Update for PureScript 0.15.0 2022-04-21 13:48:21 +02: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 :: GraphQLClientAff
client = graphQL "https://api.react-finland.fi/graphql" [] driver

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.

Development

You can either use the nix shell, or the npm package.

Nix shell

Having set up flakes, either using direnv (direnv allow) or nix develop

Buliding:

spago build

Testing:

spago -x test.dhall test

Npm

Just run npm i and then:

Building:

spago build

Testing:

npm run test