https://github.com/ian-barnes/dream-postgres-graphql
Playing around with Dream, trying to get pagination of GraphQL queries working...
https://github.com/ian-barnes/dream-postgres-graphql
Last synced: 8 months ago
JSON representation
Playing around with Dream, trying to get pagination of GraphQL queries working...
- Host: GitHub
- URL: https://github.com/ian-barnes/dream-postgres-graphql
- Owner: ian-barnes
- Created: 2021-07-29T12:17:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-08T14:47:52.000Z (over 4 years ago)
- Last Synced: 2024-08-04T01:28:22.688Z (over 1 year ago)
- Language: OCaml
- Size: 15.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - dream-postgres-graphql - barnes | 3 | (OCaml)
README
# dream-postgres-graphql
Combines a few of the features of some of the Dream examples, in particular
`h-sql`, `i-graphql` and `w-postgres`. Accesses the `person` table in a `demo`
database.
The URL `/view` displays an HTML view of everything in the database table. Using
the query query parameters `after` and/or `first` gives a partial Relay-style
pagination. For example, `/view?after=2&first=3` will get the 3rd, 4th and 5th
rows of the table.
The URL `/` displays a GraphiQL interface to a GraphQL schema for the same
table. The `person` query has the same optional `after` and `first` pagination
arguments.
## Files
- `bin/main.ml`: Main program / starting point. This is where you see the Dream
handler / middleware / router pipeline.
- `lib/person.ml[i]`: Person model
- `lib/sql.ml[i]`: Caqti types and query for fetching people from the database
- `lib/api.ml[i]`: GraphQL schema definition
- `templates/person.eml.html`: HTML/OCaml template for displaying a single
person as a table row. (A bit like a Jinja2 macro.)
- `templates/page.eml.html`: HTML/OCaml template for the people page
- `db.sql`: Postgres database dump with schema and data
## Setup
After cloning this repo, do:
```
opam install dream caqti-driver-postgresql
```
Create an empty Postgres database called `demo`, then run
```psql --file=db.sql demo```
and it should create and populate the tables you'll need.
## Build
```
dune build
```
## Run
```
dune exec main
```
And then point your browser at .