graphile-plugin-connection-filter-postgis 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -86
- package/esm/index.d.ts +18 -0
- package/esm/index.js +19 -24
- package/esm/plugin.d.ts +14 -0
- package/esm/plugin.js +280 -0
- package/esm/preset.d.ts +23 -0
- package/esm/preset.js +25 -0
- package/esm/types.d.ts +23 -0
- package/esm/types.js +1 -0
- package/index.d.ts +18 -4
- package/index.js +22 -28
- package/package.json +45 -41
- package/plugin.d.ts +14 -0
- package/plugin.js +286 -0
- package/preset.d.ts +23 -0
- package/preset.js +28 -0
- package/types.d.ts +23 -0
- package/types.js +2 -0
- package/PgConnectionArgFilterPostgisOperatorsPlugin.d.ts +0 -3
- package/PgConnectionArgFilterPostgisOperatorsPlugin.js +0 -219
- package/esm/PgConnectionArgFilterPostgisOperatorsPlugin.js +0 -217
package/README.md
CHANGED
|
@@ -1,100 +1,66 @@
|
|
|
1
1
|
# graphile-plugin-connection-filter-postgis
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<p align="center" width="100%">
|
|
8
|
-
<a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
|
|
9
|
-
<img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
-
</a>
|
|
11
|
-
<a href="https://github.com/constructive-io/constructive/blob/main/LICENSE">
|
|
12
|
-
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
13
|
-
</a>
|
|
14
|
-
<a href="https://www.npmjs.com/package/graphile-plugin-connection-filter-postgis">
|
|
15
|
-
<img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=graphile%2Fgraphile-plugin-connection-filter-postgis%2Fpackage.json"/>
|
|
16
|
-
</a>
|
|
17
|
-
</p>
|
|
18
|
-
|
|
19
|
-
**`graphile-plugin-connection-filter-postgis`** exposes PostGIS-aware operators on the `filter` argument for PostGraphile connections.
|
|
20
|
-
|
|
21
|
-
## 🚀 Installation
|
|
3
|
+
PostGIS spatial filter operators for `postgraphile-plugin-connection-filter` (PostGraphile v5).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
22
6
|
|
|
23
7
|
```bash
|
|
24
8
|
npm install graphile-plugin-connection-filter-postgis
|
|
25
9
|
```
|
|
26
10
|
|
|
27
|
-
##
|
|
28
|
-
|
|
29
|
-
- Adds PostGIS functions and operators to `graphile-plugin-connection-filter`
|
|
30
|
-
- Supports both `geometry` and `geography` columns
|
|
31
|
-
- Works with PostGraphile v4 filter inputs
|
|
32
|
-
|
|
33
|
-
## 📦 Usage
|
|
11
|
+
## Usage
|
|
34
12
|
|
|
35
|
-
|
|
13
|
+
```typescript
|
|
14
|
+
import { GraphilePostgisPreset } from 'graphile-postgis';
|
|
15
|
+
import { PostGraphileConnectionFilterPreset } from 'postgraphile-plugin-connection-filter';
|
|
16
|
+
import { PostgisConnectionFilterPreset } from 'graphile-plugin-connection-filter-postgis';
|
|
36
17
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
app.use(
|
|
46
|
-
postgraphile(pgConfig, schemas, {
|
|
47
|
-
appendPlugins: [
|
|
48
|
-
PostGISPlugin,
|
|
49
|
-
ConnectionFilterPlugin,
|
|
50
|
-
PostGISFilterPlugin
|
|
51
|
-
]
|
|
52
|
-
})
|
|
53
|
-
);
|
|
18
|
+
const preset = {
|
|
19
|
+
extends: [
|
|
20
|
+
GraphilePostgisPreset,
|
|
21
|
+
PostGraphileConnectionFilterPreset,
|
|
22
|
+
PostgisConnectionFilterPreset
|
|
23
|
+
]
|
|
24
|
+
};
|
|
54
25
|
```
|
|
55
26
|
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```sh
|
|
95
|
-
# requires a local Postgres with PostGIS available (defaults to postgres/password@localhost:5432)
|
|
96
|
-
pnpm --filter graphile-plugin-connection-filter-postgis test
|
|
97
|
-
```
|
|
27
|
+
## Operators
|
|
28
|
+
|
|
29
|
+
### Function-based operators (geometry)
|
|
30
|
+
|
|
31
|
+
- `contains` — ST_Contains
|
|
32
|
+
- `containsProperly` — ST_ContainsProperly
|
|
33
|
+
- `crosses` — ST_Crosses
|
|
34
|
+
- `disjoint` — ST_Disjoint
|
|
35
|
+
- `equals` — ST_Equals
|
|
36
|
+
- `intersects` — ST_Intersects
|
|
37
|
+
- `intersects3D` — ST_3DIntersects
|
|
38
|
+
- `orderingEquals` — ST_OrderingEquals
|
|
39
|
+
- `overlaps` — ST_Overlaps
|
|
40
|
+
- `touches` — ST_Touches
|
|
41
|
+
- `within` — ST_Within
|
|
42
|
+
|
|
43
|
+
### Function-based operators (geometry + geography)
|
|
44
|
+
|
|
45
|
+
- `coveredBy` — ST_CoveredBy
|
|
46
|
+
- `covers` — ST_Covers
|
|
47
|
+
- `intersects` — ST_Intersects
|
|
48
|
+
|
|
49
|
+
### Bounding box operators
|
|
50
|
+
|
|
51
|
+
- `bboxIntersects2D` — `&&`
|
|
52
|
+
- `bboxIntersectsND` — `&&&`
|
|
53
|
+
- `bboxOverlapsOrLeftOf` — `&<`
|
|
54
|
+
- `bboxOverlapsOrBelow` — `&<|`
|
|
55
|
+
- `bboxOverlapsOrRightOf` — `&>`
|
|
56
|
+
- `bboxOverlapsOrAbove` — `|&>`
|
|
57
|
+
- `bboxLeftOf` — `<<`
|
|
58
|
+
- `bboxBelow` — `<<|`
|
|
59
|
+
- `bboxRightOf` — `>>`
|
|
60
|
+
- `bboxAbove` — `|>>`
|
|
61
|
+
- `bboxContains` — `~`
|
|
62
|
+
- `bboxEquals` — `~=`
|
|
63
|
+
- `exactlyEquals` — `=`
|
|
98
64
|
|
|
99
65
|
---
|
|
100
66
|
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostGIS Connection Filter Plugin for PostGraphile v5
|
|
3
|
+
*
|
|
4
|
+
* Adds PostGIS spatial filter operators (ST_Contains, ST_Intersects, etc.)
|
|
5
|
+
* to postgraphile-plugin-connection-filter.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { PostgisConnectionFilterPreset } from 'graphile-plugin-connection-filter-postgis';
|
|
10
|
+
*
|
|
11
|
+
* const preset = {
|
|
12
|
+
* extends: [PostgisConnectionFilterPreset]
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export { PostgisConnectionFilterPreset } from './preset';
|
|
17
|
+
export { PgConnectionArgFilterPostgisOperatorsPlugin } from './plugin';
|
|
18
|
+
export type { PostgisFilterOperatorSpec, ResolvedFilterSpec } from './types';
|
package/esm/index.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
PostgisOperatorsPlugin(builder, options);
|
|
22
|
-
};
|
|
23
|
-
export { PostGraphileConnectionFilterPostgisPlugin };
|
|
24
|
-
export default PostGraphileConnectionFilterPostgisPlugin;
|
|
1
|
+
/**
|
|
2
|
+
* PostGIS Connection Filter Plugin for PostGraphile v5
|
|
3
|
+
*
|
|
4
|
+
* Adds PostGIS spatial filter operators (ST_Contains, ST_Intersects, etc.)
|
|
5
|
+
* to postgraphile-plugin-connection-filter.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { PostgisConnectionFilterPreset } from 'graphile-plugin-connection-filter-postgis';
|
|
10
|
+
*
|
|
11
|
+
* const preset = {
|
|
12
|
+
* extends: [PostgisConnectionFilterPreset]
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
// Preset (recommended entry point)
|
|
17
|
+
export { PostgisConnectionFilterPreset } from './preset';
|
|
18
|
+
// Plugin
|
|
19
|
+
export { PgConnectionArgFilterPostgisOperatorsPlugin } from './plugin';
|
package/esm/plugin.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'graphile-build';
|
|
2
|
+
import type { GraphileConfig } from 'graphile-config';
|
|
3
|
+
/**
|
|
4
|
+
* PgConnectionArgFilterPostgisOperatorsPlugin
|
|
5
|
+
*
|
|
6
|
+
* Adds PostGIS spatial filter operators to postgraphile-plugin-connection-filter.
|
|
7
|
+
*
|
|
8
|
+
* Includes:
|
|
9
|
+
* - ST_ function-based operators (contains, intersects, within, etc.)
|
|
10
|
+
* - SQL operator-based operators (&&, =, ~, etc. for bounding box ops)
|
|
11
|
+
*
|
|
12
|
+
* Requires graphile-postgis and postgraphile-plugin-connection-filter to be loaded.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PgConnectionArgFilterPostgisOperatorsPlugin: GraphileConfig.Plugin;
|
package/esm/plugin.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import 'graphile-build';
|
|
2
|
+
import sql from 'pg-sql2';
|
|
3
|
+
import { CONCRETE_SUBTYPES } from 'graphile-postgis';
|
|
4
|
+
const ALLOWED_SQL_OPERATORS = new Set([
|
|
5
|
+
'=',
|
|
6
|
+
'&&',
|
|
7
|
+
'&&&',
|
|
8
|
+
'&<',
|
|
9
|
+
'&<|',
|
|
10
|
+
'&>',
|
|
11
|
+
'|&>',
|
|
12
|
+
'<<',
|
|
13
|
+
'<<|',
|
|
14
|
+
'>>',
|
|
15
|
+
'|>>',
|
|
16
|
+
'~',
|
|
17
|
+
'~=',
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* PgConnectionArgFilterPostgisOperatorsPlugin
|
|
21
|
+
*
|
|
22
|
+
* Adds PostGIS spatial filter operators to postgraphile-plugin-connection-filter.
|
|
23
|
+
*
|
|
24
|
+
* Includes:
|
|
25
|
+
* - ST_ function-based operators (contains, intersects, within, etc.)
|
|
26
|
+
* - SQL operator-based operators (&&, =, ~, etc. for bounding box ops)
|
|
27
|
+
*
|
|
28
|
+
* Requires graphile-postgis and postgraphile-plugin-connection-filter to be loaded.
|
|
29
|
+
*/
|
|
30
|
+
export const PgConnectionArgFilterPostgisOperatorsPlugin = {
|
|
31
|
+
name: 'PgConnectionArgFilterPostgisOperatorsPlugin',
|
|
32
|
+
version: '2.0.0',
|
|
33
|
+
description: 'Adds PostGIS spatial filter operators to connection filter',
|
|
34
|
+
after: [
|
|
35
|
+
'PostgisRegisterTypesPlugin',
|
|
36
|
+
'PostgisExtensionDetectionPlugin',
|
|
37
|
+
'PostgisInflectionPlugin',
|
|
38
|
+
'PgConnectionArgFilterPlugin'
|
|
39
|
+
],
|
|
40
|
+
schema: {
|
|
41
|
+
hooks: {
|
|
42
|
+
init(_, build) {
|
|
43
|
+
const postgisInfo = build.pgGISExtensionInfo;
|
|
44
|
+
if (!postgisInfo) {
|
|
45
|
+
return _;
|
|
46
|
+
}
|
|
47
|
+
const addConnectionFilterOperator = build.addConnectionFilterOperator;
|
|
48
|
+
if (typeof addConnectionFilterOperator !== 'function') {
|
|
49
|
+
return _;
|
|
50
|
+
}
|
|
51
|
+
const { inflection } = build;
|
|
52
|
+
const { schemaName, geometryCodec, geographyCodec } = postgisInfo;
|
|
53
|
+
// Collect all GQL type names for geometry and geography
|
|
54
|
+
const gqlTypeNamesByBase = {
|
|
55
|
+
geometry: [],
|
|
56
|
+
geography: []
|
|
57
|
+
};
|
|
58
|
+
const codecPairs = [['geometry', geometryCodec]];
|
|
59
|
+
if (geographyCodec) {
|
|
60
|
+
codecPairs.push(['geography', geographyCodec]);
|
|
61
|
+
}
|
|
62
|
+
for (const [baseKey, codec] of codecPairs) {
|
|
63
|
+
const typeName = codec.name;
|
|
64
|
+
gqlTypeNamesByBase[baseKey].push(inflection.gisInterfaceName(typeName));
|
|
65
|
+
for (const subtype of CONCRETE_SUBTYPES) {
|
|
66
|
+
for (const hasZ of [false, true]) {
|
|
67
|
+
for (const hasM of [false, true]) {
|
|
68
|
+
gqlTypeNamesByBase[baseKey].push(inflection.gisType(typeName, subtype, hasZ, hasM, 0));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// PostGIS function-based operators
|
|
74
|
+
const functionSpecs = [
|
|
75
|
+
[
|
|
76
|
+
'ST_3DIntersects',
|
|
77
|
+
['geometry'],
|
|
78
|
+
'intersects3D',
|
|
79
|
+
'They share any portion of space in 3D.'
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
'ST_Contains',
|
|
83
|
+
['geometry'],
|
|
84
|
+
'contains',
|
|
85
|
+
'No points of the specified geometry lie in the exterior, and at least one point of the interior of the specified geometry lies in the interior.'
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
'ST_ContainsProperly',
|
|
89
|
+
['geometry'],
|
|
90
|
+
'containsProperly',
|
|
91
|
+
'The specified geometry intersects the interior but not the boundary (or exterior).'
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
'ST_CoveredBy',
|
|
95
|
+
['geometry', 'geography'],
|
|
96
|
+
'coveredBy',
|
|
97
|
+
'No point is outside the specified geometry.'
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
'ST_Covers',
|
|
101
|
+
['geometry', 'geography'],
|
|
102
|
+
'covers',
|
|
103
|
+
'No point in the specified geometry is outside.'
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
'ST_Crosses',
|
|
107
|
+
['geometry'],
|
|
108
|
+
'crosses',
|
|
109
|
+
'They have some, but not all, interior points in common.'
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
'ST_Disjoint',
|
|
113
|
+
['geometry'],
|
|
114
|
+
'disjoint',
|
|
115
|
+
'They do not share any space together.'
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
'ST_Equals',
|
|
119
|
+
['geometry'],
|
|
120
|
+
'equals',
|
|
121
|
+
'They represent the same geometry. Directionality is ignored.'
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
'ST_Intersects',
|
|
125
|
+
['geometry', 'geography'],
|
|
126
|
+
'intersects',
|
|
127
|
+
'They share any portion of space in 2D.'
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
'ST_OrderingEquals',
|
|
131
|
+
['geometry'],
|
|
132
|
+
'orderingEquals',
|
|
133
|
+
'They represent the same geometry and points are in the same directional order.'
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
'ST_Overlaps',
|
|
137
|
+
['geometry'],
|
|
138
|
+
'overlaps',
|
|
139
|
+
'They share space, are of the same dimension, but are not completely contained by each other.'
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
'ST_Touches',
|
|
143
|
+
['geometry'],
|
|
144
|
+
'touches',
|
|
145
|
+
'They have at least one point in common, but their interiors do not intersect.'
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
'ST_Within',
|
|
149
|
+
['geometry'],
|
|
150
|
+
'within',
|
|
151
|
+
'Completely inside the specified geometry.'
|
|
152
|
+
]
|
|
153
|
+
];
|
|
154
|
+
// SQL operator-based operators
|
|
155
|
+
const operatorSpecs = [
|
|
156
|
+
[
|
|
157
|
+
'=',
|
|
158
|
+
['geometry', 'geography'],
|
|
159
|
+
'exactlyEquals',
|
|
160
|
+
'Coordinates and coordinate order are the same as specified geometry.'
|
|
161
|
+
],
|
|
162
|
+
[
|
|
163
|
+
'&&',
|
|
164
|
+
['geometry', 'geography'],
|
|
165
|
+
'bboxIntersects2D',
|
|
166
|
+
"2D bounding box intersects the specified geometry's 2D bounding box."
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
'&&&',
|
|
170
|
+
['geometry'],
|
|
171
|
+
'bboxIntersectsND',
|
|
172
|
+
"n-D bounding box intersects the specified geometry's n-D bounding box."
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
'&<',
|
|
176
|
+
['geometry'],
|
|
177
|
+
'bboxOverlapsOrLeftOf',
|
|
178
|
+
"Bounding box overlaps or is to the left of the specified geometry's bounding box."
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
'&<|',
|
|
182
|
+
['geometry'],
|
|
183
|
+
'bboxOverlapsOrBelow',
|
|
184
|
+
"Bounding box overlaps or is below the specified geometry's bounding box."
|
|
185
|
+
],
|
|
186
|
+
[
|
|
187
|
+
'&>',
|
|
188
|
+
['geometry'],
|
|
189
|
+
'bboxOverlapsOrRightOf',
|
|
190
|
+
"Bounding box overlaps or is to the right of the specified geometry's bounding box."
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
'|&>',
|
|
194
|
+
['geometry'],
|
|
195
|
+
'bboxOverlapsOrAbove',
|
|
196
|
+
"Bounding box overlaps or is above the specified geometry's bounding box."
|
|
197
|
+
],
|
|
198
|
+
[
|
|
199
|
+
'<<',
|
|
200
|
+
['geometry'],
|
|
201
|
+
'bboxLeftOf',
|
|
202
|
+
"Bounding box is strictly to the left of the specified geometry's bounding box."
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
'<<|',
|
|
206
|
+
['geometry'],
|
|
207
|
+
'bboxBelow',
|
|
208
|
+
"Bounding box is strictly below the specified geometry's bounding box."
|
|
209
|
+
],
|
|
210
|
+
[
|
|
211
|
+
'>>',
|
|
212
|
+
['geometry'],
|
|
213
|
+
'bboxRightOf',
|
|
214
|
+
"Bounding box is strictly to the right of the specified geometry's bounding box."
|
|
215
|
+
],
|
|
216
|
+
[
|
|
217
|
+
'|>>',
|
|
218
|
+
['geometry'],
|
|
219
|
+
'bboxAbove',
|
|
220
|
+
"Bounding box is strictly above the specified geometry's bounding box."
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
'~',
|
|
224
|
+
['geometry'],
|
|
225
|
+
'bboxContains',
|
|
226
|
+
"Bounding box contains the specified geometry's bounding box."
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
'~=',
|
|
230
|
+
['geometry'],
|
|
231
|
+
'bboxEquals',
|
|
232
|
+
"Bounding box is the same as the specified geometry's bounding box."
|
|
233
|
+
]
|
|
234
|
+
];
|
|
235
|
+
const allSpecs = [];
|
|
236
|
+
// Process function-based operators
|
|
237
|
+
for (const [fn, baseTypes, operatorName, description] of functionSpecs) {
|
|
238
|
+
for (const baseType of baseTypes) {
|
|
239
|
+
const sqlGisFunction = sql.identifier(schemaName, fn.toLowerCase());
|
|
240
|
+
allSpecs.push({
|
|
241
|
+
typeNames: gqlTypeNamesByBase[baseType],
|
|
242
|
+
operatorName,
|
|
243
|
+
description,
|
|
244
|
+
resolve: (i, v) => sql.fragment `${sqlGisFunction}(${i}, ${v})`
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Process SQL operator-based operators
|
|
249
|
+
for (const [op, baseTypes, operatorName, description] of operatorSpecs) {
|
|
250
|
+
if (!ALLOWED_SQL_OPERATORS.has(op)) {
|
|
251
|
+
throw new Error(`Unexpected SQL operator: ${op}`);
|
|
252
|
+
}
|
|
253
|
+
for (const baseType of baseTypes) {
|
|
254
|
+
allSpecs.push({
|
|
255
|
+
typeNames: gqlTypeNamesByBase[baseType],
|
|
256
|
+
operatorName,
|
|
257
|
+
description,
|
|
258
|
+
resolve: (i, v) => sql.fragment `${i} ${sql.raw(op)} ${v}`
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Sort by operator name for deterministic schema output
|
|
263
|
+
allSpecs.sort((a, b) => a.operatorName.localeCompare(b.operatorName));
|
|
264
|
+
// Register each operator with the connection filter plugin
|
|
265
|
+
for (const spec of allSpecs) {
|
|
266
|
+
for (const typeName of spec.typeNames) {
|
|
267
|
+
addConnectionFilterOperator(typeName, spec.operatorName, {
|
|
268
|
+
description: spec.description,
|
|
269
|
+
resolveType: (fieldType) => fieldType,
|
|
270
|
+
resolve(sqlIdentifier, sqlValue, _input, _$where, _details) {
|
|
271
|
+
return spec.resolve(sqlIdentifier, sqlValue);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return _;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
package/esm/preset.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GraphileConfig } from 'graphile-config';
|
|
2
|
+
/**
|
|
3
|
+
* PostGIS Connection Filter Preset
|
|
4
|
+
*
|
|
5
|
+
* Adds PostGIS spatial filter operators to postgraphile-plugin-connection-filter.
|
|
6
|
+
* Requires graphile-postgis and postgraphile-plugin-connection-filter to be loaded.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { GraphilePostgisPreset } from 'graphile-postgis';
|
|
11
|
+
* import { PostGraphileConnectionFilterPreset } from 'postgraphile-plugin-connection-filter';
|
|
12
|
+
* import { PostgisConnectionFilterPreset } from 'graphile-plugin-connection-filter-postgis';
|
|
13
|
+
*
|
|
14
|
+
* const preset = {
|
|
15
|
+
* extends: [
|
|
16
|
+
* GraphilePostgisPreset,
|
|
17
|
+
* PostGraphileConnectionFilterPreset,
|
|
18
|
+
* PostgisConnectionFilterPreset
|
|
19
|
+
* ]
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const PostgisConnectionFilterPreset: GraphileConfig.Preset;
|
package/esm/preset.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PgConnectionArgFilterPostgisOperatorsPlugin } from './plugin';
|
|
2
|
+
/**
|
|
3
|
+
* PostGIS Connection Filter Preset
|
|
4
|
+
*
|
|
5
|
+
* Adds PostGIS spatial filter operators to postgraphile-plugin-connection-filter.
|
|
6
|
+
* Requires graphile-postgis and postgraphile-plugin-connection-filter to be loaded.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { GraphilePostgisPreset } from 'graphile-postgis';
|
|
11
|
+
* import { PostGraphileConnectionFilterPreset } from 'postgraphile-plugin-connection-filter';
|
|
12
|
+
* import { PostgisConnectionFilterPreset } from 'graphile-plugin-connection-filter-postgis';
|
|
13
|
+
*
|
|
14
|
+
* const preset = {
|
|
15
|
+
* extends: [
|
|
16
|
+
* GraphilePostgisPreset,
|
|
17
|
+
* PostGraphileConnectionFilterPreset,
|
|
18
|
+
* PostgisConnectionFilterPreset
|
|
19
|
+
* ]
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const PostgisConnectionFilterPreset = {
|
|
24
|
+
plugins: [PgConnectionArgFilterPostgisOperatorsPlugin]
|
|
25
|
+
};
|
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SQL } from 'pg-sql2';
|
|
2
|
+
export interface PostgisFilterOperatorSpec {
|
|
3
|
+
/** PostGIS SQL function name (e.g. 'ST_Contains') */
|
|
4
|
+
sqlFunction?: string;
|
|
5
|
+
/** SQL operator (e.g. '&&', '=') — used instead of sqlFunction for operator-based specs */
|
|
6
|
+
sqlOperator?: string;
|
|
7
|
+
/** GraphQL filter operator name (e.g. 'contains', 'bboxIntersects2D') */
|
|
8
|
+
operatorName: string;
|
|
9
|
+
/** Human-readable description of the operator */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Which base types this operator applies to: 'geometry', 'geography', or both */
|
|
12
|
+
baseTypes: ('geometry' | 'geography')[];
|
|
13
|
+
}
|
|
14
|
+
export interface ResolvedFilterSpec {
|
|
15
|
+
/** GraphQL type names this operator applies to (interface + all concrete types) */
|
|
16
|
+
typeNames: string[];
|
|
17
|
+
/** GraphQL filter operator name */
|
|
18
|
+
operatorName: string;
|
|
19
|
+
/** Description */
|
|
20
|
+
description: string;
|
|
21
|
+
/** SQL resolve function: (identifier, value) => SQL expression */
|
|
22
|
+
resolve: (i: SQL, v: SQL) => SQL;
|
|
23
|
+
}
|
package/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* PostGIS Connection Filter Plugin for PostGraphile v5
|
|
3
|
+
*
|
|
4
|
+
* Adds PostGIS spatial filter operators (ST_Contains, ST_Intersects, etc.)
|
|
5
|
+
* to postgraphile-plugin-connection-filter.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { PostgisConnectionFilterPreset } from 'graphile-plugin-connection-filter-postgis';
|
|
10
|
+
*
|
|
11
|
+
* const preset = {
|
|
12
|
+
* extends: [PostgisConnectionFilterPreset]
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export { PostgisConnectionFilterPreset } from './preset';
|
|
17
|
+
export { PgConnectionArgFilterPostgisOperatorsPlugin } from './plugin';
|
|
18
|
+
export type { PostgisFilterOperatorSpec, ResolvedFilterSpec } from './types';
|