Skip to content

Commit ea8480e

Browse files
wesselvdvWessel van der Veenbenjie
authored
fix(graphile-build-pg): add more numeric casting exceptions (#661)
Co-authored-by: Wessel van der Veen <wvn@synadia.nl> Co-authored-by: Benjie Gillam <benjie@jemjie.com>
1 parent 7182d92 commit ea8480e

28 files changed

Lines changed: 2109 additions & 2 deletions

packages/graphile-build-pg/src/QueryBuilder.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ function escapeLarge(sqlFragment: SQL, type: PgType) {
5757
"23" /* int4 */,
5858
"700" /* float4 */,
5959
"701" /* float8 */,
60+
"24" /* regproc */,
61+
"2202" /* regprocedure */,
62+
"2203" /* regoper */,
63+
"2204" /* regoperator */,
64+
"2205" /* regclass */,
65+
"2206" /* regtype */,
66+
"4096" /* regrole */,
67+
"4089" /* regnamespace */,
68+
"3734" /* regconfig */,
69+
"3769" /* regdictionary */,
6070
].includes(actualType.id)
6171
) {
6272
// No need for special handling

packages/graphile-build-pg/src/plugins/PgTypesPlugin.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,46 @@ export default (function PgTypesPlugin(
357357
inflection.builtin("InternetAddress"),
358358
"An IPv4 or IPv6 host address, and optionally its subnet."
359359
);
360+
const RegProcType = stringType(
361+
inflection.builtin("RegProc"),
362+
"A builtin object identifier type for a function name"
363+
);
364+
const RegProcedureType = stringType(
365+
inflection.builtin("RegProcedure"),
366+
"A builtin object identifier type for a function with argument types"
367+
);
368+
const RegOperType = stringType(
369+
inflection.builtin("RegOper"),
370+
"A builtin object identifier type for an operator"
371+
);
372+
const RegOperatorType = stringType(
373+
inflection.builtin("RegOperator"),
374+
"A builtin object identifier type for an operator with argument types"
375+
);
376+
const RegClassType = stringType(
377+
inflection.builtin("RegClass"),
378+
"A builtin object identifier type for a relation name"
379+
);
380+
const RegTypeType = stringType(
381+
inflection.builtin("RegType"),
382+
"A builtin object identifier type for a data type name"
383+
);
384+
const RegRoleType = stringType(
385+
inflection.builtin("RegRole"),
386+
"A builtin object identifier type for a role name"
387+
);
388+
const RegNamespaceType = stringType(
389+
inflection.builtin("RegNamespace"),
390+
"A builtin object identifier type for a namespace name"
391+
);
392+
const RegConfigType = stringType(
393+
inflection.builtin("RegConfig"),
394+
"A builtin object identifier type for a text search configuration"
395+
);
396+
const RegDictionaryType = stringType(
397+
inflection.builtin("RegDictionary"),
398+
"A builtin object identifier type for a text search dictionary"
399+
);
360400
const CidrType = pgUseCustomNetworkScalars
361401
? stringType(
362402
inflection.builtin("CidrAddress"),
@@ -424,6 +464,16 @@ export default (function PgTypesPlugin(
424464
addType(DateType, "graphile-build-pg built-in");
425465
addType(DateTimeType, "graphile-build-pg built-in");
426466
addType(TimeType, "graphile-build-pg built-in");
467+
addType(RegProcType, "graphile-build-pg built-in");
468+
addType(RegProcedureType, "graphile-build-pg built-in");
469+
addType(RegOperType, "graphile-build-pg built-in");
470+
addType(RegOperatorType, "graphile-build-pg built-in");
471+
addType(RegClassType, "graphile-build-pg built-in");
472+
addType(RegTypeType, "graphile-build-pg built-in");
473+
addType(RegRoleType, "graphile-build-pg built-in");
474+
addType(RegNamespaceType, "graphile-build-pg built-in");
475+
addType(RegConfigType, "graphile-build-pg built-in");
476+
addType(RegDictionaryType, "graphile-build-pg built-in");
427477

428478
const oidLookup = {
429479
20: stringType(
@@ -461,6 +511,16 @@ export default (function PgTypesPlugin(
461511
650: CidrType,
462512
829: MacAddrType,
463513
774: MacAddr8Type,
514+
24: RegProcType,
515+
2202: RegProcedureType,
516+
2203: RegOperType,
517+
2204: RegOperatorType,
518+
2205: RegClassType,
519+
2206: RegTypeType,
520+
4096: RegRoleType,
521+
4089: RegNamespaceType,
522+
3734: RegConfigType,
523+
3769: RegDictionaryType,
464524
};
465525
const oidInputLookup = {
466526
1186: GQLIntervalInput, // interval
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
mutation {
2+
# Must come next to last
3+
updateTypeById(
4+
input: {
5+
id: 12
6+
typePatch: {
7+
regrole: "postgraphile_test_authenticator"
8+
regnamespace: "pg10"
9+
}
10+
}
11+
) {
12+
type {
13+
...type
14+
}
15+
}
16+
# Must come last
17+
createType(
18+
input: {
19+
type: {
20+
regrole: "postgraphile_test_visitor"
21+
regnamespace: "c"
22+
}
23+
}
24+
) {
25+
type {
26+
...type
27+
}
28+
}
29+
}
30+
31+
fragment type on Type {
32+
id
33+
regrole
34+
regnamespace
35+
}

packages/postgraphile-core/__tests__/fixtures/mutations/types.graphql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ mutation {
5555
money: 27
5656
compoundType: { a: 1 }
5757
nestedCompoundType: { a: { a: 1 } }
58+
regproc: "b.type_function"
59+
regprocedure: "b.type_function(int)"
60+
regoper: "*<>"
61+
regoperator: "+(integer, integer)"
62+
regclass: "c.person"
63+
regtype: "numeric"
64+
regconfig: "dutch"
65+
regdictionary: "dutch_stem"
5866
}
5967
}
6068
) {
@@ -102,6 +110,14 @@ mutation {
102110
money: 27
103111
compoundType: { a: 1 }
104112
nestedCompoundType: { a: { a: 1 } }
113+
regproc: "b.type_function"
114+
regprocedure: "b.type_function(int)"
115+
regoper: "*<>"
116+
regoperator: "+(integer, integer)"
117+
regclass: "c.person"
118+
regtype: "numeric"
119+
regconfig: "dutch"
120+
regdictionary: "dutch_stem"
105121
}
106122
}
107123
) {
@@ -122,6 +138,7 @@ fragment compoundType on CompoundType {
122138
}
123139

124140
fragment type on Type {
141+
id
125142
smallint
126143
bigint
127144
boolean
@@ -195,4 +212,12 @@ fragment type on Type {
195212
x
196213
y
197214
}
215+
regproc
216+
regprocedure
217+
regoper
218+
regoperator
219+
regclass
220+
regtype
221+
regconfig
222+
regdictionary
198223
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
query {
2+
allTypes {
3+
...typesConnection
4+
}
5+
}
6+
7+
fragment type on Type {
8+
id
9+
regrole
10+
regnamespace
11+
}
12+
13+
fragment typesConnection on TypesConnection {
14+
nodes {
15+
...type
16+
}
17+
edges {
18+
node {
19+
...type
20+
}
21+
}
22+
totalCount
23+
pageInfo {
24+
hasNextPage
25+
hasPreviousPage
26+
startCursor
27+
endCursor
28+
}
29+
}

packages/postgraphile-core/__tests__/fixtures/queries/types.graphql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fragment compoundType on CompoundType {
5757
}
5858

5959
fragment type on Type {
60+
id
6061
smallint
6162
bigint
6263
boolean
@@ -138,6 +139,14 @@ fragment type on Type {
138139
id
139140
headline
140141
}
142+
regproc
143+
regprocedure
144+
regoper
145+
regoperator
146+
regclass
147+
regtype
148+
regconfig
149+
regdictionary
141150
}
142151

143152
fragment typesConnection on TypesConnection {

0 commit comments

Comments
 (0)