graphile-build-pg 4.13.0 → 4.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -13
- package/node8plus/GraphQLJSON.js +0 -11
- package/node8plus/GraphQLJSON.js.map +1 -1
- package/node8plus/PgLiveProvider.js +4 -11
- package/node8plus/PgLiveProvider.js.map +1 -1
- package/node8plus/QueryBuilder.js +42 -176
- package/node8plus/QueryBuilder.js.map +1 -1
- package/node8plus/index.js +8 -47
- package/node8plus/index.js.map +1 -1
- package/node8plus/inflections.js +9 -61
- package/node8plus/inflections.js.map +1 -1
- package/node8plus/omit.js +7 -22
- package/node8plus/omit.js.map +1 -1
- package/node8plus/parseIdentifier.js +0 -1
- package/node8plus/parseIdentifier.js.map +1 -1
- package/node8plus/pgPrepareAndRun.js +2 -14
- package/node8plus/pgPrepareAndRun.js.map +1 -1
- package/node8plus/plugins/PageInfoStartEndCursor.js +0 -4
- package/node8plus/plugins/PageInfoStartEndCursor.js.map +1 -1
- package/node8plus/plugins/PgAllRows.js +0 -29
- package/node8plus/plugins/PgAllRows.js.map +1 -1
- package/node8plus/plugins/PgBackwardRelationPlugin.js +2 -41
- package/node8plus/plugins/PgBackwardRelationPlugin.js.map +1 -1
- package/node8plus/plugins/PgBasicsPlugin.js +20 -147
- package/node8plus/plugins/PgBasicsPlugin.js.map +1 -1
- package/node8plus/plugins/PgColumnDeprecationPlugin.js +2 -5
- package/node8plus/plugins/PgColumnDeprecationPlugin.js.map +1 -1
- package/node8plus/plugins/PgColumnsPlugin.js +4 -17
- package/node8plus/plugins/PgColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgComputedColumnsPlugin.js +4 -19
- package/node8plus/plugins/PgComputedColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgConditionComputedColumnPlugin.js +12 -23
- package/node8plus/plugins/PgConditionComputedColumnPlugin.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgCondition.js +1 -9
- package/node8plus/plugins/PgConnectionArgCondition.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js +0 -12
- package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgOrderBy.js +2 -19
- package/node8plus/plugins/PgConnectionArgOrderBy.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgOrderByDefaultValue.js +0 -6
- package/node8plus/plugins/PgConnectionArgOrderByDefaultValue.js.map +1 -1
- package/node8plus/plugins/PgConnectionTotalCount.js +0 -8
- package/node8plus/plugins/PgConnectionTotalCount.js.map +1 -1
- package/node8plus/plugins/PgForwardRelationPlugin.js +2 -25
- package/node8plus/plugins/PgForwardRelationPlugin.js.map +1 -1
- package/node8plus/plugins/PgIntrospectionPlugin.js +91 -180
- package/node8plus/plugins/PgIntrospectionPlugin.js.flow +30 -2
- package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgJWTPlugin.js +2 -18
- package/node8plus/plugins/PgJWTPlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationCreatePlugin.js +0 -18
- package/node8plus/plugins/PgMutationCreatePlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationPayloadEdgePlugin.js +4 -25
- package/node8plus/plugins/PgMutationPayloadEdgePlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationProceduresPlugin.js +0 -6
- package/node8plus/plugins/PgMutationProceduresPlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js +14 -49
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.flow +5 -2
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
- package/node8plus/plugins/PgNodeAliasPostGraphile.js +0 -6
- package/node8plus/plugins/PgNodeAliasPostGraphile.js.map +1 -1
- package/node8plus/plugins/PgOrderAllColumnsPlugin.js +0 -4
- package/node8plus/plugins/PgOrderAllColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgOrderByPrimaryKeyPlugin.js +0 -6
- package/node8plus/plugins/PgOrderByPrimaryKeyPlugin.js.map +1 -1
- package/node8plus/plugins/PgOrderComputedColumnsPlugin.js +10 -14
- package/node8plus/plugins/PgOrderComputedColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgQueryProceduresPlugin.js +4 -16
- package/node8plus/plugins/PgQueryProceduresPlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js +3 -20
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js +11 -16
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js.map +1 -1
- package/node8plus/plugins/PgRowByUniqueConstraint.js +4 -25
- package/node8plus/plugins/PgRowByUniqueConstraint.js.map +1 -1
- package/node8plus/plugins/PgRowNode.js +0 -32
- package/node8plus/plugins/PgRowNode.js.map +1 -1
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js +3 -17
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgTablesPlugin.js +7 -59
- package/node8plus/plugins/PgTablesPlugin.js.map +1 -1
- package/node8plus/plugins/PgTypesPlugin.js +140 -240
- package/node8plus/plugins/PgTypesPlugin.js.flow +76 -23
- package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
- package/node8plus/plugins/addStartEndCursor.js +2 -5
- package/node8plus/plugins/addStartEndCursor.js.map +1 -1
- package/node8plus/plugins/debugSql.js +1 -16
- package/node8plus/plugins/debugSql.js.map +1 -1
- package/node8plus/plugins/introspectionQuery.js +3 -4
- package/node8plus/plugins/introspectionQuery.js.flow +11 -3
- package/node8plus/plugins/introspectionQuery.js.map +1 -1
- package/node8plus/plugins/makeProcField.js +40 -90
- package/node8plus/plugins/makeProcField.js.map +1 -1
- package/node8plus/plugins/pgField.js +2 -7
- package/node8plus/plugins/pgField.js.map +1 -1
- package/node8plus/plugins/viaTemporaryTable.js +6 -12
- package/node8plus/plugins/viaTemporaryTable.js.map +1 -1
- package/node8plus/postgresInterval.js +4 -4
- package/node8plus/postgresInterval.js.map +1 -1
- package/node8plus/queryFromResolveDataFactory.js +33 -77
- package/node8plus/queryFromResolveDataFactory.js.map +1 -1
- package/node8plus/utils.js +8 -9
- package/node8plus/utils.js.map +1 -1
- package/node8plus/withPgClient.js +4 -26
- package/node8plus/withPgClient.js.map +1 -1
- package/package.json +4 -4
|
@@ -5,81 +5,51 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.preventEmptyResult = preventEmptyResult;
|
|
8
|
-
|
|
9
8
|
var sql = _interopRequireWildcard(require("pg-sql2"));
|
|
10
|
-
|
|
11
9
|
var _package = require("../../package.json");
|
|
12
|
-
|
|
13
10
|
var _pgField = _interopRequireDefault(require("./pgField"));
|
|
14
|
-
|
|
15
11
|
var _queryFromResolveDataFactory = _interopRequireDefault(require("../queryFromResolveDataFactory"));
|
|
16
|
-
|
|
17
12
|
var _addStartEndCursor = _interopRequireDefault(require("./addStartEndCursor"));
|
|
18
|
-
|
|
19
13
|
var _omit = _interopRequireWildcard(require("../omit"));
|
|
20
|
-
|
|
21
14
|
var _makeProcField = _interopRequireWildcard(require("./makeProcField"));
|
|
22
|
-
|
|
23
15
|
var _PgComputedColumnsPlugin = require("./PgComputedColumnsPlugin");
|
|
24
|
-
|
|
25
16
|
var _parseIdentifier = _interopRequireDefault(require("../parseIdentifier"));
|
|
26
|
-
|
|
27
17
|
var _viaTemporaryTable = _interopRequireDefault(require("./viaTemporaryTable"));
|
|
28
|
-
|
|
29
18
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
30
|
-
|
|
31
19
|
var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
|
|
32
|
-
|
|
33
20
|
var _PgLiveProvider = _interopRequireDefault(require("../PgLiveProvider"));
|
|
34
|
-
|
|
35
21
|
var _pgPrepareAndRun = _interopRequireDefault(require("../pgPrepareAndRun"));
|
|
36
|
-
|
|
37
22
|
var _debugSql = require("./debugSql");
|
|
38
|
-
|
|
39
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
40
|
-
|
|
41
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
42
|
-
|
|
43
25
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
44
|
-
|
|
45
26
|
const defaultPgColumnFilter = (_attr, _build, _context) => true;
|
|
46
|
-
|
|
47
27
|
const identity = _ => _;
|
|
48
|
-
|
|
49
28
|
function preventEmptyResult(obj) {
|
|
50
29
|
return Object.keys(obj).reduce((memo, key) => {
|
|
51
30
|
const fn = obj[key];
|
|
52
|
-
|
|
53
31
|
memo[key] = function (...args) {
|
|
54
32
|
const result = fn.apply(this, args);
|
|
55
|
-
|
|
56
33
|
if (typeof result !== "string" || result.length === 0) {
|
|
57
34
|
const stringifiedArgs = require("util").inspect(args);
|
|
58
|
-
|
|
59
35
|
throw new Error(`Inflector for '${key}' returned '${String(result)}'; expected non-empty string\n` + `See: https://github.com/graphile/graphile-engine/blob/master/packages/graphile-build-pg/src/plugins/PgBasicsPlugin.js\n` + `Arguments passed to ${key}:\n${stringifiedArgs}`);
|
|
60
36
|
}
|
|
61
|
-
|
|
62
37
|
return result;
|
|
63
38
|
};
|
|
64
|
-
|
|
65
39
|
return memo;
|
|
66
40
|
}, {});
|
|
67
41
|
}
|
|
68
|
-
|
|
69
42
|
const omitWithRBACChecks = omit => (entity, permission) => {
|
|
70
43
|
const ORDINARY_TABLE = "r";
|
|
71
44
|
const VIEW = "v";
|
|
72
45
|
const MATERIALIZED_VIEW = "m";
|
|
73
|
-
|
|
74
46
|
const isTableLike = entity => entity && entity.kind === "class" && (entity.classKind === ORDINARY_TABLE || entity.classKind === VIEW || entity.classKind === MATERIALIZED_VIEW);
|
|
75
|
-
|
|
76
47
|
if (entity.kind === "procedure") {
|
|
77
48
|
if (permission === _omit.EXECUTE && !entity.aclExecutable) {
|
|
78
49
|
return true;
|
|
79
50
|
}
|
|
80
51
|
} else if (entity.kind === "class" && isTableLike(entity)) {
|
|
81
52
|
const tableEntity = entity;
|
|
82
|
-
|
|
83
53
|
if ((permission === _omit.READ || permission === _omit.ALL || permission === _omit.MANY) && !tableEntity.aclSelectable && !tableEntity.attributes.some(attr => attr.aclSelectable)) {
|
|
84
54
|
return true;
|
|
85
55
|
} else if (permission === _omit.CREATE && !tableEntity.aclInsertable && !tableEntity.attributes.some(attr => attr.aclInsertable)) {
|
|
@@ -91,8 +61,8 @@ const omitWithRBACChecks = omit => (entity, permission) => {
|
|
|
91
61
|
}
|
|
92
62
|
} else if (entity.kind === "attribute" && isTableLike(entity.class)) {
|
|
93
63
|
const attributeEntity = entity;
|
|
94
|
-
const klass = attributeEntity.class;
|
|
95
|
-
|
|
64
|
+
const klass = attributeEntity.class;
|
|
65
|
+
// Have we got *any* permissions on the table?
|
|
96
66
|
if (klass.aclSelectable || klass.attributes.some(attr => attr.aclSelectable)) {
|
|
97
67
|
// Yes; this is a regular table; omit if RBAC permissions tell us to.
|
|
98
68
|
if ((permission === _omit.READ || permission === _omit.FILTER || permission === _omit.ORDER) && !attributeEntity.aclSelectable) {
|
|
@@ -102,53 +72,44 @@ const omitWithRBACChecks = omit => (entity, permission) => {
|
|
|
102
72
|
} else if (permission === _omit.UPDATE && !attributeEntity.aclUpdatable) {
|
|
103
73
|
return true;
|
|
104
74
|
}
|
|
105
|
-
} else {
|
|
75
|
+
} else {
|
|
76
|
+
// No permissions on the table at all, so normal connections will skip
|
|
106
77
|
// over it. Thus we must be being exposed via a security definer function
|
|
107
78
|
// or similar, so we should expose all fields except those that are
|
|
108
79
|
// explicitly @omit-ed.
|
|
109
80
|
}
|
|
110
81
|
}
|
|
111
|
-
|
|
112
82
|
return omit(entity, permission);
|
|
113
83
|
};
|
|
114
|
-
|
|
115
84
|
const omitUnindexed = (omit, hideIndexWarnings) => (entity, permission) => {
|
|
116
85
|
if (entity.kind === "attribute" && !entity.isIndexed && (permission === "filter" || permission === "order")) {
|
|
117
86
|
return true;
|
|
118
87
|
}
|
|
119
|
-
|
|
120
88
|
if (entity.kind === "constraint" && entity.type === "f" && !entity.isIndexed && permission === "read") {
|
|
121
89
|
const klass = entity.class;
|
|
122
|
-
|
|
123
90
|
if (klass) {
|
|
124
|
-
const shouldOutputWarning =
|
|
91
|
+
const shouldOutputWarning =
|
|
92
|
+
// $FlowFixMe
|
|
125
93
|
!entity._omitUnindexedReadWarningGiven && !hideIndexWarnings;
|
|
126
|
-
|
|
127
94
|
if (shouldOutputWarning) {
|
|
128
95
|
// $FlowFixMe
|
|
129
|
-
entity._omitUnindexedReadWarningGiven = true;
|
|
130
|
-
|
|
96
|
+
entity._omitUnindexedReadWarningGiven = true;
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
131
98
|
console.log("%s", `Disabled 'read' permission for ${describePgEntity(entity)} because it isn't indexed. For more information see https://graphile.org/postgraphile/best-practices/ To fix, perform\n\n CREATE INDEX ON ${`"${klass.namespaceName}"."${klass.name}"`}("${entity.keyAttributes.map(a => a.name).join('", "')}");`);
|
|
132
99
|
}
|
|
133
100
|
}
|
|
134
|
-
|
|
135
101
|
return true;
|
|
136
102
|
}
|
|
137
|
-
|
|
138
103
|
return omit(entity, permission);
|
|
139
104
|
};
|
|
140
|
-
|
|
141
105
|
function describePgEntity(entity, includeAlias = true) {
|
|
142
106
|
const getAlias = !includeAlias ? () => "" : () => {
|
|
143
107
|
const tags = (0, _pickBy.default)(entity.tags, (value, key) => key === "name" || key.endsWith("Name"));
|
|
144
|
-
|
|
145
108
|
if (Object.keys(tags).length) {
|
|
146
109
|
return ` (with smart comments: ${_chalk.default.bold(Object.keys(tags).map(t => `@${t} ${tags[t]}`).join(" | "))})`;
|
|
147
110
|
}
|
|
148
|
-
|
|
149
111
|
return "";
|
|
150
112
|
};
|
|
151
|
-
|
|
152
113
|
try {
|
|
153
114
|
if (entity.kind === "constraint") {
|
|
154
115
|
return `constraint ${_chalk.default.bold(`"${entity.name}"`)} on ${describePgEntity(entity.class, false)}${getAlias()}`;
|
|
@@ -170,18 +131,17 @@ function describePgEntity(entity, includeAlias = true) {
|
|
|
170
131
|
}
|
|
171
132
|
} catch (e) {
|
|
172
133
|
// eslint-disable-next-line no-console
|
|
173
|
-
console.error("Error occurred while attempting to debug entity:", entity);
|
|
174
|
-
|
|
134
|
+
console.error("Error occurred while attempting to debug entity:", entity);
|
|
135
|
+
// eslint-disable-next-line no-console
|
|
175
136
|
console.error(e);
|
|
176
137
|
}
|
|
177
|
-
|
|
178
138
|
return `entity of kind '${entity.kind}' with ${typeof entity.id === "string" ? `oid '${entity.id}'` : ""}`;
|
|
179
139
|
}
|
|
180
|
-
|
|
181
140
|
function sqlCommentByAddingTags(entity, tagsToAdd) {
|
|
182
141
|
// NOTE: this function is NOT intended to be SQL safe; it's for
|
|
183
142
|
// displaying in error messages. Nonetheless if you find issues with
|
|
184
143
|
// SQL compatibility, please send a PR or issue.
|
|
144
|
+
|
|
185
145
|
// Ref: https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-BACKSLASH-TABLE
|
|
186
146
|
const escape = str => str.replace(/['\\\b\f\n\r\t]/g, chr => ({
|
|
187
147
|
"\b": "\\b",
|
|
@@ -189,10 +149,11 @@ function sqlCommentByAddingTags(entity, tagsToAdd) {
|
|
|
189
149
|
"\n": "\\n",
|
|
190
150
|
"\r": "\\r",
|
|
191
151
|
"\t": "\\t"
|
|
192
|
-
})[chr] || "\\" + chr);
|
|
193
|
-
|
|
152
|
+
})[chr] || "\\" + chr);
|
|
194
153
|
|
|
195
|
-
|
|
154
|
+
// tagsToAdd is here twice to ensure that the keys in tagsToAdd come first, but that they also "win" any conflicts.
|
|
155
|
+
const tags = {
|
|
156
|
+
...tagsToAdd,
|
|
196
157
|
...entity.tags,
|
|
197
158
|
...tagsToAdd
|
|
198
159
|
};
|
|
@@ -208,10 +169,8 @@ function sqlCommentByAddingTags(entity, tagsToAdd) {
|
|
|
208
169
|
}, []).join("\\n");
|
|
209
170
|
const commentValue = `E'${tagsSql}${description ? "\\n" + escape(description) : ""}'`;
|
|
210
171
|
let sqlThing;
|
|
211
|
-
|
|
212
172
|
if (entity.kind === "class") {
|
|
213
173
|
const identifier = `"${entity.namespaceName}"."${entity.name}"`;
|
|
214
|
-
|
|
215
174
|
if (entity.classKind === "r") {
|
|
216
175
|
sqlThing = `TABLE ${identifier}`;
|
|
217
176
|
} else if (entity.classKind === "v") {
|
|
@@ -233,10 +192,8 @@ function sqlCommentByAddingTags(entity, tagsToAdd) {
|
|
|
233
192
|
} else {
|
|
234
193
|
sqlThing = `UNKNOWN_ENTITY_PLEASE_SEND_A_PULL_REQUEST`;
|
|
235
194
|
}
|
|
236
|
-
|
|
237
195
|
return `COMMENT ON ${sqlThing} IS ${commentValue};`;
|
|
238
196
|
}
|
|
239
|
-
|
|
240
197
|
var PgBasicsPlugin = function PgBasicsPlugin(builder, {
|
|
241
198
|
pgStrictFunctions = false,
|
|
242
199
|
pgColumnFilter = defaultPgColumnFilter,
|
|
@@ -249,15 +206,12 @@ var PgBasicsPlugin = function PgBasicsPlugin(builder, {
|
|
|
249
206
|
pgAugmentIntrospectionResults
|
|
250
207
|
}) {
|
|
251
208
|
let pgOmit = _omit.default;
|
|
252
|
-
|
|
253
209
|
if (!pgIgnoreRBAC) {
|
|
254
210
|
pgOmit = omitWithRBACChecks(pgOmit);
|
|
255
211
|
}
|
|
256
|
-
|
|
257
212
|
if (!pgIgnoreIndexes) {
|
|
258
213
|
pgOmit = omitUnindexed(pgOmit, pgHideIndexWarnings);
|
|
259
214
|
}
|
|
260
|
-
|
|
261
215
|
builder.hook("build", build => {
|
|
262
216
|
build.versions["graphile-build-pg"] = _package.version;
|
|
263
217
|
build.liveCoordinator.registerProvider(new _PgLiveProvider.default());
|
|
@@ -287,55 +241,43 @@ var PgBasicsPlugin = function PgBasicsPlugin(builder, {
|
|
|
287
241
|
builder.hook("inflection", (inflection, build) => {
|
|
288
242
|
// TODO:v5: move this to postgraphile-core
|
|
289
243
|
const oldBuiltin = inflection.builtin;
|
|
290
|
-
|
|
291
244
|
inflection.builtin = function (name) {
|
|
292
245
|
if (pgLegacyJsonUuid && name === "JSON") return "Json";
|
|
293
246
|
if (pgLegacyJsonUuid && name === "UUID") return "Uuid";
|
|
294
247
|
return oldBuiltin.call(this, name);
|
|
295
248
|
};
|
|
296
|
-
|
|
297
249
|
return build.extend(inflection, preventEmptyResult({
|
|
298
250
|
// These helpers are passed GraphQL type names as strings
|
|
299
251
|
conditionType(typeName) {
|
|
300
252
|
return this.upperCamelCase(`${typeName}-condition`);
|
|
301
253
|
},
|
|
302
|
-
|
|
303
254
|
inputType(typeName) {
|
|
304
255
|
return this.upperCamelCase(`${typeName}-input`);
|
|
305
256
|
},
|
|
306
|
-
|
|
307
257
|
rangeBoundType(typeName) {
|
|
308
258
|
return this.upperCamelCase(`${typeName}-range-bound`);
|
|
309
259
|
},
|
|
310
|
-
|
|
311
260
|
rangeType(typeName) {
|
|
312
261
|
return this.upperCamelCase(`${typeName}-range`);
|
|
313
262
|
},
|
|
314
|
-
|
|
315
263
|
patchType(typeName) {
|
|
316
264
|
return this.upperCamelCase(`${typeName}-patch`);
|
|
317
265
|
},
|
|
318
|
-
|
|
319
266
|
baseInputType(typeName) {
|
|
320
267
|
return this.upperCamelCase(`${typeName}-base-input`);
|
|
321
268
|
},
|
|
322
|
-
|
|
323
269
|
patchField(itemName) {
|
|
324
270
|
return this.camelCase(`${itemName}-patch`);
|
|
325
271
|
},
|
|
326
|
-
|
|
327
272
|
orderByType(typeName) {
|
|
328
273
|
return this.upperCamelCase(`${this.pluralize(typeName)}-order-by`);
|
|
329
274
|
},
|
|
330
|
-
|
|
331
275
|
edge(typeName) {
|
|
332
276
|
return this.upperCamelCase(`${this.pluralize(typeName)}-edge`);
|
|
333
277
|
},
|
|
334
|
-
|
|
335
278
|
connection(typeName) {
|
|
336
279
|
return this.upperCamelCase(`${this.pluralize(typeName)}-connection`);
|
|
337
280
|
},
|
|
338
|
-
|
|
339
281
|
// These helpers handle overrides via smart comments. They should only
|
|
340
282
|
// be used in other inflectors, hence the underscore prefix.
|
|
341
283
|
//
|
|
@@ -345,76 +287,63 @@ var PgBasicsPlugin = function PgBasicsPlugin(builder, {
|
|
|
345
287
|
_functionName(proc) {
|
|
346
288
|
return this.coerceToGraphQLName(proc.tags.name || proc.name);
|
|
347
289
|
},
|
|
348
|
-
|
|
349
290
|
_typeName(type) {
|
|
350
291
|
// 'type' introspection result
|
|
351
292
|
return this.coerceToGraphQLName(type.tags.name || type.name);
|
|
352
293
|
},
|
|
353
|
-
|
|
354
294
|
_tableName(table) {
|
|
355
295
|
return this.coerceToGraphQLName(table.tags.name || table.type.tags.name || table.name);
|
|
356
296
|
},
|
|
357
|
-
|
|
358
297
|
_singularizedTableName(table) {
|
|
359
298
|
return this.singularize(this._tableName(table)).replace(/.(?:(?:[_-]i|I)nput|(?:[_-]p|P)atch)$/, "$&_record");
|
|
360
299
|
},
|
|
361
|
-
|
|
362
300
|
_columnName(attr, _options) {
|
|
363
301
|
return this.coerceToGraphQLName(attr.tags.name || attr.name);
|
|
364
302
|
},
|
|
365
|
-
|
|
366
303
|
// From here down, functions are passed database introspection results
|
|
367
304
|
enumType(type) {
|
|
368
305
|
if (type.tags.enumName) {
|
|
369
306
|
return type.tags.enumName;
|
|
370
307
|
}
|
|
371
|
-
|
|
372
308
|
return this.upperCamelCase(this._typeName(type));
|
|
373
309
|
},
|
|
374
|
-
|
|
375
310
|
argument(name, index) {
|
|
376
311
|
return this.coerceToGraphQLName(this.camelCase(name || `arg${index}`));
|
|
377
312
|
},
|
|
378
|
-
|
|
379
313
|
orderByEnum(columnName, ascending) {
|
|
380
314
|
return this.constantCase(`${columnName}_${ascending ? "asc" : "desc"}`);
|
|
381
315
|
},
|
|
382
|
-
|
|
383
316
|
orderByColumnEnum(attr, ascending) {
|
|
384
317
|
const columnName = this._columnName(attr, {
|
|
385
318
|
skipRowId: true // Because we messed up 😔
|
|
386
|
-
|
|
387
319
|
});
|
|
388
320
|
|
|
389
321
|
return this.orderByEnum(columnName, ascending);
|
|
390
322
|
},
|
|
391
|
-
|
|
392
323
|
orderByComputedColumnEnum(pseudoColumnName, proc, table, ascending) {
|
|
393
324
|
const columnName = this.computedColumn(pseudoColumnName, proc, table);
|
|
394
325
|
return this.orderByEnum(columnName, ascending);
|
|
395
326
|
},
|
|
396
|
-
|
|
397
327
|
domainType(type) {
|
|
398
328
|
return this.upperCamelCase(this._typeName(type));
|
|
399
329
|
},
|
|
400
|
-
|
|
401
330
|
enumName(inValue) {
|
|
402
331
|
let value = inValue;
|
|
403
|
-
|
|
404
332
|
if (value === "") {
|
|
405
333
|
return "_EMPTY_";
|
|
406
|
-
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Some enums use asterisks to signify wildcards - this might be for
|
|
407
337
|
// the whole item, or prefixes/suffixes, or even in the middle. This
|
|
408
338
|
// is provided on a best efforts basis, if it doesn't suit your
|
|
409
339
|
// purposes then please pass a custom inflector as mentioned below.
|
|
340
|
+
value = value.replace(/\*/g, "_ASTERISK_").replace(/^(_?)_+ASTERISK/, "$1ASTERISK").replace(/ASTERISK_(_?)_*$/, "ASTERISK$1");
|
|
410
341
|
|
|
411
|
-
|
|
412
|
-
value = value.replace(/\*/g, "_ASTERISK_").replace(/^(_?)_+ASTERISK/, "$1ASTERISK").replace(/ASTERISK_(_?)_*$/, "ASTERISK$1"); // This is a best efforts replacement for common symbols that you
|
|
342
|
+
// This is a best efforts replacement for common symbols that you
|
|
413
343
|
// might find in enums. Generally we only support enums that are
|
|
414
344
|
// alphanumeric, if these replacements don't work for you, you should
|
|
415
345
|
// pass a custom inflector that replaces this `enumName` method
|
|
416
346
|
// with one of your own chosing.
|
|
417
|
-
|
|
418
347
|
value = {
|
|
419
348
|
// SQL comparison operators
|
|
420
349
|
">": "GREATER_THAN",
|
|
@@ -471,34 +400,26 @@ var PgBasicsPlugin = function PgBasicsPlugin(builder, {
|
|
|
471
400
|
}[value] || value;
|
|
472
401
|
return value;
|
|
473
402
|
},
|
|
474
|
-
|
|
475
403
|
tableNode(table) {
|
|
476
404
|
return this.camelCase(this._singularizedTableName(table));
|
|
477
405
|
},
|
|
478
|
-
|
|
479
406
|
tableFieldName(table) {
|
|
480
407
|
return this.camelCase(this._singularizedTableName(table));
|
|
481
408
|
},
|
|
482
|
-
|
|
483
409
|
allRows(table) {
|
|
484
410
|
return this.camelCase(`all-${this.pluralize(this._singularizedTableName(table))}`);
|
|
485
411
|
},
|
|
486
|
-
|
|
487
412
|
allRowsSimple(table) {
|
|
488
413
|
return this.camelCase(`all-${this.pluralize(this._singularizedTableName(table))}-list`);
|
|
489
414
|
},
|
|
490
|
-
|
|
491
415
|
functionMutationName(proc) {
|
|
492
416
|
return this.camelCase(this._functionName(proc));
|
|
493
417
|
},
|
|
494
|
-
|
|
495
418
|
functionMutationResultFieldName(proc, gqlType, plural = false, outputArgNames = []) {
|
|
496
419
|
if (proc.tags.resultFieldName) {
|
|
497
420
|
return proc.tags.resultFieldName;
|
|
498
421
|
}
|
|
499
|
-
|
|
500
422
|
let name;
|
|
501
|
-
|
|
502
423
|
if (outputArgNames.length === 1 && outputArgNames[0] !== "") {
|
|
503
424
|
name = this.camelCase(outputArgNames[0]);
|
|
504
425
|
} else if (gqlType.name === "Int") {
|
|
@@ -515,193 +436,145 @@ var PgBasicsPlugin = function PgBasicsPlugin(builder, {
|
|
|
515
436
|
} else {
|
|
516
437
|
name = this.camelCase(gqlType.name);
|
|
517
438
|
}
|
|
518
|
-
|
|
519
439
|
return plural ? this.pluralize(name) : name;
|
|
520
440
|
},
|
|
521
|
-
|
|
522
441
|
functionQueryName(proc) {
|
|
523
442
|
return this.camelCase(this._functionName(proc));
|
|
524
443
|
},
|
|
525
|
-
|
|
526
444
|
functionQueryNameList(proc) {
|
|
527
445
|
return this.camelCase(`${this._functionName(proc)}-list`);
|
|
528
446
|
},
|
|
529
|
-
|
|
530
447
|
functionPayloadType(proc) {
|
|
531
448
|
return this.upperCamelCase(`${this._functionName(proc)}-payload`);
|
|
532
449
|
},
|
|
533
|
-
|
|
534
450
|
functionInputType(proc) {
|
|
535
451
|
return this.upperCamelCase(`${this._functionName(proc)}-input`);
|
|
536
452
|
},
|
|
537
|
-
|
|
538
453
|
functionOutputFieldName(proc, outputArgName, index) {
|
|
539
454
|
return this.argument(outputArgName, index);
|
|
540
455
|
},
|
|
541
|
-
|
|
542
456
|
tableType(table) {
|
|
543
457
|
return this.upperCamelCase(this._singularizedTableName(table));
|
|
544
458
|
},
|
|
545
|
-
|
|
546
459
|
column(attr) {
|
|
547
460
|
return this.camelCase(this._columnName(attr));
|
|
548
461
|
},
|
|
549
|
-
|
|
550
462
|
computedColumn(pseudoColumnName, proc, _table) {
|
|
551
463
|
return proc.tags.fieldName || this.camelCase(pseudoColumnName);
|
|
552
464
|
},
|
|
553
|
-
|
|
554
465
|
computedColumnList(pseudoColumnName, proc, _table) {
|
|
555
466
|
return proc.tags.fieldName ? proc.tags.fieldName + "List" : this.camelCase(`${pseudoColumnName}-list`);
|
|
556
467
|
},
|
|
557
|
-
|
|
558
468
|
singleRelationByKeys(detailedKeys, table, _foreignTable, constraint) {
|
|
559
469
|
if (constraint.tags.fieldName) {
|
|
560
470
|
return constraint.tags.fieldName;
|
|
561
471
|
}
|
|
562
|
-
|
|
563
472
|
return this.camelCase(`${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}`);
|
|
564
473
|
},
|
|
565
|
-
|
|
566
474
|
singleRelationByKeysBackwards(detailedKeys, table, _foreignTable, constraint) {
|
|
567
475
|
if (constraint.tags.foreignSingleFieldName) {
|
|
568
476
|
return constraint.tags.foreignSingleFieldName;
|
|
569
477
|
}
|
|
570
|
-
|
|
571
478
|
if (constraint.tags.foreignFieldName) {
|
|
572
479
|
return constraint.tags.foreignFieldName;
|
|
573
480
|
}
|
|
574
|
-
|
|
575
481
|
return this.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
576
482
|
},
|
|
577
|
-
|
|
578
483
|
manyRelationByKeys(detailedKeys, table, _foreignTable, constraint) {
|
|
579
484
|
if (constraint.tags.foreignFieldName) {
|
|
580
485
|
return constraint.tags.foreignFieldName;
|
|
581
486
|
}
|
|
582
|
-
|
|
583
487
|
return this.camelCase(`${this.pluralize(this._singularizedTableName(table))}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}`);
|
|
584
488
|
},
|
|
585
|
-
|
|
586
489
|
manyRelationByKeysSimple(detailedKeys, table, _foreignTable, constraint) {
|
|
587
490
|
if (constraint.tags.foreignSimpleFieldName) {
|
|
588
491
|
return constraint.tags.foreignSimpleFieldName;
|
|
589
492
|
}
|
|
590
|
-
|
|
591
493
|
if (constraint.tags.foreignFieldName) {
|
|
592
494
|
return constraint.tags.foreignFieldName;
|
|
593
495
|
}
|
|
594
|
-
|
|
595
496
|
return this.camelCase(`${this.pluralize(this._singularizedTableName(table))}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}-list`);
|
|
596
497
|
},
|
|
597
|
-
|
|
598
498
|
rowByUniqueKeys(detailedKeys, table, constraint) {
|
|
599
499
|
if (constraint.tags.fieldName) {
|
|
600
500
|
return constraint.tags.fieldName;
|
|
601
501
|
}
|
|
602
|
-
|
|
603
502
|
return this.camelCase(`${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}`);
|
|
604
503
|
},
|
|
605
|
-
|
|
606
504
|
updateByKeys(detailedKeys, table, constraint) {
|
|
607
505
|
if (constraint.tags.updateFieldName) {
|
|
608
506
|
return constraint.tags.updateFieldName;
|
|
609
507
|
}
|
|
610
|
-
|
|
611
508
|
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}`);
|
|
612
509
|
},
|
|
613
|
-
|
|
614
510
|
deleteByKeys(detailedKeys, table, constraint) {
|
|
615
511
|
if (constraint.tags.deleteFieldName) {
|
|
616
512
|
return constraint.tags.deleteFieldName;
|
|
617
513
|
}
|
|
618
|
-
|
|
619
514
|
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}`);
|
|
620
515
|
},
|
|
621
|
-
|
|
622
516
|
updateByKeysInputType(detailedKeys, table, constraint) {
|
|
623
517
|
if (constraint.tags.updateFieldName) {
|
|
624
518
|
return this.upperCamelCase(`${constraint.tags.updateFieldName}-input`);
|
|
625
519
|
}
|
|
626
|
-
|
|
627
520
|
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}-input`);
|
|
628
521
|
},
|
|
629
|
-
|
|
630
522
|
deleteByKeysInputType(detailedKeys, table, constraint) {
|
|
631
523
|
if (constraint.tags.deleteFieldName) {
|
|
632
524
|
return this.upperCamelCase(`${constraint.tags.deleteFieldName}-input`);
|
|
633
525
|
}
|
|
634
|
-
|
|
635
526
|
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}-input`);
|
|
636
527
|
},
|
|
637
|
-
|
|
638
528
|
updateNode(table) {
|
|
639
529
|
return this.camelCase(`update-${this._singularizedTableName(table)}`);
|
|
640
530
|
},
|
|
641
|
-
|
|
642
531
|
deleteNode(table) {
|
|
643
532
|
return this.camelCase(`delete-${this._singularizedTableName(table)}`);
|
|
644
533
|
},
|
|
645
|
-
|
|
646
534
|
deletedNodeId(table) {
|
|
647
535
|
return this.camelCase(`deleted-${this.singularize(table.name)}-id`);
|
|
648
536
|
},
|
|
649
|
-
|
|
650
537
|
updateNodeInputType(table) {
|
|
651
538
|
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-input`);
|
|
652
539
|
},
|
|
653
|
-
|
|
654
540
|
deleteNodeInputType(table) {
|
|
655
541
|
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-input`);
|
|
656
542
|
},
|
|
657
|
-
|
|
658
543
|
edgeField(table) {
|
|
659
544
|
return this.camelCase(`${this._singularizedTableName(table)}-edge`);
|
|
660
545
|
},
|
|
661
|
-
|
|
662
546
|
recordFunctionReturnType(proc) {
|
|
663
547
|
return proc.tags.resultTypeName || this.upperCamelCase(`${this._functionName(proc)}-record`);
|
|
664
548
|
},
|
|
665
|
-
|
|
666
549
|
recordFunctionConnection(proc) {
|
|
667
550
|
return this.upperCamelCase(`${this._functionName(proc)}-connection`);
|
|
668
551
|
},
|
|
669
|
-
|
|
670
552
|
recordFunctionEdge(proc) {
|
|
671
553
|
return this.upperCamelCase(`${this.singularize(this._functionName(proc))}-edge`);
|
|
672
554
|
},
|
|
673
|
-
|
|
674
555
|
scalarFunctionConnection(proc) {
|
|
675
556
|
return this.upperCamelCase(`${this._functionName(proc)}-connection`);
|
|
676
557
|
},
|
|
677
|
-
|
|
678
558
|
scalarFunctionEdge(proc) {
|
|
679
559
|
return this.upperCamelCase(`${this.singularize(this._functionName(proc))}-edge`);
|
|
680
560
|
},
|
|
681
|
-
|
|
682
561
|
createField(table) {
|
|
683
562
|
return this.camelCase(`create-${this._singularizedTableName(table)}`);
|
|
684
563
|
},
|
|
685
|
-
|
|
686
564
|
createInputType(table) {
|
|
687
565
|
return this.upperCamelCase(`create-${this._singularizedTableName(table)}-input`);
|
|
688
566
|
},
|
|
689
|
-
|
|
690
567
|
createPayloadType(table) {
|
|
691
568
|
return this.upperCamelCase(`create-${this._singularizedTableName(table)}-payload`);
|
|
692
569
|
},
|
|
693
|
-
|
|
694
570
|
updatePayloadType(table) {
|
|
695
571
|
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-payload`);
|
|
696
572
|
},
|
|
697
|
-
|
|
698
573
|
deletePayloadType(table) {
|
|
699
574
|
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-payload`);
|
|
700
575
|
}
|
|
701
|
-
|
|
702
576
|
}), "Default inflectors from PgBasicsPlugin. You can override these with `makeAddInflectorsPlugin(..., true)`.");
|
|
703
577
|
}, ["PgBasics"]);
|
|
704
578
|
};
|
|
705
|
-
|
|
706
579
|
exports.default = PgBasicsPlugin;
|
|
707
580
|
//# sourceMappingURL=PgBasicsPlugin.js.map
|