Skip to content

Commit

Permalink
chore(deps): upgrade dev deps, apply prettier formatting changes (#180
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mattbretl authored Apr 3, 2022
1 parent 3a5d8d9 commit 8763d6c
Show file tree
Hide file tree
Showing 11 changed files with 1,477 additions and 2,686 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
"tslib": "^2.3.0"
},
"devDependencies": {
"@graphile-contrib/pg-simplify-inflector": "^6.1.0",
"@types/jest": "26.0.22",
"@typescript-eslint/eslint-plugin": "4.20.0",
"@typescript-eslint/parser": "4.20.0",
"eslint": "7.22.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-jest": "24.3.3",
"@graphile-contrib/pg-simplify-inflector": "6.1.0",
"@types/jest": "27.4.1",
"@typescript-eslint/eslint-plugin": "5.17.0",
"@typescript-eslint/parser": "5.17.0",
"eslint": "8.12.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "26.1.3",
"graphql": "14.7.0",
"jest": "26.6.3",
"pg": "8.5.1",
"jest": "27.5.1",
"pg": "8.7.3",
"postgraphile-core": "4.5.0",
"prettier": "2.2.1",
"ts-jest": "26.5.4",
"typescript": "4.2.3"
"prettier": "2.6.2",
"ts-jest": "27.1.4",
"typescript": "4.6.3"
},
"files": [
"dist"
Expand Down
71 changes: 32 additions & 39 deletions src/PgConnectionArgFilterBackwardRelationsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (

connectionFilterTypesByTypeName[Self.name] = Self;

const backwardRelationSpecs = (introspectionResultsByKind.constraint as PgConstraint[])
const backwardRelationSpecs = (
introspectionResultsByKind.constraint as PgConstraint[]
)
.filter((con) => con.type === "f")
.filter((con) => con.foreignClassId === table.id)
.reduce((memo: BackwardRelationSpec[], foreignConstraint) => {
Expand All @@ -91,10 +93,14 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
if (omit(foreignTable, "read") || omit(foreignTable, "filter")) {
return memo;
}
const attributes = (introspectionResultsByKind.attribute as PgAttribute[])
const attributes = (
introspectionResultsByKind.attribute as PgAttribute[]
)
.filter((attr) => attr.classId === table.id)
.sort((a, b) => a.num - b.num);
const foreignAttributes = (introspectionResultsByKind.attribute as PgAttribute[])
const foreignAttributes = (
introspectionResultsByKind.attribute as PgAttribute[]
)
.filter((attr) => attr.classId === foreignTable.id)
.sort((a, b) => a.num - b.num);
const keyAttributes = foreignConstraint.foreignKeyAttributeNums.map(
Expand All @@ -109,7 +115,9 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
if (foreignKeyAttributes.some((attr) => omit(attr, "read"))) {
return memo;
}
const isForeignKeyUnique = !!(introspectionResultsByKind.constraint as PgConstraint[]).find(
const isForeignKeyUnique = !!(
introspectionResultsByKind.constraint as PgConstraint[]
).find(
(c) =>
c.classId === foreignTable.id &&
(c.type === "p" || c.type === "u") &&
Expand Down Expand Up @@ -177,18 +185,14 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
}) => {
if (fieldValue == null) return null;

const {
foreignTable,
foreignKeyAttributes,
keyAttributes,
} = backwardRelationSpecByFieldName[fieldName];
const { foreignTable, foreignKeyAttributes, keyAttributes } =
backwardRelationSpecByFieldName[fieldName];

const foreignTableTypeName = inflection.tableType(foreignTable);

const foreignTableAlias = sql.identifier(Symbol());
const foreignTableFilterTypeName = inflection.filterType(
foreignTableTypeName
);
const foreignTableFilterTypeName =
inflection.filterType(foreignTableTypeName);
const sqlIdentifier = sql.identifier(
foreignTable.namespace.name,
foreignTable.name
Expand Down Expand Up @@ -220,11 +224,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
}) => {
if (fieldValue == null) return null;

const {
foreignTable,
foreignKeyAttributes,
keyAttributes,
} = backwardRelationSpecByFieldName[fieldName];
const { foreignTable, foreignKeyAttributes, keyAttributes } =
backwardRelationSpecByFieldName[fieldName];

const foreignTableAlias = sql.identifier(Symbol());

Expand Down Expand Up @@ -287,9 +288,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
isOneToMany,
} = spec;
const foreignTableTypeName = inflection.tableType(foreignTable);
const foreignTableFilterTypeName = inflection.filterType(
foreignTableTypeName
);
const foreignTableFilterTypeName =
inflection.filterType(foreignTableTypeName);
const ForeignTableFilterType = connectionFilterType(
newWithHooks,
foreignTableFilterTypeName,
Expand Down Expand Up @@ -332,9 +332,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
table,
foreignConstraint
);
const filterFieldName = inflection.filterManyRelationByKeysFieldName(
fieldName
);
const filterFieldName =
inflection.filterManyRelationByKeysFieldName(fieldName);
addField(
filterFieldName,
`Filter by the object’s \`${fieldName}\` relation.`,
Expand All @@ -346,9 +345,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
)} to ${describePgEntity(foreignTable)}`
);

const existsFieldName = inflection.filterBackwardManyRelationExistsFieldName(
fieldName
);
const existsFieldName =
inflection.filterBackwardManyRelationExistsFieldName(fieldName);
addField(
existsFieldName,
`Some related \`${fieldName}\` exist.`,
Expand All @@ -367,9 +365,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
table,
foreignConstraint
);
const filterFieldName = inflection.filterSingleRelationByKeysBackwardsFieldName(
fieldName
);
const filterFieldName =
inflection.filterSingleRelationByKeysBackwardsFieldName(fieldName);
addField(
filterFieldName,
`Filter by the object’s \`${fieldName}\` relation.`,
Expand All @@ -381,9 +378,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
)} to ${describePgEntity(foreignTable)}`
);

const existsFieldName = inflection.filterBackwardSingleRelationExistsFieldName(
fieldName
);
const existsFieldName =
inflection.filterBackwardSingleRelationExistsFieldName(fieldName);
addField(
existsFieldName,
`A related \`${fieldName}\` exists.`,
Expand Down Expand Up @@ -422,9 +418,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (
connectionFilterTypesByTypeName[Self.name] = Self;

const foreignTableTypeName = inflection.tableType(foreignTable);
const foreignTableFilterTypeName = inflection.filterType(
foreignTableTypeName
);
const foreignTableFilterTypeName =
inflection.filterType(foreignTableTypeName);
const FilterType = connectionFilterType(
newWithHooks,
foreignTableFilterTypeName,
Expand Down Expand Up @@ -476,10 +471,8 @@ const PgConnectionArgFilterBackwardRelationsPlugin: Plugin = (

if (!parentFieldInfo || !parentFieldInfo.backwardRelationSpec)
throw new Error("Did not receive backward relation spec");
const {
keyAttributes,
foreignKeyAttributes,
}: BackwardRelationSpec = parentFieldInfo.backwardRelationSpec;
const { keyAttributes, foreignKeyAttributes }: BackwardRelationSpec =
parentFieldInfo.backwardRelationSpec;

const foreignTableAlias = sql.identifier(Symbol());
const sqlIdentifier = sql.identifier(
Expand Down
4 changes: 3 additions & 1 deletion src/PgConnectionArgFilterColumnsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const PgConnectionArgFilterColumnsPlugin: Plugin = (builder) => {

connectionFilterTypesByTypeName[Self.name] = Self;

const attrByFieldName = (introspectionResultsByKind.attribute as PgAttribute[])
const attrByFieldName = (
introspectionResultsByKind.attribute as PgAttribute[]
)
.filter((attr) => attr.classId === table.id)
.filter((attr) => pgColumnFilter(attr, build, context))
.filter((attr) => !omit(attr, "filter"))
Expand Down
4 changes: 3 additions & 1 deletion src/PgConnectionArgFilterCompositeTypeColumnsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const PgConnectionArgFilterCompositeTypeColumnsPlugin: Plugin = (

connectionFilterTypesByTypeName[Self.name] = Self;

const attrByFieldName = (introspectionResultsByKind.attribute as PgAttribute[])
const attrByFieldName = (
introspectionResultsByKind.attribute as PgAttribute[]
)
.filter((attr) => attr.classId === table.id)
.filter((attr) => pgColumnFilter(attr, build, context))
.filter((attr) => !omit(attr, "filter"))
Expand Down
100 changes: 49 additions & 51 deletions src/PgConnectionArgFilterComputedColumnsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,58 @@ const PgConnectionArgFilterComputedColumnsPlugin: Plugin = (

connectionFilterTypesByTypeName[Self.name] = Self;

const procByFieldName = (introspectionResultsByKind.procedure as PgProc[]).reduce(
(memo: { [fieldName: string]: PgProc }, proc) => {
// Must be marked @filterable OR enabled via plugin option
if (!(proc.tags.filterable || connectionFilterComputedColumns))
return memo;
const procByFieldName = (
introspectionResultsByKind.procedure as PgProc[]
).reduce((memo: { [fieldName: string]: PgProc }, proc) => {
// Must be marked @filterable OR enabled via plugin option
if (!(proc.tags.filterable || connectionFilterComputedColumns))
return memo;

// Must not be omitted
if (omit(proc, "execute")) return memo;
if (omit(proc, "filter")) return memo;
// Must not be omitted
if (omit(proc, "execute")) return memo;
if (omit(proc, "filter")) return memo;

// Must be a computed column
const computedColumnDetails = getComputedColumnDetails(
build,
table,
proc
);
if (!computedColumnDetails) return memo;
const { pseudoColumnName } = computedColumnDetails;

// Must have only one required argument
const inputArgsCount = proc.argTypeIds.filter(
(_typeId, idx) =>
proc.argModes.length === 0 || // all args are `in`
proc.argModes[idx] === "i" || // this arg is `in`
proc.argModes[idx] === "b" // this arg is `inout`
).length;
const nonOptionalArgumentsCount = inputArgsCount - proc.argDefaultsNum;
if (nonOptionalArgumentsCount > 1) {
return memo;
}

// Must return a scalar or an array
if (proc.returnsSet) return memo;
const returnType =
introspectionResultsByKind.typeById[proc.returnTypeId];
const returnTypeTable =
introspectionResultsByKind.classById[returnType.classId];
if (returnTypeTable) return memo;
const isRecordLike = returnType.id === "2249";
if (isRecordLike) return memo;
const isVoid = String(returnType.id) === "2278";
if (isVoid) return memo;

// Looks good
const fieldName = inflection.computedColumn(
pseudoColumnName,
proc,
table
);
memo = build.extend(memo, { [fieldName]: proc });
// Must be a computed column
const computedColumnDetails = getComputedColumnDetails(
build,
table,
proc
);
if (!computedColumnDetails) return memo;
const { pseudoColumnName } = computedColumnDetails;

// Must have only one required argument
const inputArgsCount = proc.argTypeIds.filter(
(_typeId, idx) =>
proc.argModes.length === 0 || // all args are `in`
proc.argModes[idx] === "i" || // this arg is `in`
proc.argModes[idx] === "b" // this arg is `inout`
).length;
const nonOptionalArgumentsCount = inputArgsCount - proc.argDefaultsNum;
if (nonOptionalArgumentsCount > 1) {
return memo;
},
{}
);
}

// Must return a scalar or an array
if (proc.returnsSet) return memo;
const returnType = introspectionResultsByKind.typeById[proc.returnTypeId];
const returnTypeTable =
introspectionResultsByKind.classById[returnType.classId];
if (returnTypeTable) return memo;
const isRecordLike = returnType.id === "2249";
if (isRecordLike) return memo;
const isVoid = String(returnType.id) === "2278";
if (isVoid) return memo;

// Looks good
const fieldName = inflection.computedColumn(
pseudoColumnName,
proc,
table
);
memo = build.extend(memo, { [fieldName]: proc });
return memo;
}, {});

const operatorsTypeNameByFieldName: { [fieldName: string]: string } = {};

Expand Down
Loading

0 comments on commit 8763d6c

Please sign in to comment.