Skip to content

Commit f8a25c9

Browse files
committed
Update README for PostGraphile v5 config
1 parent 5e6c801 commit f8a25c9

File tree

1 file changed

+66
-47
lines changed

1 file changed

+66
-47
lines changed

README.md

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ yarn add postgraphile postgraphile-plugin-connection-filter
1818
Add to your `graphile.config.ts` configuration:
1919

2020
```ts
21+
import { makePgService } from "postgraphile/adaptors/pg";
22+
import { PostGraphileAmberPreset } from "postgraphile/presets/amber";
2123
import { PostGraphileConnectionFilterPreset } from "postgraphile-plugin-connection-filter";
2224

23-
const preset = {
24-
extends: [PostGraphileConnectionFilterPreset],
25+
const preset: GraphileConfig.Preset = {
26+
extends: [PostGraphileAmberPreset, PostGraphileConnectionFilterPreset],
27+
pgServices: [
28+
makePgService({
29+
connectionString: process.env.DATABASE_URL!,
30+
schemas: ["app_public"],
31+
}),
32+
],
2533
};
2634

2735
export default preset;
@@ -64,15 +72,16 @@ To allow `null` and `{}` in inputs, use the `connectionFilterAllowNullInput` and
6472

6573
## Plugin Options
6674

67-
When using PostGraphile as a library, the following plugin options can be passed via `graphileBuildOptions`:
75+
These options live in the `schema` section of your Graphile config:
6876

6977
#### connectionFilterAllowedOperators
7078

7179
Restrict filtering to specific operators:
7280

73-
```js
74-
postgraphile(pgConfig, schema, {
75-
graphileBuildOptions: {
81+
```ts
82+
const preset: GraphileConfig.Preset = {
83+
extends: [PostGraphileConnectionFilterPreset],
84+
schema: {
7685
connectionFilterAllowedOperators: [
7786
"isNull",
7887
"equalTo",
@@ -87,19 +96,20 @@ postgraphile(pgConfig, schema, {
8796
"notIn",
8897
],
8998
},
90-
});
99+
};
91100
```
92101

93102
#### connectionFilterAllowedFieldTypes
94103

95104
Restrict filtering to specific field types:
96105

97-
```js
98-
postgraphile(pgConfig, schema, {
99-
graphileBuildOptions: {
106+
```ts
107+
const preset: GraphileConfig.Preset = {
108+
extends: [PostGraphileConnectionFilterPreset],
109+
schema: {
100110
connectionFilterAllowedFieldTypes: ["String", "Int"],
101111
},
102-
});
112+
};
103113
```
104114

105115
The available field types will depend on your database schema.
@@ -108,24 +118,26 @@ The available field types will depend on your database schema.
108118

109119
Enable/disable filtering on PostgreSQL arrays:
110120

111-
```js
112-
postgraphile(pgConfig, schema, {
113-
graphileBuildOptions: {
121+
```ts
122+
const preset: GraphileConfig.Preset = {
123+
extends: [PostGraphileConnectionFilterPreset],
124+
schema: {
114125
connectionFilterArrays: false, // default: true
115126
},
116-
});
127+
};
117128
```
118129

119130
#### connectionFilterComputedColumns
120131

121132
Enable/disable filtering by computed columns:
122133

123-
```js
124-
postgraphile(pgConfig, schema, {
125-
graphileBuildOptions: {
134+
```ts
135+
const preset: GraphileConfig.Preset = {
136+
extends: [PostGraphileConnectionFilterPreset],
137+
schema: {
126138
connectionFilterComputedColumns: false, // default: true
127139
},
128-
});
140+
};
129141
```
130142

131143
Consider setting this to `false` and using `@filterable` [smart comments](https://www.graphile.org/postgraphile/smart-comments/) to selectively enable filtering:
@@ -141,39 +153,42 @@ comment on function app_public.foo_computed(foo app_public.foo) is E'@filterable
141153

142154
Use alternative names (e.g. `eq`, `ne`) for operators:
143155

144-
```js
145-
postgraphile(pgConfig, schema, {
146-
graphileBuildOptions: {
156+
```ts
157+
const preset: GraphileConfig.Preset = {
158+
extends: [PostGraphileConnectionFilterPreset],
159+
schema: {
147160
connectionFilterOperatorNames: {
148161
equalTo: "eq",
149162
notEqualTo: "ne",
150163
},
151164
},
152-
});
165+
};
153166
```
154167

155168
#### connectionFilterRelations
156169

157170
Enable/disable filtering on related fields:
158171

159-
```js
160-
postgraphile(pgConfig, schema, {
161-
graphileBuildOptions: {
172+
```ts
173+
const preset: GraphileConfig.Preset = {
174+
extends: [PostGraphileConnectionFilterPreset],
175+
schema: {
162176
connectionFilterRelations: true, // default: false
163177
},
164-
});
178+
};
165179
```
166180

167181
#### connectionFilterSetofFunctions
168182

169183
Enable/disable filtering on functions that return `setof`:
170184

171-
```js
172-
postgraphile(pgConfig, schema, {
173-
graphileBuildOptions: {
185+
```ts
186+
const preset: GraphileConfig.Preset = {
187+
extends: [PostGraphileConnectionFilterPreset],
188+
schema: {
174189
connectionFilterSetofFunctions: false, // default: true
175190
},
176-
});
191+
};
177192
```
178193

179194
Consider setting this to `false` and using `@filterable` [smart comments](https://www.graphile.org/postgraphile/smart-comments/) to selectively enable filtering:
@@ -189,24 +204,26 @@ comment on function app_public.some_foos() is E'@filterable';
189204

190205
Enable/disable filtering with logical operators (`and`/`or`/`not`):
191206

192-
```js
193-
postgraphile(pgConfig, schema, {
194-
graphileBuildOptions: {
207+
```ts
208+
const preset: GraphileConfig.Preset = {
209+
extends: [PostGraphileConnectionFilterPreset],
210+
schema: {
195211
connectionFilterLogicalOperators: false, // default: true
196212
},
197-
});
213+
};
198214
```
199215

200216
#### connectionFilterAllowNullInput
201217

202218
Allow/forbid `null` literals in input:
203219

204-
```js
205-
postgraphile(pgConfig, schema, {
206-
graphileBuildOptions: {
220+
```ts
221+
const preset: GraphileConfig.Preset = {
222+
extends: [PostGraphileConnectionFilterPreset],
223+
schema: {
207224
connectionFilterAllowNullInput: true, // default: false
208225
},
209-
});
226+
};
210227
```
211228

212229
When `false`, passing `null` as a field value will throw an error.
@@ -216,12 +233,13 @@ When `true`, passing `null` as a field value is equivalent to omitting the field
216233

217234
Allow/forbid empty objects (`{}`) in input:
218235

219-
```js
220-
postgraphile(pgConfig, schema, {
221-
graphileBuildOptions: {
236+
```ts
237+
const preset: GraphileConfig.Preset = {
238+
extends: [PostGraphileConnectionFilterPreset],
239+
schema: {
222240
connectionFilterAllowEmptyObjectInput: true, // default: false
223241
},
224-
});
242+
};
225243
```
226244

227245
When `false`, passing `{}` as a field value will throw an error.
@@ -237,12 +255,13 @@ inflection to omit the `-list` suffix, e.g. using
237255
`@graphile-contrib/pg-simplify-inflector`'s `pgOmitListSuffix` option. Use this
238256
if you see `Connection` added to your filter field names.
239257

240-
```js
241-
postgraphile(pgConfig, schema, {
242-
graphileBuildOptions: {
258+
```ts
259+
const preset: GraphileConfig.Preset = {
260+
extends: [PostGraphileConnectionFilterPreset],
261+
schema: {
243262
connectionFilterUseListInflectors: true, // default: false
244263
},
245-
});
264+
};
246265
```
247266

248267
## Examples

0 commit comments

Comments
 (0)