graphile-build-pg
Advanced tools
Comparing version 0.1.0-alpha.31 to 0.1.0-alpha.32
@@ -53,2 +53,5 @@ "use strict"; | ||
enumName(value) { | ||
if (value === "") { | ||
return "_EMPTY_"; | ||
} | ||
return value; | ||
@@ -108,16 +111,23 @@ }, | ||
}, | ||
updateByKeys(detailedKeys, table, schema) { | ||
rowByUniqueKeys(detailedKeys, table, schema) { | ||
var _this2 = this; | ||
return camelCase(`update-${this.tableName(table, schema)}-by-${detailedKeys.map(function (key) { | ||
return camelCase(`${this.tableName(table, schema)}-by-${detailedKeys.map(function (key) { | ||
return _this2.column(key.column, key.table, key.schema); | ||
}).join("-and-")}`); | ||
}, | ||
deleteByKeys(detailedKeys, table, schema) { | ||
updateByKeys(detailedKeys, table, schema) { | ||
var _this3 = this; | ||
return camelCase(`delete-${this.tableName(table, schema)}-by-${detailedKeys.map(function (key) { | ||
return camelCase(`update-${this.tableName(table, schema)}-by-${detailedKeys.map(function (key) { | ||
return _this3.column(key.column, key.table, key.schema); | ||
}).join("-and-")}`); | ||
}, | ||
deleteByKeys(detailedKeys, table, schema) { | ||
var _this4 = this; | ||
return camelCase(`delete-${this.tableName(table, schema)}-by-${detailedKeys.map(function (key) { | ||
return _this4.column(key.column, key.table, key.schema); | ||
}).join("-and-")}`); | ||
}, | ||
updateNode(name, _schema) { | ||
@@ -130,13 +140,13 @@ return camelCase(`update-${singularize(name)}`); | ||
updateByKeysInputType(detailedKeys, name, _schema) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
return upperCamelCase(`update-${singularize(name)}-by-${detailedKeys.map(function (key) { | ||
return _this4.column(key.column, key.table, key.schema); | ||
return _this5.column(key.column, key.table, key.schema); | ||
}).join("-and-")}-input`); | ||
}, | ||
deleteByKeysInputType(detailedKeys, name, _schema) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
return upperCamelCase(`delete-${singularize(name)}-by-${detailedKeys.map(function (key) { | ||
return _this5.column(key.column, key.table, key.schema); | ||
return _this6.column(key.column, key.table, key.schema); | ||
}).join("-and-")}-input`); | ||
@@ -151,6 +161,6 @@ }, | ||
manyRelationByKeys(detailedKeys, table, schema) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
return camelCase(`${this.pluralize(this.tableName(table, schema))}-by-${detailedKeys.map(function (key) { | ||
return _this6.column(key.column, key.table, key.schema); | ||
return _this7.column(key.column, key.table, key.schema); | ||
}).join("-and-")}`); | ||
@@ -157,0 +167,0 @@ }, |
@@ -305,3 +305,3 @@ "use strict"; | ||
}, scope)); | ||
ReturnType = new GraphQLNonNull(PayloadType); | ||
ReturnType = PayloadType; | ||
var InputType = newWithHooks(GraphQLInputObjectType, { | ||
@@ -363,3 +363,3 @@ name: inflection.functionInputType(proc.name, proc.namespace.name), | ||
if (!isMutation) { | ||
_context2.next = 15; | ||
_context2.next = 27; | ||
break; | ||
@@ -373,11 +373,33 @@ } | ||
isPgClass = !returnFirstValueAsValue || returnTypeTable || false; | ||
_context2.next = 12; | ||
_context2.prev = 10; | ||
_context2.next = 13; | ||
return pgClient.query("SAVEPOINT graphql_mutation"); | ||
case 13: | ||
_context2.next = 15; | ||
return (0, _viaTemporaryTable2.default)(pgClient, isVoid ? null : sql.identifier(_returnType.namespaceName, _returnType.name), sql.query`select ${isPgClass ? sql.query`${intermediateIdentifier}.*` : sql.query`${intermediateIdentifier}.${intermediateIdentifier} as ${functionAlias}`} from ${sqlMutationQuery} ${intermediateIdentifier}`, functionAlias, query, isPgClass); | ||
case 12: | ||
case 15: | ||
queryResult = _context2.sent; | ||
_context2.next = 21; | ||
_context2.next = 18; | ||
return pgClient.query("RELEASE SAVEPOINT graphql_mutation"); | ||
case 18: | ||
_context2.next = 25; | ||
break; | ||
case 15: | ||
case 20: | ||
_context2.prev = 20; | ||
_context2.t0 = _context2["catch"](10); | ||
_context2.next = 24; | ||
return pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation"); | ||
case 24: | ||
throw _context2.t0; | ||
case 25: | ||
_context2.next = 33; | ||
break; | ||
case 27: | ||
_query = makeQuery(parsedResolveInfoFragment, resolveInfo.returnType, sqlMutationQuery, functionAlias); | ||
@@ -387,9 +409,9 @@ _sql$compile = sql.compile(_query), text = _sql$compile.text, values = _sql$compile.values; | ||
if (debugSql.enabled) debugSql(text); | ||
_context2.next = 20; | ||
_context2.next = 32; | ||
return pgClient.query(text, values); | ||
case 20: | ||
case 32: | ||
queryResult = _context2.sent; | ||
case 21: | ||
case 33: | ||
_queryResult = queryResult, rows = _queryResult.rows; | ||
@@ -424,3 +446,3 @@ _rows = (0, _slicedToArray3.default)(rows, 1), row = _rows[0]; | ||
if (!isMutation) { | ||
_context2.next = 28; | ||
_context2.next = 40; | ||
break; | ||
@@ -434,6 +456,6 @@ } | ||
case 28: | ||
case 40: | ||
return _context2.abrupt("return", result); | ||
case 29: | ||
case 41: | ||
case "end": | ||
@@ -443,3 +465,3 @@ return _context2.stop(); | ||
} | ||
}, _callee, _this); | ||
}, _callee, _this, [[10, 20]]); | ||
})); | ||
@@ -446,0 +468,0 @@ |
@@ -11,6 +11,2 @@ "use strict"; | ||
var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray"); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _symbol = require("babel-runtime/core-js/symbol"); | ||
@@ -146,5 +142,3 @@ | ||
var pgClient = _ref7.pgClient; | ||
var parsedResolveInfoFragment, resolveData, insertedRowAlias, query, sqlColumns, sqlValues, inputData, mutationQuery, _ref8, _ref8$rows, row; | ||
var parsedResolveInfoFragment, resolveData, insertedRowAlias, query, sqlColumns, sqlValues, inputData, mutationQuery, row, result; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -167,3 +161,3 @@ while (1) { | ||
var val = inputData[fieldName]; | ||
if (val != null) { | ||
if (Object.prototype.hasOwnProperty.call(inputData, fieldName)) { | ||
sqlColumns.push(sql.identifier(attr.name)); | ||
@@ -178,9 +172,32 @@ sqlValues.push(gql2pg(val, attr.type)); | ||
) values(${sql.join(sqlValues, ", ")})` : sql.fragment`default values`} returning *`; | ||
_context.next = 11; | ||
row = void 0; | ||
_context.prev = 10; | ||
_context.next = 13; | ||
return pgClient.query("SAVEPOINT graphql_mutation"); | ||
case 13: | ||
_context.next = 15; | ||
return (0, _viaTemporaryTable2.default)(pgClient, sql.identifier(table.namespace.name, table.name), mutationQuery, insertedRowAlias, query); | ||
case 11: | ||
_ref8 = _context.sent; | ||
_ref8$rows = (0, _slicedToArray3.default)(_ref8.rows, 1); | ||
row = _ref8$rows[0]; | ||
case 15: | ||
result = _context.sent; | ||
row = result.rows[0]; | ||
_context.next = 19; | ||
return pgClient.query("RELEASE SAVEPOINT graphql_mutation"); | ||
case 19: | ||
_context.next = 26; | ||
break; | ||
case 21: | ||
_context.prev = 21; | ||
_context.t0 = _context["catch"](10); | ||
_context.next = 25; | ||
return pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation"); | ||
case 25: | ||
throw _context.t0; | ||
case 26: | ||
return _context.abrupt("return", { | ||
@@ -191,3 +208,3 @@ clientMutationId: input.clientMutationId, | ||
case 15: | ||
case 27: | ||
case "end": | ||
@@ -197,3 +214,3 @@ return _context.stop(); | ||
} | ||
}, _callee, _this); | ||
}, _callee, _this, [[10, 21]]); | ||
}))(); | ||
@@ -200,0 +217,0 @@ } |
@@ -23,6 +23,2 @@ "use strict"; | ||
var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray"); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _symbol = require("babel-runtime/core-js/symbol"); | ||
@@ -111,4 +107,3 @@ | ||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, condition) { | ||
var parsedResolveInfoFragment, resolveData, sqlTypeIdentifier, sqlMutationQuery, sqlColumns, sqlValues, inputData, modifiedRowAlias, query, _ref6, _ref6$rows, row; | ||
var parsedResolveInfoFragment, resolveData, sqlTypeIdentifier, sqlMutationQuery, sqlColumns, sqlValues, inputData, modifiedRowAlias, query, row, result; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -170,12 +165,34 @@ while (1) { | ||
query = (0, _queryFromResolveData2.default)(modifiedRowAlias, modifiedRowAlias, resolveData, {}); | ||
_context.next = 19; | ||
row = void 0; | ||
_context.prev = 18; | ||
_context.next = 21; | ||
return pgClient.query("SAVEPOINT graphql_mutation"); | ||
case 21: | ||
_context.next = 23; | ||
return (0, _viaTemporaryTable2.default)(pgClient, sqlTypeIdentifier, sqlMutationQuery, modifiedRowAlias, query); | ||
case 19: | ||
_ref6 = _context.sent; | ||
_ref6$rows = (0, _slicedToArray3.default)(_ref6.rows, 1); | ||
row = _ref6$rows[0]; | ||
case 23: | ||
result = _context.sent; | ||
row = result.rows[0]; | ||
_context.next = 27; | ||
return pgClient.query("RELEASE SAVEPOINT graphql_mutation"); | ||
case 27: | ||
_context.next = 34; | ||
break; | ||
case 29: | ||
_context.prev = 29; | ||
_context.t0 = _context["catch"](18); | ||
_context.next = 33; | ||
return pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation"); | ||
case 33: | ||
throw _context.t0; | ||
case 34: | ||
if (row) { | ||
_context.next = 24; | ||
_context.next = 36; | ||
break; | ||
@@ -186,3 +203,3 @@ } | ||
case 24: | ||
case 36: | ||
return _context.abrupt("return", { | ||
@@ -193,3 +210,3 @@ clientMutationId: input.clientMutationId, | ||
case 25: | ||
case 37: | ||
case "end": | ||
@@ -199,3 +216,3 @@ return _context.stop(); | ||
} | ||
}, _callee, this); | ||
}, _callee, this, [[18, 29]]); | ||
})); | ||
@@ -227,4 +244,4 @@ | ||
description: `The output of our ${mode} \`${tableTypeName}\` mutation.`, | ||
fields: function fields(_ref7) { | ||
var recurseDataGeneratorsForField = _ref7.recurseDataGeneratorsForField; | ||
fields: function fields(_ref6) { | ||
var recurseDataGeneratorsForField = _ref6.recurseDataGeneratorsForField; | ||
@@ -304,4 +321,4 @@ var tableName = inflection.tableName(table.name, table.namespace.name); | ||
memo[fieldName] = fieldWithHooks(fieldName, function (_ref8) { | ||
var getDataFromParsedResolveInfoFragment = _ref8.getDataFromParsedResolveInfoFragment; | ||
memo[fieldName] = fieldWithHooks(fieldName, function (_ref7) { | ||
var getDataFromParsedResolveInfoFragment = _ref7.getDataFromParsedResolveInfoFragment; | ||
@@ -316,8 +333,8 @@ return { | ||
}, | ||
resolve(parent, _ref9, _ref10, resolveInfo) { | ||
resolve(parent, _ref8, _ref9, resolveInfo) { | ||
var _this = this; | ||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
var input = _ref9.input; | ||
var pgClient = _ref10.pgClient; | ||
var input = _ref8.input; | ||
var pgClient = _ref9.pgClient; | ||
@@ -422,4 +439,4 @@ var nodeId, _JSON$parse, _JSON$parse2, alias, identifiers, NodeTypeByAlias; | ||
memo[fieldName] = fieldWithHooks(fieldName, function (_ref11) { | ||
var getDataFromParsedResolveInfoFragment = _ref11.getDataFromParsedResolveInfoFragment; | ||
memo[fieldName] = fieldWithHooks(fieldName, function (_ref10) { | ||
var getDataFromParsedResolveInfoFragment = _ref10.getDataFromParsedResolveInfoFragment; | ||
@@ -434,8 +451,8 @@ return { | ||
}, | ||
resolve(parent, _ref12, _ref13, resolveInfo) { | ||
resolve(parent, _ref11, _ref12, resolveInfo) { | ||
var _this2 = this; | ||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() { | ||
var input = _ref12.input; | ||
var pgClient = _ref13.pgClient; | ||
var input = _ref11.input; | ||
var pgClient = _ref12.pgClient; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
@@ -442,0 +459,0 @@ while (1) { |
@@ -87,3 +87,3 @@ "use strict"; | ||
}); | ||
var fieldName = inflection.singleRelationByKeys(simpleKeys, table.name, table.namespace.name); | ||
var fieldName = inflection.rowByUniqueKeys(simpleKeys, table.name, table.namespace.name); | ||
memo[fieldName] = fieldWithHooks(fieldName, function (_ref5) { | ||
@@ -90,0 +90,0 @@ var getDataFromParsedResolveInfoFragment = _ref5.getDataFromParsedResolveInfoFragment; |
@@ -388,2 +388,12 @@ "use strict"; | ||
var enforceGqlTypeByPgType = function enforceGqlTypeByPgType(type) { | ||
try { | ||
return reallyEnforceGqlTypeByPgType(type); | ||
} catch (e) { | ||
var error = new Error(`Error occurred when processing type '${type.namespaceName}.${type.name}' (type=${type.type}): ${e.message}`); | ||
// $FlowFixMe | ||
error.originalError = e; | ||
throw error; | ||
} | ||
}; | ||
var reallyEnforceGqlTypeByPgType = function reallyEnforceGqlTypeByPgType(type) { | ||
// Explicit overrides | ||
@@ -390,0 +400,0 @@ if (!gqlTypeByTypeId[type.id]) { |
@@ -49,2 +49,5 @@ "use strict"; | ||
enumName(value) { | ||
if (value === "") { | ||
return "_EMPTY_"; | ||
} | ||
return value; | ||
@@ -100,2 +103,5 @@ }, | ||
}, | ||
rowByUniqueKeys(detailedKeys, table, schema) { | ||
return camelCase(`${this.tableName(table, schema)}-by-${detailedKeys.map(key => this.column(key.column, key.table, key.schema)).join("-and-")}`); | ||
}, | ||
updateByKeys(detailedKeys, table, schema) { | ||
@@ -102,0 +108,0 @@ return camelCase(`update-${this.tableName(table, schema)}-by-${detailedKeys.map(key => this.column(key.column, key.table, key.schema)).join("-and-")}`); |
@@ -275,3 +275,3 @@ "use strict"; | ||
}, scope)); | ||
ReturnType = new GraphQLNonNull(PayloadType); | ||
ReturnType = PayloadType; | ||
const InputType = newWithHooks(GraphQLInputObjectType, { | ||
@@ -327,3 +327,10 @@ name: inflection.functionInputType(proc.name, proc.namespace.name), | ||
const isPgClass = !returnFirstValueAsValue || returnTypeTable || false; | ||
queryResult = await (0, _viaTemporaryTable2.default)(pgClient, isVoid ? null : sql.identifier(returnType.namespaceName, returnType.name), sql.query`select ${isPgClass ? sql.query`${intermediateIdentifier}.*` : sql.query`${intermediateIdentifier}.${intermediateIdentifier} as ${functionAlias}`} from ${sqlMutationQuery} ${intermediateIdentifier}`, functionAlias, query, isPgClass); | ||
try { | ||
await pgClient.query("SAVEPOINT graphql_mutation"); | ||
queryResult = await (0, _viaTemporaryTable2.default)(pgClient, isVoid ? null : sql.identifier(returnType.namespaceName, returnType.name), sql.query`select ${isPgClass ? sql.query`${intermediateIdentifier}.*` : sql.query`${intermediateIdentifier}.${intermediateIdentifier} as ${functionAlias}`} from ${sqlMutationQuery} ${intermediateIdentifier}`, functionAlias, query, isPgClass); | ||
await pgClient.query("RELEASE SAVEPOINT graphql_mutation"); | ||
} catch (e) { | ||
await pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation"); | ||
throw e; | ||
} | ||
} else { | ||
@@ -330,0 +337,0 @@ const query = makeQuery(parsedResolveInfoFragment, resolveInfo.returnType, sqlMutationQuery, functionAlias); |
@@ -124,3 +124,3 @@ "use strict"; | ||
const val = inputData[fieldName]; | ||
if (val != null) { | ||
if (Object.prototype.hasOwnProperty.call(inputData, fieldName)) { | ||
sqlColumns.push(sql.identifier(attr.name)); | ||
@@ -136,3 +136,12 @@ sqlValues.push(gql2pg(val, attr.type)); | ||
const { rows: [row] } = await (0, _viaTemporaryTable2.default)(pgClient, sql.identifier(table.namespace.name, table.name), mutationQuery, insertedRowAlias, query); | ||
let row; | ||
try { | ||
await pgClient.query("SAVEPOINT graphql_mutation"); | ||
const result = await (0, _viaTemporaryTable2.default)(pgClient, sql.identifier(table.namespace.name, table.name), mutationQuery, insertedRowAlias, query); | ||
row = result.rows[0]; | ||
await pgClient.query("RELEASE SAVEPOINT graphql_mutation"); | ||
} catch (e) { | ||
await pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation"); | ||
throw e; | ||
} | ||
return { | ||
@@ -139,0 +148,0 @@ clientMutationId: input.clientMutationId, |
@@ -105,3 +105,12 @@ "use strict"; | ||
const query = (0, _queryFromResolveData2.default)(modifiedRowAlias, modifiedRowAlias, resolveData, {}); | ||
const { rows: [row] } = await (0, _viaTemporaryTable2.default)(pgClient, sqlTypeIdentifier, sqlMutationQuery, modifiedRowAlias, query); | ||
let row; | ||
try { | ||
await pgClient.query("SAVEPOINT graphql_mutation"); | ||
const result = await (0, _viaTemporaryTable2.default)(pgClient, sqlTypeIdentifier, sqlMutationQuery, modifiedRowAlias, query); | ||
row = result.rows[0]; | ||
await pgClient.query("RELEASE SAVEPOINT graphql_mutation"); | ||
} catch (e) { | ||
await pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation"); | ||
throw e; | ||
} | ||
if (!row) { | ||
@@ -108,0 +117,0 @@ throw new Error(`No values were ${mode}d in collection '${(0, _pluralize2.default)(table.name)}' because no values were found.`); |
@@ -49,3 +49,3 @@ "use strict"; | ||
})); | ||
const fieldName = inflection.singleRelationByKeys(simpleKeys, table.name, table.namespace.name); | ||
const fieldName = inflection.rowByUniqueKeys(simpleKeys, table.name, table.namespace.name); | ||
memo[fieldName] = fieldWithHooks(fieldName, ({ getDataFromParsedResolveInfoFragment }) => { | ||
@@ -52,0 +52,0 @@ return { |
@@ -328,2 +328,12 @@ "use strict"; | ||
const enforceGqlTypeByPgType = type => { | ||
try { | ||
return reallyEnforceGqlTypeByPgType(type); | ||
} catch (e) { | ||
const error = new Error(`Error occurred when processing type '${type.namespaceName}.${type.name}' (type=${type.type}): ${e.message}`); | ||
// $FlowFixMe | ||
error.originalError = e; | ||
throw error; | ||
} | ||
}; | ||
const reallyEnforceGqlTypeByPgType = type => { | ||
// Explicit overrides | ||
@@ -330,0 +340,0 @@ if (!gqlTypeByTypeId[type.id]) { |
{ | ||
"name": "graphile-build-pg", | ||
"version": "0.1.0-alpha.31", | ||
"version": "0.1.0-alpha.32", | ||
"description": "Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build", | ||
@@ -40,3 +40,3 @@ "main": "index.js", | ||
"debug": ">=2 <3", | ||
"graphile-build": "^0.1.0-alpha.27", | ||
"graphile-build": "^0.1.0-alpha.32", | ||
"graphql-iso-date": "^3.2.0", | ||
@@ -43,0 +43,0 @@ "graphql-type-json": "^0.1.4", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1361334
9470