Skip to content

Commit 59a07a2

Browse files
authored
feat(pg): procFieldDetails helper (#717)
1 parent 352dab3 commit 59a07a2

13 files changed

Lines changed: 234 additions & 159 deletions

File tree

packages/graphile-build-pg/src/QueryBuilder.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type CursorValue = Array<any>;
1919
export type CursorComparator = (val: CursorValue, isAfter: boolean) => void;
2020

2121
export default class QueryBuilder {
22-
public parentQueryBuilder: QueryBuilder | void;
22+
public parentQueryBuilder: QueryBuilder | undefined;
2323
public context: GraphQLContext;
2424
public rootValue: any;
2525
public beforeLock(field: string, fn: () => void): void;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import PgColumnDeprecationPlugin from "./plugins/PgColumnDeprecationPlugin";
1717
import PgForwardRelationPlugin from "./plugins/PgForwardRelationPlugin";
1818
import PgBackwardRelationPlugin from "./plugins/PgBackwardRelationPlugin";
1919
import PgRowByUniqueConstraint from "./plugins/PgRowByUniqueConstraint";
20-
import PgComputedColumnsPlugin, {
21-
getComputedColumnDetails,
22-
} from "./plugins/PgComputedColumnsPlugin";
20+
import PgComputedColumnsPlugin from "./plugins/PgComputedColumnsPlugin";
2321
import PgQueryProceduresPlugin from "./plugins/PgQueryProceduresPlugin";
2422
import PgOrderAllColumnsPlugin from "./plugins/PgOrderAllColumnsPlugin";
2523
import PgOrderComputedColumnsPlugin from "./plugins/PgOrderComputedColumnsPlugin";
@@ -83,7 +81,7 @@ export const defaultPlugins = [
8381
PgMutationPayloadEdgePlugin,
8482
];
8583

86-
export { inflections, getComputedColumnDetails };
84+
export { inflections };
8785

8886
// TypeScript compatibility
8987
export { PgEntityKind };

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import baseOmit, {
2525
FILTER,
2626
EXECUTE,
2727
} from "../omit";
28-
import makeProcField from "./makeProcField";
28+
import makeProcField, { procFieldDetails } from "./makeProcField";
29+
import { getComputedColumnDetails } from "./PgComputedColumnsPlugin";
2930
import parseIdentifier from "../parseIdentifier";
3031
import viaTemporaryTable from "./viaTemporaryTable";
3132
import chalk from "chalk";
@@ -349,6 +350,8 @@ export default (function PgBasicsPlugin(
349350
pgAddStartEndCursor: addStartEndCursor,
350351
pgOmit,
351352
pgMakeProcField: makeProcField,
353+
pgProcFieldDetails: procFieldDetails,
354+
pgGetComputedColumnDetails: getComputedColumnDetails,
352355
pgParseIdentifier: parseIdentifier,
353356
pgViaTemporaryTable: viaTemporaryTable,
354357
describePgEntity,

packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.d.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export interface PgNamespace {
1414
kind: PgEntityKind.NAMESPACE;
1515
id: string;
1616
name: string;
17-
comment: string | void;
18-
description: string | void;
17+
comment: string | undefined;
18+
description: string | undefined;
1919
tags: { [tag: string]: true | string | Array<string> };
2020
}
2121

2222
export interface PgProc {
2323
kind: PgEntityKind.PROCEDURE;
2424
id: string;
2525
name: string;
26-
comment: string | void;
27-
description: string | void;
26+
comment: string | undefined;
27+
description: string | undefined;
2828
namespaceId: string;
2929
namespaceName: string;
3030
isStrict: boolean;
@@ -47,8 +47,8 @@ export interface PgClass {
4747
kind: PgEntityKind.CLASS;
4848
id: string;
4949
name: string;
50-
comment: string | void;
51-
description: string | void;
50+
comment: string | undefined;
51+
description: string | undefined;
5252
classKind: string;
5353
namespaceId: string;
5454
namespaceName: string;
@@ -64,7 +64,7 @@ export interface PgClass {
6464
attributes: Array<PgAttribute>;
6565
constraints: Array<PgConstraint>;
6666
foreignConstraints: Array<PgConstraint>;
67-
primaryKeyConstraint: PgConstraint | void;
67+
primaryKeyConstraint: PgConstraint | undefined;
6868
aclSelectable: boolean;
6969
aclInsertable: boolean;
7070
aclUpdatable: boolean;
@@ -76,27 +76,27 @@ export interface PgType {
7676
kind: PgEntityKind.TYPE;
7777
id: string;
7878
name: string;
79-
comment: string | void;
80-
description: string | void;
79+
comment: string | undefined;
80+
description: string | undefined;
8181
namespaceId: string;
8282
namespaceName: string;
8383
type: string;
8484
category: string;
8585
domainIsNotNull: boolean;
86-
arrayItemTypeId: string | void;
87-
arrayItemType: PgType | void;
88-
arrayType: PgType | void;
89-
typeLength: number | void;
86+
arrayItemTypeId: string | undefined;
87+
arrayItemType: PgType | undefined;
88+
arrayType: PgType | undefined;
89+
typeLength: number | undefined;
9090
isPgArray: boolean;
91-
classId: string | void;
92-
class: PgClass | void;
93-
domainBaseTypeId: string | void;
94-
domainBaseType: PgType | void;
95-
domainTypeModifier: number | void;
91+
classId: string | undefined;
92+
class: PgClass | undefined;
93+
domainBaseTypeId: string | undefined;
94+
domainBaseType: PgType | undefined;
95+
domainTypeModifier: number | undefined;
9696
domainHasDefault: boolean;
97-
enumVariants: string[] | void;
98-
enumDescriptions: string[] | void;
99-
rangeSubTypeId: string | void;
97+
enumVariants: string[] | undefined;
98+
enumDescriptions: string[] | undefined;
99+
rangeSubTypeId: string | undefined;
100100
tags: { [tag: string]: true | string | Array<string> };
101101
isFake?: boolean;
102102
}
@@ -106,8 +106,8 @@ export interface PgAttribute {
106106
classId: string;
107107
num: number;
108108
name: string;
109-
comment: string | void;
110-
description: string | void;
109+
comment: string | undefined;
110+
description: string | undefined;
111111
typeId: string;
112112
typeModifier: number;
113113
isNotNull: boolean;
@@ -120,8 +120,8 @@ export interface PgAttribute {
120120
aclSelectable: boolean;
121121
aclInsertable: boolean;
122122
aclUpdatable: boolean;
123-
isIndexed: boolean | void;
124-
isUnique: boolean | void;
123+
isIndexed: boolean | undefined;
124+
isUnique: boolean | undefined;
125125
columnLevelSelectGrant: boolean;
126126
}
127127

@@ -132,16 +132,16 @@ export interface PgConstraint {
132132
type: string;
133133
classId: string;
134134
class: PgClass;
135-
foreignClassId: string | void;
136-
foreignClass: PgClass | void;
137-
comment: string | void;
138-
description: string | void;
135+
foreignClassId: string | undefined;
136+
foreignClass: PgClass | undefined;
137+
comment: string | undefined;
138+
description: string | undefined;
139139
keyAttributeNums: Array<number>;
140140
keyAttributes: Array<PgAttribute>;
141141
foreignKeyAttributeNums: Array<number>;
142142
foreignKeyAttributes: Array<PgAttribute>;
143143
namespace: PgNamespace;
144-
isIndexed: boolean | void;
144+
isIndexed: boolean | undefined;
145145
tags: { [tag: string]: true | string | Array<string> };
146146
}
147147

@@ -154,8 +154,8 @@ export interface PgExtension {
154154
relocatable: boolean;
155155
version: string;
156156
configurationClassIds?: Array<string>;
157-
comment: string | void;
158-
description: string | void;
157+
comment: string | undefined;
158+
description: string | undefined;
159159
tags: { [tag: string]: true | string | Array<string> };
160160
}
161161

@@ -171,9 +171,9 @@ export interface PgIndex {
171171
isPrimary: boolean;
172172
isPartial: boolean;
173173
attributeNums: Array<number>;
174-
attributePropertiesAsc: Array<boolean> | void;
175-
attributePropertiesNullsFirst: Array<boolean> | void;
176-
description: string | void;
174+
attributePropertiesAsc: Array<boolean> | undefined;
175+
attributePropertiesNullsFirst: Array<boolean> | undefined;
176+
description: string | undefined;
177177
tags: { [tag: string]: true | string | Array<string> };
178178
}
179179

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function makeIntrospectionQuery(
3030
-- - \`$1\`: An array of strings that represent the namespaces we are introspecting.
3131
-- - \`$2\`: set true to include functions/tables/etc that come from extensions
3232
with
33-
${!pgIgnoreRBAC ? "recursive" : ""} accessible_roles(_oid) as (
33+
${!pgIgnoreRBAC ? "recursive" : ""} accessible_roles as (
3434
select oid _oid, pg_roles.*
3535
from pg_roles
3636
where rolname = current_user
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { PgType, PgProc } from "./PgIntrospectionPlugin";
2+
import { GraphQLInputType } from "graphql";
3+
import { Build } from "graphile-build";
4+
import { SQL } from "../QueryBuilder";
5+
6+
export function procFieldDetails(
7+
proc: PgProc,
8+
build: Build,
9+
options: {
10+
computed?: boolean;
11+
isMutation?: boolean;
12+
}
13+
): {
14+
inputs: {
15+
[name: string]: {
16+
type: GraphQLInputType;
17+
description?: string;
18+
};
19+
};
20+
makeSqlFunctionCall: (
21+
args: any,
22+
options: { implicitArgs?: any[]; unnest?: boolean }
23+
) => SQL;
24+
outputArgNames: string[];
25+
outputArgTypes: PgType[];
26+
};

0 commit comments

Comments
 (0)