Skip to content

Commit 567722e

Browse files
benjaiebenjie
andauthored
Update README for PostGraphile v5 config (#60)
Co-authored-by: Benjie Gillam <benjie@jemjie.com>
1 parent c1c310e commit 567722e

1 file changed

Lines changed: 34 additions & 54 deletions

File tree

README.md

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
[![Package on npm](https://img.shields.io/npm/v/@graphile-contrib/pg-order-by-related.svg)](https://www.npmjs.com/package/@graphile-contrib/pg-order-by-related)
44

5-
This Graphile Engine plugin adds additional enum values to the `orderBy` argument on connections, allowing you to order by columns in related tables.
5+
This plugin adds additional enum values to the `orderBy` argument on
6+
connections, allowing you to order by columns in related tables.
67

7-
> Requires `postgraphile@^4.3.1` or `graphile-build-pg@^4.3.1`
8+
> Requires `postgraphile@^5.0.0`
89
910
Example:
1011

@@ -28,74 +29,53 @@ One-to-one and many-to-one relations are supported. For one-to-many relations, `
2829

2930
## Usage
3031

31-
Append this plugin and the additional `orderBy` options will be added to your schema.
32-
33-
### CLI
34-
35-
```bash
36-
yarn add postgraphile
37-
yarn add @graphile-contrib/pg-order-by-related
38-
npx postgraphile --append-plugins @graphile-contrib/pg-order-by-related
39-
```
40-
41-
### Library
42-
43-
```js
44-
const express = require("express");
45-
const { postgraphile } = require("postgraphile");
46-
const PgOrderByRelatedPlugin = require("@graphile-contrib/pg-order-by-related");
47-
48-
const app = express();
49-
50-
app.use(
51-
postgraphile(process.env.DATABASE_URL, "app_public", {
52-
appendPlugins: [PgOrderByRelatedPlugin],
53-
graphiql: true,
54-
})
55-
);
56-
57-
app.listen(5000);
32+
Add the plugin to the `plugins` list in your Graphile config:
33+
34+
```ts
35+
import { makePgService } from "postgraphile/adaptors/pg";
36+
import { PostGraphileAmberPreset } from "postgraphile/presets/amber";
37+
import { PgOrderByRelatedPlugin } from "@graphile-contrib/pg-order-by-related";
38+
39+
const preset: GraphileConfig.Preset = {
40+
extends: [PostGraphileAmberPreset],
41+
plugins: [PgOrderByRelatedPlugin],
42+
pgServices: [
43+
makePgService({
44+
connectionString: process.env.DATABASE_URL!,
45+
schemas: ["app_public"],
46+
}),
47+
],
48+
};
49+
50+
export default preset;
5851
```
5952

6053
## Inflection
6154

62-
To avoid naming conflicts, this plugin uses a `<TABLE>_BY_<KEY>` naming convention (e.g. `USER_BY_AUTHOR_ID__CREATED_AT_ASC`), similar to how related fields are named by default in PostGraphile v4.
63-
64-
You can override this by adding an inflector plugin. For example, the following plugin shortens the names by dropping the `<TABLE>_BY` portion (producing e.g. `AUTHOR_ID__CREATED_AT_ASC`):
55+
To avoid naming conflicts, this plugin uses a `<TABLE>_BY_<KEY>` naming
56+
convention (e.g. `USER_BY_AUTHOR_ID__CREATED_AT_ASC`).
6557

66-
```js
67-
const { makeAddInflectorsPlugin } = require("graphile-utils");
68-
69-
module.exports = makeAddInflectorsPlugin(
70-
{
71-
orderByRelatedColumnEnum(attr, ascending, foreignTable, keyAttributes) {
72-
return `${this.constantCase(
73-
keyAttributes.map((keyAttr) => this._columnName(keyAttr)).join("-and-")
74-
)}__${this.orderByColumnEnum(attr, ascending)}`;
75-
},
76-
},
77-
true // Passing true here allows the plugin to overwrite existing inflectors.
78-
);
79-
```
80-
81-
See the [makeAddInflectorsPlugin documentation](https://www.graphile.org/postgraphile/make-add-inflectors-plugin/) for more information.
58+
You can override this with a custom V5 inflection plugin if you want shorter or
59+
more domain-specific enum names. See the
60+
[inflection documentation](https://postgraphile.org/postgraphile/next/inflection)
61+
for the current plugin patterns.
8262

8363
## Options
8464

85-
When using PostGraphile as a library, the following options can be specified via `graphileBuildOptions`.
86-
8765
### orderByRelatedColumnAggregates
8866

8967
Adds additional enum values for column aggregates (currently `min` and `max`) for one-to-many relationships.
9068

9169
Example:
9270

93-
```js
94-
postgraphile(pgConfig, schema, {
95-
graphileBuildOptions: {
71+
```ts
72+
const preset: GraphileConfig.Preset = {
73+
extends: [PostGraphileAmberPreset],
74+
plugins: [PgOrderByRelatedPlugin],
75+
schema: {
9676
orderByRelatedColumnAggregates: true,
9777
},
98-
});
78+
};
9979
```
10080

10181
```graphql

0 commit comments

Comments
 (0)