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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"PageInfoStartEndCursor.js","names":["PageInfoStartEndCursor","builder","hook","fields","build","context","extend","getTypeByName","inflection","Self","fieldWithHooks","name","builtin","Cursor","startCursor","addDataGenerator","usesCursor","description","wrapDescription","type","isPageInfoStartCursorField","endCursor","exports","default"],"sources":["../../src/plugins/PageInfoStartEndCursor.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nexport default (function PageInfoStartEndCursor(builder) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const { extend, getTypeByName, inflection } = build;\n const { Self, fieldWithHooks } = context;\n if (Self.name !== inflection.builtin(\"PageInfo\")) {\n return fields;\n }\n const Cursor = getTypeByName(\"Cursor\");\n return extend(\n fields,\n {\n startCursor: fieldWithHooks(\n \"startCursor\",\n ({ addDataGenerator }) => {\n addDataGenerator(() => ({ usesCursor: [true] }));\n return {\n description: build.wrapDescription(\n \"When paginating backwards, the cursor to continue.\",\n \"field\"\n ),\n type: Cursor,\n };\n },\n {\n isPageInfoStartCursorField: true,\n }\n ),\n endCursor: fieldWithHooks(\n \"endCursor\",\n ({ addDataGenerator }) => {\n addDataGenerator(() => ({ usesCursor: [true] }));\n return {\n description: build.wrapDescription(\n \"When paginating forwards, the cursor to continue.\",\n \"field\"\n ),\n type: Cursor,\n };\n },\n {\n isPageInfoStartCursorField: true,\n }\n ),\n },\n `Adding startCursor/endCursor to ${Self.name}`\n );\n },\n [\"P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C;EACH,CAAC,EACD,CAAC,wBAAwB,CAAC,EAC1B,EAAE,EACF,CAAC,QAAQ,CACX,CAAC;AACH,CAAC;AAAAW,OAAA,CAAAC,OAAA,GAAAvB,sBAAA"}
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _debugSql = _interopRequireDefault(require("./debugSql"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
var PgAllRows = async function PgAllRows(builder, {
|
|
13
10
|
pgViewUniqueKey,
|
|
14
11
|
pgSimpleCollections,
|
|
@@ -38,49 +35,37 @@ var PgAllRows = async function PgAllRows(builder, {
|
|
|
38
35
|
isRootQuery
|
|
39
36
|
}
|
|
40
37
|
} = context;
|
|
41
|
-
|
|
42
38
|
if (!isRootQuery) {
|
|
43
39
|
return fields;
|
|
44
40
|
}
|
|
45
|
-
|
|
46
41
|
return extend(fields, introspectionResultsByKind.class.reduce((memo, table) => {
|
|
47
42
|
// PERFORMANCE: These used to be .filter(...) calls
|
|
48
43
|
if (!table.isSelectable) return memo;
|
|
49
44
|
if (!table.namespace) return memo;
|
|
50
45
|
if (omit(table, "all")) return memo;
|
|
51
46
|
const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);
|
|
52
|
-
|
|
53
47
|
if (!TableType) {
|
|
54
48
|
return memo;
|
|
55
49
|
}
|
|
56
|
-
|
|
57
50
|
const tableTypeName = TableType.name;
|
|
58
51
|
const ConnectionType = getTypeByName(inflection.connection(TableType.name));
|
|
59
|
-
|
|
60
52
|
if (!TableType) {
|
|
61
53
|
throw new Error(`Could not find GraphQL type for table '${table.name}'`);
|
|
62
54
|
}
|
|
63
|
-
|
|
64
55
|
const attributes = table.attributes;
|
|
65
56
|
const primaryKeyConstraint = table.primaryKeyConstraint;
|
|
66
57
|
const primaryKeys = primaryKeyConstraint && primaryKeyConstraint.keyAttributes;
|
|
67
|
-
|
|
68
58
|
const isView = t => t.classKind === "v";
|
|
69
|
-
|
|
70
59
|
const viewUniqueKey = table.tags.uniqueKey || pgViewUniqueKey;
|
|
71
60
|
const uniqueIdAttribute = viewUniqueKey ? attributes.find(attr => attr.name === viewUniqueKey) : undefined;
|
|
72
|
-
|
|
73
61
|
if (isView(table) && table.tags.uniqueKey && !uniqueIdAttribute) {
|
|
74
62
|
throw new Error(`Could not find the named unique key '${table.tags.uniqueKey}' on view '${table.namespaceName}.${table.name}'`);
|
|
75
63
|
}
|
|
76
|
-
|
|
77
64
|
if (!ConnectionType) {
|
|
78
65
|
throw new Error(`Could not find GraphQL connection type for table '${table.name}'`);
|
|
79
66
|
}
|
|
80
|
-
|
|
81
67
|
const schema = table.namespace;
|
|
82
68
|
const sqlFullTableName = sql.identifier(schema.name, table.name);
|
|
83
|
-
|
|
84
69
|
function makeField(isConnection) {
|
|
85
70
|
const fieldName = isConnection ? inflection.allRows(table) : inflection.allRowsSimple(table);
|
|
86
71
|
memo[fieldName] = fieldWithHooks(fieldName, ({
|
|
@@ -90,14 +75,12 @@ var PgAllRows = async function PgAllRows(builder, {
|
|
|
90
75
|
description: build.wrapDescription(isConnection ? `Reads and enables pagination through a set of \`${tableTypeName}\`.` : `Reads a set of \`${tableTypeName}\`.`, "field"),
|
|
91
76
|
type: isConnection ? ConnectionType : new GraphQLList(new GraphQLNonNull(TableType)),
|
|
92
77
|
args: {},
|
|
93
|
-
|
|
94
78
|
async resolve(parent, args, resolveContext, resolveInfo) {
|
|
95
79
|
const {
|
|
96
80
|
pgClient
|
|
97
81
|
} = resolveContext;
|
|
98
82
|
const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);
|
|
99
83
|
parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin
|
|
100
|
-
|
|
101
84
|
const resolveData = getDataFromParsedResolveInfoFragment(parsedResolveInfoFragment, resolveInfo.returnType);
|
|
102
85
|
let checkerGenerator;
|
|
103
86
|
const query = queryFromResolveData(sqlFullTableName, undefined, resolveData, {
|
|
@@ -109,12 +92,10 @@ var PgAllRows = async function PgAllRows(builder, {
|
|
|
109
92
|
checkerGenerator = _checkerGenerator;
|
|
110
93
|
});
|
|
111
94
|
}
|
|
112
|
-
|
|
113
95
|
if (primaryKeys) {
|
|
114
96
|
if (subscriptions && !isConnection) {
|
|
115
97
|
queryBuilder.selectIdentifiers(table);
|
|
116
98
|
}
|
|
117
|
-
|
|
118
99
|
queryBuilder.beforeLock("orderBy", () => {
|
|
119
100
|
if (!queryBuilder.isOrderUnique(false)) {
|
|
120
101
|
// Order by PK if no order specified
|
|
@@ -142,12 +123,10 @@ var PgAllRows = async function PgAllRows(builder, {
|
|
|
142
123
|
if (_debugSql.default.enabled) (0, _debugSql.default)(text);
|
|
143
124
|
const result = await pgPrepareAndRun(pgClient, text, values);
|
|
144
125
|
const liveCollection = resolveInfo.rootValue && resolveInfo.rootValue.liveCollection;
|
|
145
|
-
|
|
146
126
|
if (subscriptions && liveCollection && checkerGenerator) {
|
|
147
127
|
const checker = checkerGenerator();
|
|
148
128
|
liveCollection("pg", table, checker);
|
|
149
129
|
}
|
|
150
|
-
|
|
151
130
|
if (isConnection) {
|
|
152
131
|
const {
|
|
153
132
|
rows: [row]
|
|
@@ -155,15 +134,12 @@ var PgAllRows = async function PgAllRows(builder, {
|
|
|
155
134
|
return addStartEndCursor(row);
|
|
156
135
|
} else {
|
|
157
136
|
const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
|
|
158
|
-
|
|
159
137
|
if (subscriptions && !isConnection && primaryKeys && liveRecord) {
|
|
160
138
|
result.rows.forEach(row => row && liveRecord("pg", table, row.__identifiers));
|
|
161
139
|
}
|
|
162
|
-
|
|
163
140
|
return result.rows;
|
|
164
141
|
}
|
|
165
142
|
}
|
|
166
|
-
|
|
167
143
|
};
|
|
168
144
|
}, {
|
|
169
145
|
isPgFieldConnection: isConnection,
|
|
@@ -171,23 +147,18 @@ var PgAllRows = async function PgAllRows(builder, {
|
|
|
171
147
|
pgFieldIntrospection: table
|
|
172
148
|
});
|
|
173
149
|
}
|
|
174
|
-
|
|
175
150
|
const simpleCollections = table.tags.simpleCollections || pgSimpleCollections;
|
|
176
151
|
const hasConnections = simpleCollections !== "only";
|
|
177
152
|
const hasSimpleCollections = simpleCollections === "only" || simpleCollections === "both";
|
|
178
|
-
|
|
179
153
|
if (TableType && ConnectionType && hasConnections) {
|
|
180
154
|
makeField(true);
|
|
181
155
|
}
|
|
182
|
-
|
|
183
156
|
if (TableType && hasSimpleCollections) {
|
|
184
157
|
makeField(false);
|
|
185
158
|
}
|
|
186
|
-
|
|
187
159
|
return memo;
|
|
188
160
|
}, {}), `Adding 'all*' relations to root Query`);
|
|
189
161
|
}, ["PgAllRows"], [], ["PgTables"]);
|
|
190
162
|
};
|
|
191
|
-
|
|
192
163
|
exports.default = PgAllRows;
|
|
193
164
|
//# sourceMappingURL=PgAllRows.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/PgAllRows.js"],"names":["PgAllRows","builder","pgViewUniqueKey","pgSimpleCollections","subscriptions","hook","fields","build","context","parseResolveInfo","extend","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","pgSql","sql","pgIntrospectionResultsByKind","introspectionResultsByKind","inflection","graphql","GraphQLList","GraphQLNonNull","pgQueryFromResolveData","queryFromResolveData","pgAddStartEndCursor","addStartEndCursor","pgOmit","omit","pgPrepareAndRun","fieldWithHooks","scope","isRootQuery","class","reduce","memo","table","isSelectable","namespace","TableType","type","id","tableTypeName","name","ConnectionType","connection","Error","attributes","primaryKeyConstraint","primaryKeys","keyAttributes","isView","t","classKind","viewUniqueKey","tags","uniqueKey","uniqueIdAttribute","find","attr","undefined","namespaceName","schema","sqlFullTableName","identifier","makeField","isConnection","fieldName","allRows","allRowsSimple","getDataFromParsedResolveInfoFragment","description","wrapDescription","args","resolve","parent","resolveContext","resolveInfo","pgClient","parsedResolveInfoFragment","resolveData","returnType","checkerGenerator","query","useAsterisk","canUseAsterisk","withPaginationAsFields","queryBuilder","makeLiveCollection","_checkerGenerator","selectIdentifiers","beforeLock","isOrderUnique","data","cursorPrefix","forEach","key","orderBy","fragment","getTableAlias","setOrderIsUnique","rootValue","text","values","compile","debugSql","enabled","result","liveCollection","checker","rows","row","liveRecord","__identifiers","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospection","simpleCollections","hasConnections","hasSimpleCollections"],"mappings":";;;;;;;AAGA;;;;IAE+BA,S,GAAf,eAAeA,SAAf,CACdC,OADc,EAEd;AAAEC,EAAAA,eAAF;AAAmBC,EAAAA,mBAAnB;AAAwCC,EAAAA;AAAxC,CAFc,EAGd;AACAH,EAAAA,OAAO,CAACI,IAAR,CACE,0BADF,EAEE,CAACC,MAAD,EAASC,KAAT,EAAgBC,OAAhB,KAA4B;AAC1B,UAAM;AACJC,MAAAA,gBADI;AAEJC,MAAAA,MAFI;AAGJC,MAAAA,aAHI;AAIJC,MAAAA,+BAJI;AAKJC,MAAAA,KAAK,EAAEC,GALH;AAMJC,MAAAA,4BAA4B,EAAEC,0BAN1B;AAOJC,MAAAA,UAPI;AAQJC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,WAAF;AAAeC,QAAAA;AAAf,OARL;AASJC,MAAAA,sBAAsB,EAAEC,oBATpB;AAUJC,MAAAA,mBAAmB,EAAEC,iBAVjB;AAWJC,MAAAA,MAAM,EAAEC,IAXJ;AAYJC,MAAAA;AAZI,QAaFpB,KAbJ;AAcA,UAAM;AACJqB,MAAAA,cADI;AAEJC,MAAAA,KAAK,EAAE;AAAEC,QAAAA;AAAF;AAFH,QAGFtB,OAHJ;;AAIA,QAAI,CAACsB,WAAL,EAAkB;AAChB,aAAOxB,MAAP;AACD;;AACD,WAAOI,MAAM,CACXJ,MADW,EAEXU,0BAA0B,CAACe,KAA3B,CAAiCC,MAAj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nC,WAAW,CAACwB,SAAZ,IACAxB,WAAW,CAACwB,SAAZ,CAAsBW,UAFxB;;AAGA,oBACE1G,aAAa,IACb,CAAC4D,YADD,IAEAjB,WAFA,IAGA+D,UAJF,EAKE;AACAL,kBAAAA,MAAM,CAACG,IAAP,CAAYf,OAAZ,CACEgB,GAAG,IACDA,GAAG,IAAIC,UAAU,CAAC,IAAD,EAAO5E,KAAP,EAAc2E,GAAG,CAACE,aAAlB,CAFrB;AAID;;AACD,uBAAON,MAAM,CAACG,IAAd;AACD;AACF;;AArHI,WAAP;AAuHD,SA1H6B,EA2H9B;AACEI,UAAAA,mBAAmB,EAAEhD,YADvB;AAEEiD,UAAAA,yBAAyB,EAAE,CAACjD,YAF9B;AAGEkD,UAAAA,oBAAoB,EAAEhF;AAHxB,SA3H8B,CAAhC;AAiID;;AACD,YAAMiF,iBAAiB,GACrBjF,KAAK,CAACmB,IAAN,CAAW8D,iBAAX,IAAgChH,mBADlC;AAEA,YAAMiH,cAAc,GAAGD,iBAAiB,KAAK,MAA7C;AACA,YAAME,oBAAoB,GACxBF,iBAAiB,KAAK,MAAtB,IAAgCA,iBAAiB,KAAK,MADxD;;AAEA,UAAI9E,SAAS,IAAIK,cAAb,IAA+B0E,cAAnC,EAAmD;AACjDrD,QAAAA,SAAS,CAAC,IAAD,CAAT;AACD;;AACD,UAAI1B,SAAS,IAAIgF,oBAAjB,EAAuC;AACrCtD,QAAAA,SAAS,CAAC,KAAD,CAAT;AACD;;AACD,aAAO9B,IAAP;AACD,KA7LD,EA6LG,EA7LH,CAFW,EAgMV,uCAhMU,CAAb;AAkMD,GA1NH,EA2NE,CAAC,WAAD,CA3NF,EA4NE,EA5NF,EA6NE,CAAC,UAAD,CA7NF;AA+ND,C","sourcesContent":["// @flow\n\nimport type { Plugin } from \"graphile-build\";\nimport debugSql from \"./debugSql\";\n\nexport default (async function PgAllRows(\n builder,\n { pgViewUniqueKey, pgSimpleCollections, subscriptions }\n) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n parseResolveInfo,\n extend,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n pgSql: sql,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n inflection,\n graphql: { GraphQLList, GraphQLNonNull },\n pgQueryFromResolveData: queryFromResolveData,\n pgAddStartEndCursor: addStartEndCursor,\n pgOmit: omit,\n pgPrepareAndRun,\n } = build;\n const {\n fieldWithHooks,\n scope: { isRootQuery },\n } = context;\n if (!isRootQuery) {\n return fields;\n }\n return extend(\n fields,\n introspectionResultsByKind.class.reduce((memo, table) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.isSelectable) return memo;\n if (!table.namespace) return memo;\n if (omit(table, \"all\")) return memo;\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n table.type.id,\n null\n );\n if (!TableType) {\n return memo;\n }\n const tableTypeName = TableType.name;\n const ConnectionType = getTypeByName(\n inflection.connection(TableType.name)\n );\n if (!TableType) {\n throw new Error(\n `Could not find GraphQL type for table '${table.name}'`\n );\n }\n const attributes = table.attributes;\n const primaryKeyConstraint = table.primaryKeyConstraint;\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n const isView = t => t.classKind === \"v\";\n const viewUniqueKey = table.tags.uniqueKey || pgViewUniqueKey;\n const uniqueIdAttribute = viewUniqueKey\n ? attributes.find(attr => attr.name === viewUniqueKey)\n : undefined;\n if (isView(table) && table.tags.uniqueKey && !uniqueIdAttribute) {\n throw new Error(\n `Could not find the named unique key '${table.tags.uniqueKey}' on view '${table.namespaceName}.${table.name}'`\n );\n }\n if (!ConnectionType) {\n throw new Error(\n `Could not find GraphQL connection type for table '${table.name}'`\n );\n }\n const schema = table.namespace;\n const sqlFullTableName = sql.identifier(schema.name, table.name);\n function makeField(isConnection) {\n const fieldName = isConnection\n ? inflection.allRows(table)\n : inflection.allRowsSimple(table);\n memo[fieldName] = fieldWithHooks(\n fieldName,\n ({ getDataFromParsedResolveInfoFragment }) => {\n return {\n description: build.wrapDescription(\n isConnection\n ? `Reads and enables pagination through a set of \\`${tableTypeName}\\`.`\n : `Reads a set of \\`${tableTypeName}\\`.`,\n \"field\"\n ),\n type: isConnection\n ? ConnectionType\n : new GraphQLList(new GraphQLNonNull(TableType)),\n args: {},\n async resolve(parent, args, resolveContext, resolveInfo) {\n const { pgClient } = resolveContext;\n const parsedResolveInfoFragment =\n parseResolveInfo(resolveInfo);\n parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin\n const resolveData = getDataFromParsedResolveInfoFragment(\n parsedResolveInfoFragment,\n resolveInfo.returnType\n );\n let checkerGenerator;\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n {\n useAsterisk: table.canUseAsterisk,\n withPaginationAsFields: isConnection,\n },\n queryBuilder => {\n if (subscriptions) {\n queryBuilder.makeLiveCollection(\n table,\n _checkerGenerator => {\n checkerGenerator = _checkerGenerator;\n }\n );\n }\n if (primaryKeys) {\n if (subscriptions && !isConnection) {\n queryBuilder.selectIdentifiers(table);\n }\n queryBuilder.beforeLock(\"orderBy\", () => {\n if (!queryBuilder.isOrderUnique(false)) {\n // Order by PK if no order specified\n queryBuilder.data.cursorPrefix = [\n \"primary_key_asc\",\n ];\n primaryKeys.forEach(key => {\n queryBuilder.orderBy(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n key.name\n )}`,\n true\n );\n });\n queryBuilder.setOrderIsUnique();\n }\n });\n } else if (isView(table) && !!uniqueIdAttribute) {\n queryBuilder.beforeLock(\"orderBy\", () => {\n if (!queryBuilder.isOrderUnique(false)) {\n queryBuilder.data.cursorPrefix = [\n \"view_unique_key_asc\",\n ];\n queryBuilder.orderBy(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n uniqueIdAttribute.name\n )}`,\n true\n );\n queryBuilder.setOrderIsUnique();\n }\n });\n }\n },\n resolveContext,\n resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const result = await pgPrepareAndRun(\n pgClient,\n text,\n values\n );\n\n const liveCollection =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveCollection;\n if (subscriptions && liveCollection && checkerGenerator) {\n const checker = checkerGenerator();\n liveCollection(\"pg\", table, checker);\n }\n\n if (isConnection) {\n const {\n rows: [row],\n } = result;\n return addStartEndCursor(row);\n } else {\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n if (\n subscriptions &&\n !isConnection &&\n primaryKeys &&\n liveRecord\n ) {\n result.rows.forEach(\n row =>\n row && liveRecord(\"pg\", table, row.__identifiers)\n );\n }\n return result.rows;\n }\n },\n };\n },\n {\n isPgFieldConnection: isConnection,\n isPgFieldSimpleCollection: !isConnection,\n pgFieldIntrospection: table,\n }\n );\n }\n const simpleCollections =\n table.tags.simpleCollections || pgSimpleCollections;\n const hasConnections = simpleCollections !== \"only\";\n const hasSimpleCollections =\n simpleCollections === \"only\" || simpleCollections === \"both\";\n if (TableType && ConnectionType && hasConnections) {\n makeField(true);\n }\n if (TableType && hasSimpleCollections) {\n makeField(false);\n }\n return memo;\n }, {}),\n `Adding 'all*' relations to root Query`\n );\n },\n [\"PgAllRows\"],\n [],\n [\"PgTables\"]\n );\n}: Plugin);\n"],"file":"PgAllRows.js"}
|
|
1
|
+
{"version":3,"file":"PgAllRows.js","names":["_debugSql","_interopRequireDefault","require","obj","__esModule","default","PgAllRows","builder","pgViewUniqueKey","pgSimpleCollections","subscriptions","hook","fields","build","context","parseResolveInfo","extend","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","pgSql","sql","pgIntrospectionResultsByKind","introspectionResultsByKind","inflection","graphql","GraphQLList","GraphQLNonNull","pgQueryFromResolveData","queryFromResolveData","pgAddStartEndCursor","addStartEndCursor","pgOmit","omit","pgPrepareAndRun","fieldWithHooks","scope","isRootQuery","class","reduce","memo","table","isSelectable","namespace","TableType","type","id","tableTypeName","name","ConnectionType","connection","Error","attributes","primaryKeyConstraint","primaryKeys","keyAttributes","isView","t","classKind","viewUniqueKey","tags","uniqueKey","uniqueIdAttribute","find","attr","undefined","namespaceName","schema","sqlFullTableName","identifier","makeField","isConnection","fieldName","allRows","allRowsSimple","getDataFromParsedResolveInfoFragment","description","wrapDescription","args","resolve","parent","resolveContext","resolveInfo","pgClient","parsedResolveInfoFragment","resolveData","returnType","checkerGenerator","query","useAsterisk","canUseAsterisk","withPaginationAsFields","queryBuilder","makeLiveCollection","_checkerGenerator","selectIdentifiers","beforeLock","isOrderUnique","data","cursorPrefix","forEach","key","orderBy","fragment","getTableAlias","setOrderIsUnique","rootValue","text","values","compile","debugSql","enabled","result","liveCollection","checker","rows","row","liveRecord","__identifiers","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospection","simpleCollections","hasConnections","hasSimpleCollections","exports"],"sources":["../../src/plugins/PgAllRows.js"],"sourcesContent":["// @flow\n\nimport type { Plugin } from \"graphile-build\";\nimport debugSql from \"./debugSql\";\n\nexport default (async function PgAllRows(\n builder,\n { pgViewUniqueKey, pgSimpleCollections, subscriptions }\n) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n parseResolveInfo,\n extend,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n pgSql: sql,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n inflection,\n graphql: { GraphQLList, GraphQLNonNull },\n pgQueryFromResolveData: queryFromResolveData,\n pgAddStartEndCursor: addStartEndCursor,\n pgOmit: omit,\n pgPrepareAndRun,\n } = build;\n const {\n fieldWithHooks,\n scope: { isRootQuery },\n } = context;\n if (!isRootQuery) {\n return fields;\n }\n return extend(\n fields,\n introspectionResultsByKind.class.reduce((memo, table) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.isSelectable) return memo;\n if (!table.namespace) return memo;\n if (omit(table, \"all\")) return memo;\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n table.type.id,\n null\n );\n if (!TableType) {\n return memo;\n }\n const tableTypeName = TableType.name;\n const ConnectionType = getTypeByName(\n inflection.connection(TableType.name)\n );\n if (!TableType) {\n throw new Error(\n `Could not find GraphQL type for table '${table.name}'`\n );\n }\n const attributes = table.attributes;\n const primaryKeyConstraint = table.primaryKeyConstraint;\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n const isView = t => t.classKind === \"v\";\n const viewUniqueKey = table.tags.uniqueKey || pgViewUniqueKey;\n const uniqueIdAttribute = viewUniqueKey\n ? attributes.find(attr => attr.name === viewUniqueKey)\n : undefined;\n if (isView(table) && table.tags.uniqueKey && !uniqueIdAttribute) {\n throw new Error(\n `Could not find the named unique key '${table.tags.uniqueKey}' on view '${table.namespaceName}.${table.name}'`\n );\n }\n if (!ConnectionType) {\n throw new Error(\n `Could not find GraphQL connection type for table '${table.name}'`\n );\n }\n const schema = table.namespace;\n const sqlFullTableName = sql.identifier(schema.name, table.name);\n function makeField(isConnection) {\n const fieldName = isConnection\n ? inflection.allRows(table)\n : inflection.allRowsSimple(table);\n memo[fieldName] = fieldWithHooks(\n fieldName,\n ({ getDataFromParsedResolveInfoFragment }) => {\n return {\n description: build.wrapDescription(\n isConnection\n ? `Reads and enables pagination through a set of \\`${tableTypeName}\\`.`\n : `Reads a set of \\`${tableTypeName}\\`.`,\n \"field\"\n ),\n type: isConnection\n ? ConnectionType\n : new GraphQLList(new GraphQLNonNull(TableType)),\n args: {},\n async resolve(parent, args, resolveContext, resolveInfo) {\n const { pgClient } = resolveContext;\n const parsedResolveInfoFragment =\n parseResolveInfo(resolveInfo);\n parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin\n const resolveData = getDataFromParsedResolveInfoFragment(\n parsedResolveInfoFragment,\n resolveInfo.returnType\n );\n let checkerGenerator;\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n {\n useAsterisk: table.canUseAsterisk,\n withPaginationAsFields: isConnection,\n },\n queryBuilder => {\n if (subscriptions) {\n queryBuilder.makeLiveCollection(\n table,\n _checkerGenerator => {\n checkerGenerator = _checkerGenerator;\n }\n );\n }\n if (primaryKeys) {\n if (subscriptions && !isConnection) {\n queryBuilder.selectIdentifiers(table);\n }\n queryBuilder.beforeLock(\"orderBy\", () => {\n if (!queryBuilder.isOrderUnique(false)) {\n // Order by PK if no order specified\n queryBuilder.data.cursorPrefix = [\n \"primary_key_asc\",\n ];\n primaryKeys.forEach(key => {\n queryBuilder.orderBy(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n key.name\n )}`,\n true\n );\n });\n queryBuilder.setOrderIsUnique();\n }\n });\n } else if (isView(table) && !!uniqueIdAttribute) {\n queryBuilder.beforeLock(\"orderBy\", () => {\n if (!queryBuilder.isOrderUnique(false)) {\n queryBuilder.data.cursorPrefix = [\n \"view_unique_key_asc\",\n ];\n queryBuilder.orderBy(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n uniqueIdAttribute.name\n )}`,\n true\n );\n queryBuilder.setOrderIsUnique();\n }\n });\n }\n },\n resolveContext,\n resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const result = await pgPrepareAndRun(\n pgClient,\n text,\n values\n );\n\n const liveCollection =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveCollection;\n if (subscriptions && liveCollection && checkerGenerator) {\n const checker = checkerGenerator();\n liveCollection(\"pg\", table, checker);\n }\n\n if (isConnection) {\n const {\n rows: [row],\n } = result;\n return addStartEndCursor(row);\n } else {\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n if (\n subscriptions &&\n !isConnection &&\n primaryKeys &&\n liveRecord\n ) {\n result.rows.forEach(\n row =>\n row && liveRecord(\"pg\", table, row.__identifiers)\n );\n }\n return result.rows;\n }\n },\n };\n },\n {\n isPgFieldConnection: isConnection,\n isPgFieldSimpleCollection: !isConnection,\n pgFieldIntrospection: table,\n }\n );\n }\n const simpleCollections =\n table.tags.simpleCollections || pgSimpleCollections;\n const hasConnections = simpleCollections !== \"only\";\n const hasSimpleCollections =\n simpleCollections === \"only\" || simpleCollections === \"both\";\n if (TableType && ConnectionType && hasConnections) {\n makeField(true);\n }\n if (TableType && hasSimpleCollections) {\n makeField(false);\n }\n return memo;\n }, {}),\n `Adding 'all*' relations to root Query`\n );\n },\n [\"PgAllRows\"],\n [],\n [\"PgTables\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAkC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAEHG,SAAS,GAAxB,eAAeA,SAASA,CACtCC,OAAO,EACP;EAAEC,eAAe;EAAEC,mBAAmB;EAAEC;AAAc,CAAC,EACvD;EACAH,OAAO,CAACI,IAAI,CACV,0BAA0B,EAC1B,CAACC,MAAM,EAAEC,KAAK,EAAEC,OAAO,KAAK;IAC1B,MAAM;MACJC,gBAAgB;MAChBC,MAAM;MACNC,aAAa;MACbC,+BAA+B;MAC/BC,KAAK,EAAEC,GAAG;MACVC,4BAA4B,EAAEC,0BAA0B;MACxDC,UAAU;MACVC,OAAO,EAAE;QAAEC,WAAW;QAAEC;MAAe,CAAC;MACxCC,sBAAsB,EAAEC,oBAAoB;MAC5CC,mBAAmB,EAAEC,iBAAiB;MACtCC,MAAM,EAAEC,IAAI;MACZC;IACF,CAAC,GAAGpB,KAAK;IACT,MAAM;MACJqB,cAAc;MACdC,KAAK,EAAE;QAAEC;MAAY;IACvB,CAAC,GAAGtB,OAAO;IACX,IAAI,CAACsB,WAAW,EAAE;MAChB,OAAOxB,MAAM;IACf;IACA,OAAOI,MAAM,CACXJ,MAAM,EACNU,0BAA0B,CAACe,KAAK,CAACC,MAAM,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAK;MACvD;MACA,I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,CAAC;QACH,CAAC,EACD;UACEI,mBAAmB,EAAEhD,YAAY;UACjCiD,yBAAyB,EAAE,CAACjD,YAAY;UACxCkD,oBAAoB,EAAEhF;QACxB,CACF,CAAC;MACH;MACA,MAAMiF,iBAAiB,GACrBjF,KAAK,CAACmB,IAAI,CAAC8D,iBAAiB,IAAIhH,mBAAmB;MACrD,MAAMiH,cAAc,GAAGD,iBAAiB,KAAK,MAAM;MACnD,MAAME,oBAAoB,GACxBF,iBAAiB,KAAK,MAAM,IAAIA,iBAAiB,KAAK,MAAM;MAC9D,IAAI9E,SAAS,IAAIK,cAAc,IAAI0E,cAAc,EAAE;QACjDrD,SAAS,CAAC,IAAI,CAAC;MACjB;MACA,IAAI1B,SAAS,IAAIgF,oBAAoB,EAAE;QACrCtD,SAAS,CAAC,KAAK,CAAC;MAClB;MACA,OAAO9B,IAAI;IACb,CAAC,EAAE,CAAC,CAAC,CAAC,EACL,uCACH,CAAC;EACH,CAAC,EACD,CAAC,WAAW,CAAC,EACb,EAAE,EACF,CAAC,UAAU,CACb,CAAC;AACH,CAAC;AAAAqF,OAAA,CAAAvH,OAAA,GAAAC,SAAA"}
|
|
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
const debug = (0, _debug.default)("graphile-build-pg");
|
|
13
10
|
const OMIT = 0;
|
|
14
11
|
const DEPRECATED = 1;
|
|
15
12
|
const ONLY = 2;
|
|
16
|
-
|
|
17
13
|
var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
18
14
|
pgLegacyRelations,
|
|
19
15
|
pgSimpleCollections,
|
|
@@ -51,61 +47,47 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
51
47
|
fieldWithHooks,
|
|
52
48
|
Self
|
|
53
49
|
} = context;
|
|
54
|
-
|
|
55
50
|
if (!isPgRowType || !foreignTable || foreignTable.kind !== "class") {
|
|
56
51
|
return fields;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
}
|
|
53
|
+
// This is a relation in which WE are foreign
|
|
60
54
|
const foreignKeyConstraints = foreignTable.foreignConstraints.filter(con => con.type === "f");
|
|
61
55
|
const foreignTableTypeName = inflection.tableType(foreignTable);
|
|
62
56
|
const gqlForeignTableType = pgGetGqlTypeByTypeIdAndModifier(foreignTable.type.id, null);
|
|
63
|
-
|
|
64
57
|
if (!gqlForeignTableType) {
|
|
65
58
|
debug(`Could not determine type for foreign table with id ${foreignTable.type.id}`);
|
|
66
59
|
return fields;
|
|
67
60
|
}
|
|
68
|
-
|
|
69
61
|
return extend(fields, foreignKeyConstraints.reduce((memo, constraint) => {
|
|
70
62
|
if (omit(constraint, "read")) {
|
|
71
63
|
return memo;
|
|
72
64
|
}
|
|
73
|
-
|
|
74
65
|
const table = introspectionResultsByKind.classById[constraint.classId];
|
|
75
|
-
|
|
76
66
|
if (!table) {
|
|
77
67
|
throw new Error(`Could not find the table that referenced us (constraint: ${constraint.name})`);
|
|
78
68
|
}
|
|
79
|
-
|
|
80
69
|
if (!table.isSelectable) {
|
|
81
70
|
// Could be a composite type
|
|
82
71
|
return memo;
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
const tableTypeName = inflection.tableType(table);
|
|
86
74
|
const gqlTableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);
|
|
87
|
-
|
|
88
75
|
if (!gqlTableType) {
|
|
89
76
|
debug(`Could not determine type for table with id ${constraint.classId}`);
|
|
90
77
|
return memo;
|
|
91
78
|
}
|
|
92
|
-
|
|
93
79
|
const schema = table.namespace;
|
|
94
80
|
const keys = constraint.keyAttributes;
|
|
95
81
|
const foreignKeys = constraint.foreignKeyAttributes;
|
|
96
|
-
|
|
97
82
|
if (!keys.every(_ => _) || !foreignKeys.every(_ => _)) {
|
|
98
83
|
throw new Error("Could not find key columns!");
|
|
99
84
|
}
|
|
100
|
-
|
|
101
85
|
if (keys.some(key => omit(key, "read"))) {
|
|
102
86
|
return memo;
|
|
103
87
|
}
|
|
104
|
-
|
|
105
88
|
if (foreignKeys.some(key => omit(key, "read"))) {
|
|
106
89
|
return memo;
|
|
107
90
|
}
|
|
108
|
-
|
|
109
91
|
const isUnique = !!table.constraints.find(c => (c.type === "p" || c.type === "u") && c.keyAttributeNums.length === keys.length && c.keyAttributeNums.every((n, i) => keys[i].num === n));
|
|
110
92
|
const isDeprecated = isUnique && legacyRelationMode === DEPRECATED;
|
|
111
93
|
const singleRelationFieldName = isUnique ? inflection.singleRelationByKeysBackwards(keys, table, foreignTable, constraint) : null;
|
|
@@ -113,7 +95,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
113
95
|
const primaryKeys = primaryKeyConstraint && primaryKeyConstraint.keyAttributes;
|
|
114
96
|
const shouldAddSingleRelation = isUnique && legacyRelationMode !== ONLY;
|
|
115
97
|
const shouldAddManyRelation = !isUnique || legacyRelationMode === DEPRECATED || legacyRelationMode === ONLY;
|
|
116
|
-
|
|
117
98
|
if (shouldAddSingleRelation && !omit(table, "read") && singleRelationFieldName) {
|
|
118
99
|
memo = extend(memo, {
|
|
119
100
|
[singleRelationFieldName]: fieldWithHooks(singleRelationFieldName, ({
|
|
@@ -136,7 +117,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
136
117
|
withPagination: false
|
|
137
118
|
}, innerQueryBuilder => {
|
|
138
119
|
innerQueryBuilder.parentQueryBuilder = queryBuilder;
|
|
139
|
-
|
|
140
120
|
if (subscriptions && table.primaryKeyConstraint) {
|
|
141
121
|
innerQueryBuilder.selectIdentifiers(table);
|
|
142
122
|
innerQueryBuilder.makeLiveCollection(table);
|
|
@@ -147,7 +127,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
147
127
|
return memo;
|
|
148
128
|
}, {}));
|
|
149
129
|
}
|
|
150
|
-
|
|
151
130
|
keys.forEach((key, i) => {
|
|
152
131
|
innerQueryBuilder.where(sql.fragment`${tableAlias}.${sql.identifier(key.name)} = ${foreignTableAlias}.${sql.identifier(foreignKeys[i].name)}`);
|
|
153
132
|
});
|
|
@@ -167,7 +146,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
167
146
|
const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
|
|
168
147
|
const liveCollection = resolveInfo.rootValue && resolveInfo.rootValue.liveCollection;
|
|
169
148
|
const liveConditions = resolveInfo.rootValue && resolveInfo.rootValue.liveConditions;
|
|
170
|
-
|
|
171
149
|
if (subscriptions && liveCollection && liveConditions && data.__live) {
|
|
172
150
|
const {
|
|
173
151
|
__id,
|
|
@@ -177,11 +155,9 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
177
155
|
const checker = condition(rest);
|
|
178
156
|
liveCollection("pg", table, checker);
|
|
179
157
|
}
|
|
180
|
-
|
|
181
158
|
if (record && liveRecord) {
|
|
182
159
|
liveRecord("pg", table, record.__identifiers);
|
|
183
160
|
}
|
|
184
|
-
|
|
185
161
|
return record;
|
|
186
162
|
}
|
|
187
163
|
};
|
|
@@ -193,7 +169,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
193
169
|
foreignSingleFieldName: "newNameHere"
|
|
194
170
|
})}`);
|
|
195
171
|
}
|
|
196
|
-
|
|
197
172
|
function makeFields(isConnection) {
|
|
198
173
|
const manyRelationFieldName = isConnection ? inflection.manyRelationByKeys(keys, table, foreignTable, constraint) : inflection.manyRelationByKeysSimple(keys, table, foreignTable, constraint);
|
|
199
174
|
memo = extend(memo, {
|
|
@@ -217,7 +192,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
217
192
|
const foreignTableAlias = queryBuilder.getTableAlias();
|
|
218
193
|
const query = queryFromResolveData(sqlFrom, tableAlias, resolveData, queryOptions, innerQueryBuilder => {
|
|
219
194
|
innerQueryBuilder.parentQueryBuilder = queryBuilder;
|
|
220
|
-
|
|
221
195
|
if (subscriptions) {
|
|
222
196
|
innerQueryBuilder.makeLiveCollection(table);
|
|
223
197
|
innerQueryBuilder.addLiveCondition(data => record => {
|
|
@@ -227,12 +201,10 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
227
201
|
return memo;
|
|
228
202
|
}, {}));
|
|
229
203
|
}
|
|
230
|
-
|
|
231
204
|
if (primaryKeys) {
|
|
232
205
|
if (subscriptions && !isConnection && table.primaryKeyConstraint) {
|
|
233
206
|
innerQueryBuilder.selectIdentifiers(table);
|
|
234
207
|
}
|
|
235
|
-
|
|
236
208
|
innerQueryBuilder.beforeLock("orderBy", () => {
|
|
237
209
|
// append order by primary key to the list of orders
|
|
238
210
|
if (!innerQueryBuilder.isOrderUnique(false)) {
|
|
@@ -244,7 +216,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
244
216
|
}
|
|
245
217
|
});
|
|
246
218
|
}
|
|
247
|
-
|
|
248
219
|
keys.forEach((key, i) => {
|
|
249
220
|
innerQueryBuilder.where(sql.fragment`${tableAlias}.${sql.identifier(key.name)} = ${foreignTableAlias}.${sql.identifier(foreignKeys[i].name)}`);
|
|
250
221
|
});
|
|
@@ -264,7 +235,6 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
264
235
|
const safeAlias = getSafeAliasFromResolveInfo(resolveInfo);
|
|
265
236
|
const liveCollection = resolveInfo.rootValue && resolveInfo.rootValue.liveCollection;
|
|
266
237
|
const liveConditions = resolveInfo.rootValue && resolveInfo.rootValue.liveConditions;
|
|
267
|
-
|
|
268
238
|
if (subscriptions && liveCollection && liveConditions && data.__live) {
|
|
269
239
|
const {
|
|
270
240
|
__id,
|
|
@@ -274,23 +244,19 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
274
244
|
const checker = condition(rest);
|
|
275
245
|
liveCollection("pg", table, checker);
|
|
276
246
|
}
|
|
277
|
-
|
|
278
247
|
if (isConnection) {
|
|
279
248
|
return addStartEndCursor(data[safeAlias]);
|
|
280
249
|
} else {
|
|
281
250
|
const records = data[safeAlias];
|
|
282
251
|
const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
|
|
283
|
-
|
|
284
252
|
if (primaryKeys && subscriptions && liveRecord) {
|
|
285
253
|
records.forEach(r => r && r.__identifiers && liveRecord("pg", table, r.__identifiers));
|
|
286
254
|
}
|
|
287
|
-
|
|
288
255
|
return records;
|
|
289
256
|
}
|
|
290
257
|
},
|
|
291
258
|
...(isDeprecated ? {
|
|
292
259
|
deprecationReason: singleRelationFieldName ? `Please use ${singleRelationFieldName} instead` : `Please use singular instead` // This should never happen
|
|
293
|
-
|
|
294
260
|
} : null)
|
|
295
261
|
};
|
|
296
262
|
}, {
|
|
@@ -303,26 +269,21 @@ var PgBackwardRelationPlugin = function PgBackwardRelationPlugin(builder, {
|
|
|
303
269
|
[isConnection ? "foreignFieldName" : "foreignSimpleFieldName"]: "newNameHere"
|
|
304
270
|
})}`);
|
|
305
271
|
}
|
|
306
|
-
|
|
307
272
|
if (shouldAddManyRelation && !omit(table, "many") && !omit(constraint, "many")) {
|
|
308
273
|
const simpleCollections = constraint.tags.simpleCollections || table.tags.simpleCollections || pgSimpleCollections;
|
|
309
274
|
const hasConnections = simpleCollections !== "only";
|
|
310
275
|
const hasSimpleCollections = simpleCollections === "only" || simpleCollections === "both";
|
|
311
|
-
|
|
312
276
|
if (hasConnections) {
|
|
313
277
|
makeFields(true);
|
|
314
278
|
}
|
|
315
|
-
|
|
316
279
|
if (hasSimpleCollections && !isUnique // if unique, use the singular instead
|
|
317
280
|
) {
|
|
318
281
|
makeFields(false);
|
|
319
282
|
}
|
|
320
283
|
}
|
|
321
|
-
|
|
322
284
|
return memo;
|
|
323
285
|
}, {}), `Adding backward relations for ${Self.name}`);
|
|
324
286
|
}, ["PgBackwardRelation"]);
|
|
325
287
|
};
|
|
326
|
-
|
|
327
288
|
exports.default = PgBackwardRelationPlugin;
|
|
328
289
|
//# sourceMappingURL=PgBackwardRelationPlugin.js.map
|