Skip to content

Commit d4e20c1

Browse files
committed
Refactor to remove all getTypeByName() calls
1 parent 51474bf commit d4e20c1

6 files changed

+139
-106
lines changed

src/PgConnectionArgFilterBackwardRelationsPlugin.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function PgConnectionArgFilterBackwardRelationsPlugin(
1717
connectionFilterResolve,
1818
connectionFilterFieldResolversByTypeNameAndFieldName,
1919
connectionFilterTypesByTypeName,
20-
newFilterType,
20+
connectionFilterType,
2121
} = build;
2222
const {
2323
fieldWithHooks,
@@ -153,9 +153,12 @@ module.exports = function PgConnectionArgFilterBackwardRelationsPlugin(
153153
const [fieldName, { table }] = curr;
154154
const tableTypeName = inflection.tableType(table);
155155
const tableFilterTypeName = inflection.filterType(tableTypeName);
156-
const FilterType =
157-
connectionFilterTypesByTypeName[tableFilterTypeName] ||
158-
newFilterType(newWithHooks, tableFilterTypeName, table, tableTypeName);
156+
const FilterType = connectionFilterType(
157+
newWithHooks,
158+
tableFilterTypeName,
159+
table,
160+
tableTypeName
161+
);
159162
if (FilterType != null) {
160163
memo[fieldName] = fieldWithHooks(
161164
fieldName,

src/PgConnectionArgFilterColumnsPlugin.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ module.exports = function PgConnectionArgFilterColumnsPlugin(builder) {
1010
pgColumnFilter,
1111
pgOmit: omit,
1212
inflection,
13-
connectionFilterField,
13+
connectionFilterOperatorsType,
1414
resolveWhereComparison,
15+
connectionFilterTypesByTypeName,
1516
connectionFilterFieldResolversByTypeNameAndFieldName,
1617
} = build;
1718
const {
@@ -22,6 +23,8 @@ module.exports = function PgConnectionArgFilterColumnsPlugin(builder) {
2223

2324
if (!isPgConnectionFilter) return fields;
2425

26+
connectionFilterTypesByTypeName[Self.name] = Self;
27+
2528
connectionFilterFieldResolversByTypeNameAndFieldName[Self.name] = {};
2629

2730
const attrByFieldName = introspectionResultsByKind.attribute
@@ -41,16 +44,25 @@ module.exports = function PgConnectionArgFilterColumnsPlugin(builder) {
4144
attr.typeId,
4245
attr.typeModifier
4346
) || GraphQLString; // TODO: Remove `|| GraphQLString` before v1.0.0
44-
const fieldSpec = connectionFilterField(
45-
fieldName,
47+
const OperatorsType = connectionFilterOperatorsType(
4648
fieldType,
47-
fieldWithHooks,
4849
newWithHooks
4950
);
50-
if (!fieldSpec) {
51+
if (!OperatorsType) {
5152
return memo;
5253
}
53-
return extend(memo, { [fieldName]: fieldSpec });
54+
return extend(memo, {
55+
[fieldName]: fieldWithHooks(
56+
fieldName,
57+
{
58+
description: `Filter by the object’s \`${fieldName}\` field.`,
59+
type: OperatorsType,
60+
},
61+
{
62+
isPgConnectionFilterField: true,
63+
}
64+
),
65+
});
5466
},
5567
{}
5668
);

src/PgConnectionArgFilterComputedColumnsPlugin.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = function PgConnectionArgFilterComputedColumnsPlugin(builder) {
99
pgSql: sql,
1010
resolveWhereComparison,
1111
inflection,
12-
connectionFilterField,
12+
connectionFilterTypesByTypeName,
13+
connectionFilterOperatorsType,
1314
connectionFilterFieldResolversByTypeNameAndFieldName,
1415
} = build;
1516
const {
@@ -20,6 +21,8 @@ module.exports = function PgConnectionArgFilterComputedColumnsPlugin(builder) {
2021

2122
if (!isPgConnectionFilter) return fields;
2223

24+
connectionFilterTypesByTypeName[Self.name] = Self;
25+
2326
const procByFieldName = introspectionResultsByKind.procedure
2427
.filter(proc => proc.isStable)
2528
.filter(proc => proc.namespaceId === table.namespaceId)
@@ -65,16 +68,25 @@ module.exports = function PgConnectionArgFilterComputedColumnsPlugin(builder) {
6568
proc.returnTypeId,
6669
null
6770
);
68-
const fieldSpec = connectionFilterField(
69-
fieldName,
71+
const OperatorsType = connectionFilterOperatorsType(
7072
fieldType,
71-
fieldWithHooks,
7273
newWithHooks
7374
);
74-
if (!fieldSpec) {
75+
if (!OperatorsType) {
7576
return memo;
7677
}
77-
return extend(memo, { [fieldName]: fieldSpec });
78+
return extend(memo, {
79+
[fieldName]: fieldWithHooks(
80+
fieldName,
81+
{
82+
description: `Filter by the object’s \`${fieldName}\` field.`,
83+
type: OperatorsType,
84+
},
85+
{
86+
isPgConnectionFilterField: true,
87+
}
88+
),
89+
});
7890
},
7991
{}
8092
);

src/PgConnectionArgFilterForwardRelationsPlugin.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function PgConnectionArgFilterForwardRelationsPlugin(builder) {
1010
connectionFilterResolve,
1111
connectionFilterFieldResolversByTypeNameAndFieldName,
1212
connectionFilterTypesByTypeName,
13-
newFilterType,
13+
connectionFilterType,
1414
} = build;
1515
const {
1616
fieldWithHooks,
@@ -92,14 +92,12 @@ module.exports = function PgConnectionArgFilterForwardRelationsPlugin(builder) {
9292
const foreignTableFilterTypeName = inflection.filterType(
9393
foreignTableTypeName
9494
);
95-
const FilterType =
96-
connectionFilterTypesByTypeName[foreignTableFilterTypeName] ||
97-
newFilterType(
98-
newWithHooks,
99-
foreignTableFilterTypeName,
100-
foreignTable,
101-
foreignTableTypeName
102-
);
95+
const FilterType = connectionFilterType(
96+
newWithHooks,
97+
foreignTableFilterTypeName,
98+
foreignTable,
99+
foreignTableTypeName
100+
);
103101
if (FilterType != null) {
104102
memo[fieldName] = fieldWithHooks(
105103
fieldName,

src/PgConnectionArgFilterLogicalOperatorsPlugin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = function PgConnectionArgFilterLogicalOperatorsPlugin(builder) {
44
extend,
55
graphql: { GraphQLList, GraphQLNonNull },
66
pgSql: sql,
7+
connectionFilterTypesByTypeName,
78
connectionFilterResolve,
89
connectionFilterFieldResolversByTypeNameAndFieldName,
910
} = build;
@@ -15,6 +16,8 @@ module.exports = function PgConnectionArgFilterLogicalOperatorsPlugin(builder) {
1516

1617
if (!isPgConnectionFilter) return fields;
1718

19+
connectionFilterTypesByTypeName[Self.name] = Self;
20+
1821
if (Object.keys(fields).length === 0) {
1922
// Skip adding these operators if they would be the only fields
2023
return fields;

0 commit comments

Comments
 (0)