|
| 1 | +# GraphpostgresQL -- a graph interface to relational data |
| 2 | + |
| 3 | +GraphpostgresQL is inspired by Facebook's [`graphql`][graphql]. By using table |
| 4 | +introspection, GraphpostgresQL is able to follow foreign keys and index into |
| 5 | +complex datatypes like `json`, `jsonb` and `hstore`. |
| 6 | + |
| 7 | +[graphql]: https://www.npmjs.com/package/graphql |
| 8 | + |
| 9 | + |
| 10 | +# A Proof of Concept |
| 11 | + |
| 12 | +GraphpostgresQL is alpha quality and has undergone neither extensive |
| 13 | +optimization nor comprehensive testing. To use it for production workloads |
| 14 | +would needlessly tempt fate. |
| 15 | + |
| 16 | + |
| 17 | +# Install GraphpostgresQL |
| 18 | + |
| 19 | +Using `psql`, load the `graphql` schema file: |
| 20 | + |
| 21 | +```sql |
| 22 | +\i graphql.sql |
| 23 | +``` |
| 24 | + |
| 25 | +All definitions are created under the `graphql` schema. GraphpostgresQL |
| 26 | +doesn't load any extensions or alter the `search_path`. If an older version of |
| 27 | +GraphpostgresQL is loaded, the new installation will overwrite it. |
| 28 | + |
| 29 | + |
| 30 | +# Using GraphpostgresQL |
| 31 | + |
| 32 | +To generate a query, use `graphql.to_sql(text)`: |
| 33 | + |
| 34 | +```sql |
| 35 | +SELECT graphql.to_sql($$ |
| 36 | + user("f3411edc-e1d0-452a-bc19-b42c0d5a0e36") { |
| 37 | + full_name, |
| 38 | + friendship |
| 39 | + } |
| 40 | +$$); |
| 41 | +``` |
| 42 | + |
| 43 | +Which should result in something like: |
| 44 | + |
| 45 | +```sql |
| 46 | +SELECT to_json("sub/2") AS "user" |
| 47 | + FROM "user", |
| 48 | + LATERAL ( |
| 49 | + SELECT json_agg("user") AS friendship |
| 50 | + FROM "user" |
| 51 | + JOIN friendship ON (("user".id) = (friendship.second)) |
| 52 | + WHERE (friendship.first) |
| 53 | + = ('f3411edc-e1d0-452a-bc19-b42c0d5a0e36'::uuid) |
| 54 | + ) AS "sub/1", |
| 55 | + LATERAL ( |
| 56 | + SELECT "user".full_name, "sub/1".friendship |
| 57 | + ) AS "sub/2" |
| 58 | + WHERE (("user".id) = ('f3411edc-e1d0-452a-bc19-b42c0d5a0e36'::uuid)) |
| 59 | +``` |
| 60 | + |
| 61 | +To run a query, use `graphql.run(text)` instead of `graphql.to_sql(text)`. |
| 62 | + |
| 63 | + |
| 64 | +# Removing GraphpostgresQL |
| 65 | + |
| 66 | +It's easy to remove GraphpostgresQL: |
| 67 | + |
| 68 | +```sql |
| 69 | +DROP SCHEMA IF EXISTS graphql CASCADE; |
| 70 | +``` |
0 commit comments