Skip to content

Commit

Permalink
feat(pg): procFieldDetails helper (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Feb 12, 2021
1 parent 352dab3 commit 59a07a2
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 159 deletions.
2 changes: 1 addition & 1 deletion packages/graphile-build-pg/src/QueryBuilder.d.ts
Expand Up @@ -19,7 +19,7 @@ export type CursorValue = Array<any>;
export type CursorComparator = (val: CursorValue, isAfter: boolean) => void;

export default class QueryBuilder {
public parentQueryBuilder: QueryBuilder | void;
public parentQueryBuilder: QueryBuilder | undefined;
public context: GraphQLContext;
public rootValue: any;
public beforeLock(field: string, fn: () => void): void;
Expand Down
6 changes: 2 additions & 4 deletions packages/graphile-build-pg/src/index.js
Expand Up @@ -17,9 +17,7 @@ import PgColumnDeprecationPlugin from "./plugins/PgColumnDeprecationPlugin";
import PgForwardRelationPlugin from "./plugins/PgForwardRelationPlugin";
import PgBackwardRelationPlugin from "./plugins/PgBackwardRelationPlugin";
import PgRowByUniqueConstraint from "./plugins/PgRowByUniqueConstraint";
import PgComputedColumnsPlugin, {
getComputedColumnDetails,
} from "./plugins/PgComputedColumnsPlugin";
import PgComputedColumnsPlugin from "./plugins/PgComputedColumnsPlugin";
import PgQueryProceduresPlugin from "./plugins/PgQueryProceduresPlugin";
import PgOrderAllColumnsPlugin from "./plugins/PgOrderAllColumnsPlugin";
import PgOrderComputedColumnsPlugin from "./plugins/PgOrderComputedColumnsPlugin";
Expand Down Expand Up @@ -83,7 +81,7 @@ export const defaultPlugins = [
PgMutationPayloadEdgePlugin,
];

export { inflections, getComputedColumnDetails };
export { inflections };

// TypeScript compatibility
export { PgEntityKind };
Expand Down
5 changes: 4 additions & 1 deletion packages/graphile-build-pg/src/plugins/PgBasicsPlugin.js
Expand Up @@ -25,7 +25,8 @@ import baseOmit, {
FILTER,
EXECUTE,
} from "../omit";
import makeProcField from "./makeProcField";
import makeProcField, { procFieldDetails } from "./makeProcField";
import { getComputedColumnDetails } from "./PgComputedColumnsPlugin";
import parseIdentifier from "../parseIdentifier";
import viaTemporaryTable from "./viaTemporaryTable";
import chalk from "chalk";
Expand Down Expand Up @@ -349,6 +350,8 @@ export default (function PgBasicsPlugin(
pgAddStartEndCursor: addStartEndCursor,
pgOmit,
pgMakeProcField: makeProcField,
pgProcFieldDetails: procFieldDetails,
pgGetComputedColumnDetails: getComputedColumnDetails,
pgParseIdentifier: parseIdentifier,
pgViaTemporaryTable: viaTemporaryTable,
describePgEntity,
Expand Down
70 changes: 35 additions & 35 deletions packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.d.ts
Expand Up @@ -14,17 +14,17 @@ export interface PgNamespace {
kind: PgEntityKind.NAMESPACE;
id: string;
name: string;
comment: string | void;
description: string | void;
comment: string | undefined;
description: string | undefined;
tags: { [tag: string]: true | string | Array<string> };
}

export interface PgProc {
kind: PgEntityKind.PROCEDURE;
id: string;
name: string;
comment: string | void;
description: string | void;
comment: string | undefined;
description: string | undefined;
namespaceId: string;
namespaceName: string;
isStrict: boolean;
Expand All @@ -47,8 +47,8 @@ export interface PgClass {
kind: PgEntityKind.CLASS;
id: string;
name: string;
comment: string | void;
description: string | void;
comment: string | undefined;
description: string | undefined;
classKind: string;
namespaceId: string;
namespaceName: string;
Expand All @@ -64,7 +64,7 @@ export interface PgClass {
attributes: Array<PgAttribute>;
constraints: Array<PgConstraint>;
foreignConstraints: Array<PgConstraint>;
primaryKeyConstraint: PgConstraint | void;
primaryKeyConstraint: PgConstraint | undefined;
aclSelectable: boolean;
aclInsertable: boolean;
aclUpdatable: boolean;
Expand All @@ -76,27 +76,27 @@ export interface PgType {
kind: PgEntityKind.TYPE;
id: string;
name: string;
comment: string | void;
description: string | void;
comment: string | undefined;
description: string | undefined;
namespaceId: string;
namespaceName: string;
type: string;
category: string;
domainIsNotNull: boolean;
arrayItemTypeId: string | void;
arrayItemType: PgType | void;
arrayType: PgType | void;
typeLength: number | void;
arrayItemTypeId: string | undefined;
arrayItemType: PgType | undefined;
arrayType: PgType | undefined;
typeLength: number | undefined;
isPgArray: boolean;
classId: string | void;
class: PgClass | void;
domainBaseTypeId: string | void;
domainBaseType: PgType | void;
domainTypeModifier: number | void;
classId: string | undefined;
class: PgClass | undefined;
domainBaseTypeId: string | undefined;
domainBaseType: PgType | undefined;
domainTypeModifier: number | undefined;
domainHasDefault: boolean;
enumVariants: string[] | void;
enumDescriptions: string[] | void;
rangeSubTypeId: string | void;
enumVariants: string[] | undefined;
enumDescriptions: string[] | undefined;
rangeSubTypeId: string | undefined;
tags: { [tag: string]: true | string | Array<string> };
isFake?: boolean;
}
Expand All @@ -106,8 +106,8 @@ export interface PgAttribute {
classId: string;
num: number;
name: string;
comment: string | void;
description: string | void;
comment: string | undefined;
description: string | undefined;
typeId: string;
typeModifier: number;
isNotNull: boolean;
Expand All @@ -120,8 +120,8 @@ export interface PgAttribute {
aclSelectable: boolean;
aclInsertable: boolean;
aclUpdatable: boolean;
isIndexed: boolean | void;
isUnique: boolean | void;
isIndexed: boolean | undefined;
isUnique: boolean | undefined;
columnLevelSelectGrant: boolean;
}

Expand All @@ -132,16 +132,16 @@ export interface PgConstraint {
type: string;
classId: string;
class: PgClass;
foreignClassId: string | void;
foreignClass: PgClass | void;
comment: string | void;
description: string | void;
foreignClassId: string | undefined;
foreignClass: PgClass | undefined;
comment: string | undefined;
description: string | undefined;
keyAttributeNums: Array<number>;
keyAttributes: Array<PgAttribute>;
foreignKeyAttributeNums: Array<number>;
foreignKeyAttributes: Array<PgAttribute>;
namespace: PgNamespace;
isIndexed: boolean | void;
isIndexed: boolean | undefined;
tags: { [tag: string]: true | string | Array<string> };
}

Expand All @@ -154,8 +154,8 @@ export interface PgExtension {
relocatable: boolean;
version: string;
configurationClassIds?: Array<string>;
comment: string | void;
description: string | void;
comment: string | undefined;
description: string | undefined;
tags: { [tag: string]: true | string | Array<string> };
}

Expand All @@ -171,9 +171,9 @@ export interface PgIndex {
isPrimary: boolean;
isPartial: boolean;
attributeNums: Array<number>;
attributePropertiesAsc: Array<boolean> | void;
attributePropertiesNullsFirst: Array<boolean> | void;
description: string | void;
attributePropertiesAsc: Array<boolean> | undefined;
attributePropertiesNullsFirst: Array<boolean> | undefined;
description: string | undefined;
tags: { [tag: string]: true | string | Array<string> };
}

Expand Down
Expand Up @@ -30,7 +30,7 @@ function makeIntrospectionQuery(
-- - \`$1\`: An array of strings that represent the namespaces we are introspecting.
-- - \`$2\`: set true to include functions/tables/etc that come from extensions
with
${!pgIgnoreRBAC ? "recursive" : ""} accessible_roles(_oid) as (
${!pgIgnoreRBAC ? "recursive" : ""} accessible_roles as (
select oid _oid, pg_roles.*
from pg_roles
where rolname = current_user
Expand Down
26 changes: 26 additions & 0 deletions packages/graphile-build-pg/src/plugins/makeProcField.d.ts
@@ -0,0 +1,26 @@
import { PgType, PgProc } from "./PgIntrospectionPlugin";
import { GraphQLInputType } from "graphql";
import { Build } from "graphile-build";
import { SQL } from "../QueryBuilder";

export function procFieldDetails(
proc: PgProc,
build: Build,
options: {
computed?: boolean;
isMutation?: boolean;
}
): {
inputs: {
[name: string]: {
type: GraphQLInputType;
description?: string;
};
};
makeSqlFunctionCall: (
args: any,
options: { implicitArgs?: any[]; unnest?: boolean }
) => SQL;
outputArgNames: string[];
outputArgTypes: PgType[];
};

0 comments on commit 59a07a2

Please sign in to comment.