Skip to content

Commit 479447a

Browse files
authored
Merge pull request #1 from graphile-contrib/mattiarossi/v5
integrate changes from upstream
2 parents 6189b44 + cf662fa commit 479447a

8 files changed

Lines changed: 2054 additions & 485 deletions

.eslintrc.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
11
module.exports = {
22
root: true,
3-
parser: "@typescript-eslint/parser",
3+
parser: "@babel/eslint-parser",
4+
parserOptions: {
5+
sourceType: "module",
6+
},
47
env: {
8+
jest: true,
59
node: true,
610
es6: true,
711
"jest/globals": true,
812
},
9-
plugins: ["@typescript-eslint", "jest", "graphile-export"],
13+
plugins: [
14+
"@typescript-eslint",
15+
"jest",
16+
//"tsdoc",
17+
//"simple-import-sort",
18+
//"import",
19+
"graphile-export",
20+
],
1021
extends: [
1122
"eslint:recommended",
23+
"plugin:@typescript-eslint/eslint-recommended",
1224
"plugin:@typescript-eslint/recommended",
25+
// "plugin:import/errors",
26+
// "plugin:import/typescript",
1327
"plugin:graphile-export/recommended",
1428
"plugin:jest/recommended",
1529
"prettier",
1630
],
1731
rules: {
1832
"jest/expect-expect": ["off"],
33+
"no-fallthrough": ["error", { allowEmptyCase: true }],
34+
"@typescript-eslint/no-var-requires": ["off"],
35+
"@typescript-eslint/no-explicit-any": ["off"],
36+
// We need this for our `GraphileBuild`/`GraphileConfig`/etc namespaces
37+
"@typescript-eslint/no-namespace": "off",
38+
"@typescript-eslint/no-unused-vars": [
39+
"warn",
40+
{
41+
argsIgnorePattern: "^_",
42+
varsIgnorePattern: "^_",
43+
args: "after-used",
44+
ignoreRestSiblings: true,
45+
},
46+
],
1947
},
48+
overrides: [
49+
// Rules for TypeScript only
50+
{
51+
files: ["*.ts", "*.tsx"],
52+
parser: "@typescript-eslint/parser",
53+
},
54+
],
2055
};

babel.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Babel config, used by Jest
2+
module.exports = {
3+
plugins: ["@babel/plugin-transform-modules-commonjs"],
4+
presets: [
5+
[
6+
"@babel/env",
7+
{
8+
targets: {
9+
node: "16.12",
10+
},
11+
},
12+
],
13+
"@babel/preset-typescript",
14+
],
15+
env: {
16+
test: {
17+
plugins: ["babel-plugin-transform-import-meta"],
18+
presets: [
19+
[
20+
"@babel/env",
21+
{
22+
targets: {
23+
node: "current",
24+
},
25+
},
26+
],
27+
"@babel/preset-typescript",
28+
],
29+
},
30+
},
31+
};

