Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rowtype-yoga/purescript-graphql-fundeps
Type-safe GraphQL queries using functional dependencies.
https://github.com/rowtype-yoga/purescript-graphql-fundeps
graphql purescript
Last synced: 25 days ago
JSON representation
Type-safe GraphQL queries using functional dependencies.
- Host: GitHub
- URL: https://github.com/rowtype-yoga/purescript-graphql-fundeps
- Owner: rowtype-yoga
- License: apache-2.0
- Created: 2021-05-19T09:35:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-30T08:07:04.000Z (over 1 year ago)
- Last Synced: 2024-08-25T22:45:22.583Z (5 months ago)
- Topics: graphql, purescript
- Language: PureScript
- Homepage:
- Size: 122 KB
- Stars: 22
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-purescript - graphql-fundeps - GraphQL client. (GraphQL / Http routing)
README
# 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.```purescript
endpoint = "https://api.react-finland.fi/graphql" :: Stringforeign 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" [] drivermain ∷ 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](./test/Main.purs) for a full example.
## Development
You can either use the nix shell, or the npm package.
### Nix shell
Having set up [flakes](https://nixos.wiki/wiki/Flakes), either using [direnv](https://direnv.net/) (`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
```