package.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,26 @@
3030
"tslib": "^2.5.0"
3131
},
3232
"devDependencies": {
33+
"@babel/eslint-parser": "^7.22.11",
34+
"@babel/plugin-transform-modules-commonjs": "^7.22.11",
35+
"@babel/plugin-transform-runtime": "^7.22.10",
36+
"@babel/preset-env": "^7.22.14",
37+
"@babel/preset-typescript": "^7.22.11",
3338
"@dataplan/pg": "^0.0.1-beta.1",
3439
"@tsconfig/node16": "^1.0.3",
3540
"@types/jest": "29.5.0",
36-
"@typescript-eslint/eslint-plugin": "5.59.0",
37-
"@typescript-eslint/parser": "5.59.0",
38-
"eslint": "8.38.0",
39-
"eslint-config-prettier": "8.8.0",
40-
"eslint-plugin-jest": "27.2.1",
41+
"@typescript-eslint/eslint-plugin": "^6.5.0",
42+
"@typescript-eslint/parser": "^6.5.0",
43+
"@typescript-eslint/typescript-estree": "^6.5.0",
44+
"babel-jest": "^29.6.4",
45+
"babel-plugin-transform-import-meta": "^2.2.1",
46+
"eslint": "^8.48.0",
47+
"eslint-config-prettier": "^9.0.0",
48+
"eslint-plugin-import": "^2.28.1",
49+
"eslint-plugin-jest": "^27.2.3",
50+
"eslint-plugin-simple-import-sort": "^10.0.0",
51+
"eslint-plugin-tsdoc": "^0.2.17",
52+
"eslint_d": "^12.2.1",
4153
"grafast": "^0.0.1-beta.1",
4254
"grafserv": "^0.0.1-beta.1",
4355
"graphile-build": "^5.0.0-beta.1",

src/PgConnectionArgFilterForwardRelationsPlugin.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const PgConnectionArgFilterForwardRelationsPlugin: GraphileConfig.Plugin
3838
graphql: { GraphQLBoolean },
3939
sql,
4040
options: { pgIgnoreReferentialIntegrity },
41+
EXPORTABLE,
4142
} = build;
4243
const {
4344
fieldWithHooks,
@@ -112,10 +113,9 @@ export const PgConnectionArgFilterForwardRelationsPlugin: GraphileConfig.Plugin
112113
() => ({
113114
description: `Filter by the object’s \`${fieldName}\` relation.`,
114115
type: ForeignTableFilterType,
115-
applyPlan: build.EXPORTABLE(
116-
() =>
117-
function ($where: PgConditionStep<any>, fieldArgs) {
118-
//assertAllowed(fieldArgs, "object");
116+
applyPlan: EXPORTABLE(
117+
(assertAllowed, foreignTable, foreignTableExpression, localAttributes, remoteAttributes, sql) => function ($where: PgConditionStep<any>, fieldArgs) {
118+
assertAllowed(fieldArgs, "object");
119119
const $subQuery = $where.existsPlan({
120120
tableExpression: foreignTableExpression,
121121
alias: foreignTable.name,
@@ -132,7 +132,7 @@ export const PgConnectionArgFilterForwardRelationsPlugin: GraphileConfig.Plugin
132132
});
133133
fieldArgs.apply($subQuery);
134134
},
135-
[]
135+
[assertAllowed, foreignTable, foreignTableExpression, localAttributes, remoteAttributes, sql]
136136
),
137137
})
138138
),
@@ -158,10 +158,9 @@ export const PgConnectionArgFilterForwardRelationsPlugin: GraphileConfig.Plugin
158158
() => ({
159159
description: `A related \`${fieldName}\` exists.`,
160160
type: GraphQLBoolean,
161-
applyPlan: build.EXPORTABLE(
162-
() =>
163-
function ($where: PgConditionStep<any>, fieldArgs) {
164-
//assertAllowed(fieldArgs, "scalar");
161+
applyPlan: EXPORTABLE(
162+
(assertAllowed, foreignTable, foreignTableExpression, localAttributes, remoteAttributes, sql) => function ($where: PgConditionStep<any>, fieldArgs) {
163+
assertAllowed(fieldArgs, "scalar");
165164
const $subQuery = $where.existsPlan({
166165
tableExpression: foreignTableExpression,
167166
alias: foreignTable.name,
@@ -178,7 +177,7 @@ export const PgConnectionArgFilterForwardRelationsPlugin: GraphileConfig.Plugin
178177
);
179178
});
180179
},
181-
[]
180+
[assertAllowed, foreignTable, foreignTableExpression, localAttributes, remoteAttributes, sql]
182181
),
183182
})
184183
),

src/PgConnectionArgFilterLogicalOperatorsPlugin.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
1414
const {
1515
extend,
1616
graphql: { GraphQLList, GraphQLNonNull },
17+
EXPORTABLE,
1718
} = build;
1819
const {
1920
fieldWithHooks,
@@ -39,16 +40,15 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
3940
{
4041
description: `Checks for all expressions in this list.`,
4142
type: new GraphQLList(new GraphQLNonNull(Self)),
42-
applyPlan: build.EXPORTABLE(
43-
() =>
44-
function ($where: PgConditionStep<any>, fieldArgs) {
43+
applyPlan: EXPORTABLE(
44+
(assertAllowed) => function ($where: PgConditionStep<any>, fieldArgs) {
4545
assertAllowed(fieldArgs, "list");
4646
const $and = $where.andPlan();
4747
// No need for this more correct form, easier to read if it's flatter.
4848
// fieldArgs.apply(() => $and.andPlan());
4949
fieldArgs.apply($and);
5050
},
51-
[]
51+
[assertAllowed]
5252
),
5353
}
5454
),
@@ -60,15 +60,14 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
6060
{
6161
description: `Checks for any expressions in this list.`,
6262
type: new GraphQLList(new GraphQLNonNull(Self)),
63-
applyPlan: build.EXPORTABLE(
64-
() =>
65-
function ($where: PgConditionStep<any>, fieldArgs) {
63+
applyPlan: EXPORTABLE(
64+
(assertAllowed) => function ($where: PgConditionStep<any>, fieldArgs) {
6665
assertAllowed(fieldArgs, "list");
6766
const $or = $where.orPlan();
6867
// Every entry is added to the `$or`, but the entries themselves should use an `and`.
6968
fieldArgs.apply(() => $or.andPlan());
7069
},
71-
[]
70+
[assertAllowed]
7271
),
7372
}
7473
),
@@ -80,15 +79,14 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
8079
{
8180
description: `Negates the expression.`,
8281
type: Self,
83-
applyPlan: build.EXPORTABLE(
84-
() =>
85-
function ($where: PgConditionStep<any>, fieldArgs) {
82+
applyPlan: EXPORTABLE(
83+
(assertAllowed) => function ($where: PgConditionStep<any>, fieldArgs) {
8684
assertAllowed(fieldArgs, "object");
8785
const $not = $where.notPlan();
8886
const $and = $not.andPlan();
8987
fieldArgs.apply($and);
9088
},
91-
[]
89+
[assertAllowed]
9290
),
9391
}
9492
),

src/PgConnectionArgFilterOperatorsPlugin.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
2929
connectionFilterAllowedOperators,
3030
connectionFilterOperatorNames,
3131
},
32+
EXPORTABLE,
3233
} = build;
3334

3435
const {
@@ -389,7 +390,7 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
389390
const hstoreOperators: { [fieldName: string]: OperatorSpec } = {
390391
contains: {
391392
description: "Contains the specified KeyValueHash.",
392-
resolve: (i, v) => sql`${i} @> ${v}`,
393+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} @> ${v}`, [sql]),
393394
},
394395
containsKey: {
395396
description: "Contains the specified key.",
@@ -412,13 +413,13 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
412413
},
413414
containedBy: {
414415
description: "Contained by the specified KeyValueHash.",
415-
resolve: (i, v) => sql`${i} <@ ${v}`,
416+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} <@ ${v}`, [sql]),
416417
},
417418
};
418419
const jsonbOperators: { [fieldName: string]: OperatorSpec } = {
419420
contains: {
420421
description: "Contains the specified JSON.",
421-
resolve: (i, v) => sql`${i} @> ${v}`,
422+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} @> ${v}`, [sql]),
422423
},
423424
containsKey: {
424425
description: "Contains the specified key.",
@@ -439,31 +440,31 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
439440
},
440441
containedBy: {
441442
description: "Contained by the specified JSON.",
442-
resolve: (i, v) => sql`${i} <@ ${v}`,
443+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} <@ ${v}`, [sql]),
443444
},
444445
};
445446
const inetOperators: { [fieldName: string]: OperatorSpec } = {
446447
contains: {
447448
description: "Contains the specified internet address.",
448-
resolve: (i, v) => sql`${i} >> ${v}`,
449+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} >> ${v}`, [sql]),
449450
},
450451
containsOrEqualTo: {
451452
description: "Contains or equal to the specified internet address.",
452-
resolve: (i, v) => sql`${i} >>= ${v}`,
453+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} >>= ${v}`, [sql]),
453454
},
454455
containedBy: {
455456
description: "Contained by the specified internet address.",
456-
resolve: (i, v) => sql`${i} << ${v}`,
457+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} << ${v}`, [sql]),
457458
},
458459
containedByOrEqualTo: {
459460
description:
460461
"Contained by or equal to the specified internet address.",
461-
resolve: (i, v) => sql`${i} <<= ${v}`,
462+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} <<= ${v}`, [sql]),
462463
},
463464
containsOrContainedBy: {
464465
description:
465466
"Contains or contained by the specified internet address.",
466-
resolve: (i, v) => sql`${i} && ${v}`,
467+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} && ${v}`, [sql]),
467468
},
468469
};
469470

@@ -579,7 +580,7 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
579580
...sortOperators,
580581
contains: {
581582
description: "Contains the specified range.",
582-
resolve: (i, v) => sql`${i} @> ${v}`,
583+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} @> ${v}`, [sql]),
583584
},
584585
containsElement: {
585586
description: "Contains the specified value.",
@@ -596,31 +597,31 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
596597
},
597598
containedBy: {
598599
description: "Contained by the specified range.",
599-
resolve: (i, v) => sql`${i} <@ ${v}`,
600+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} <@ ${v}`, [sql]),
600601
},
601602
overlaps: {
602603
description: "Overlaps the specified range.",
603-
resolve: (i, v) => sql`${i} && ${v}`,
604+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} && ${v}`, [sql]),
604605
},
605606
strictlyLeftOf: {
606607
description: "Strictly left of the specified range.",
607-
resolve: (i, v) => sql`${i} << ${v}`,
608+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} << ${v}`, [sql]),
608609
},
609610
strictlyRightOf: {
610611
description: "Strictly right of the specified range.",
611-
resolve: (i, v) => sql`${i} >> ${v}`,
612+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} >> ${v}`, [sql]),
612613
},
613614
notExtendsRightOf: {
614615
description: "Does not extend right of the specified range.",
615-
resolve: (i, v) => sql`${i} &< ${v}`,
616+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} &< ${v}`, [sql]),
616617
},
617618
notExtendsLeftOf: {
618619
description: "Does not extend left of the specified range.",
619-
resolve: (i, v) => sql`${i} &> ${v}`,
620+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} &> ${v}`, [sql]),
620621
},
621622
adjacentTo: {
622623
description: "Adjacent to the specified range.",
623-
resolve: (i, v) => sql`${i} -|- ${v}`,
624+
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} -|- ${v}`, [sql]),
624625
},
625626
};
626627

@@ -716,7 +717,7 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
716717
let rangeLike = true;
717718
let enumLike = true;
718719
for (const codec of pgCodecs) {
719-
let underlyingType = codec.domainOfCodec ?? codec;
720+
const underlyingType = codec.domainOfCodec ?? codec;
720721
if (!underlyingType.arrayOfCodec) {
721722
arrayLike = false;
722723
}
@@ -928,7 +929,7 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
928929
if (!codecGraphQLType) {
929930
return memo;
930931
}
931-
let type = resolveType
932+
const type = resolveType
932933
? resolveType(codecGraphQLType)
933934
: codecGraphQLType;
934935

@@ -1046,7 +1047,7 @@ export function makeApplyPlanFromOperatorSpec(
10461047
return ($where, fieldArgs) => {
10471048
if (!$where.extensions?.pgFilterAttribute) {
10481049
throw new Error(
1049-
`Planning error: expected 'pgFilterAttribute' to be present on the \$where plan's extensions; your extensions to \`postgraphile-plugin-connection-filter\` does not implement the required interfaces.`
1050+
`Planning error: expected 'pgFilterAttribute' to be present on the $where plan's extensions; your extensions to \`postgraphile-plugin-connection-filter\` does not implement the required interfaces.`
10501051
);
10511052
}
10521053
const $input = fieldArgs.getRaw();

0 commit comments

Comments
 (0)