Socket
Socket
Sign inDemoInstall

graphile-build-pg

Package Overview
Dependencies
Maintainers
1
Versions
208
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphile-build-pg - npm Package Compare versions

Comparing version 0.1.0-alpha.36 to 0.1.0-alpha.37

node7minus/plugins/PgColumnDeprecationPlugin.js

14

node7minus/index.js

@@ -6,3 +6,3 @@ "use strict";

});
exports.constantCase = exports.camelCase = exports.upperFirst = exports.PgMutationPayloadEdgePlugin = exports.PgMutationProceduresPlugin = exports.PgMutationUpdateDeletePlugin = exports.PgMutationCreatePlugin = exports.PgConnectionTotalCount = exports.PageInfoStartEndCursor = exports.PgScalarFunctionConnectionPlugin = exports.PgNodeAliasPostGraphQL = exports.PgRowNode = exports.PgOrderByPrimaryKeyPlugin = exports.PgOrderAllColumnsPlugin = exports.PgQueryProceduresPlugin = exports.PgComputedColumnsPlugin = exports.PgRowByUniqueConstraint = exports.PgBackwardRelationPlugin = exports.PgForwardRelationPlugin = exports.PgColumnsPlugin = exports.PgAllRows = exports.PgConnectionArgCondition = exports.PgConnectionArgOrderBy = exports.PgConnectionArgFirstLastBeforeAfter = exports.PgTablesPlugin = exports.PgJWTPlugin = exports.PgTypesPlugin = exports.PgIntrospectionPlugin = exports.PgBasicsPlugin = exports.inflections = exports.defaultPlugins = undefined;
exports.constantCase = exports.camelCase = exports.upperFirst = exports.PgMutationPayloadEdgePlugin = exports.PgMutationProceduresPlugin = exports.PgMutationUpdateDeletePlugin = exports.PgMutationCreatePlugin = exports.PgConnectionTotalCount = exports.PageInfoStartEndCursor = exports.PgScalarFunctionConnectionPlugin = exports.PgNodeAliasPostGraphQL = exports.PgRowNode = exports.PgOrderByPrimaryKeyPlugin = exports.PgOrderAllColumnsPlugin = exports.PgQueryProceduresPlugin = exports.PgComputedColumnsPlugin = exports.PgRowByUniqueConstraint = exports.PgBackwardRelationPlugin = exports.PgForwardRelationPlugin = exports.PgColumnDeprecationPlugin = exports.PgColumnsPlugin = exports.PgAllRows = exports.PgConnectionArgCondition = exports.PgConnectionArgOrderByDefaultValue = exports.PgConnectionArgOrderBy = exports.PgConnectionArgFirstLastBeforeAfter = exports.PgTablesPlugin = exports.PgJWTPlugin = exports.PgTypesPlugin = exports.PgIntrospectionPlugin = exports.PgBasicsPlugin = exports.inflections = exports.defaultPlugins = undefined;

@@ -58,2 +58,6 @@ var _utils = require("./utils");

var _PgConnectionArgOrderByDefaultValue = require("./plugins/PgConnectionArgOrderByDefaultValue");
var _PgConnectionArgOrderByDefaultValue2 = _interopRequireDefault(_PgConnectionArgOrderByDefaultValue);
var _PgConnectionArgCondition = require("./plugins/PgConnectionArgCondition");

@@ -71,2 +75,6 @@

var _PgColumnDeprecationPlugin = require("./plugins/PgColumnDeprecationPlugin");
var _PgColumnDeprecationPlugin2 = _interopRequireDefault(_PgColumnDeprecationPlugin);
var _PgForwardRelationPlugin = require("./plugins/PgForwardRelationPlugin");

@@ -144,3 +152,3 @@

var defaultPlugins = exports.defaultPlugins = [_PgBasicsPlugin2.default, _PgIntrospectionPlugin2.default, _PgTypesPlugin2.default, _PgJWTPlugin2.default, _PgTablesPlugin2.default, _PgConnectionArgFirstLastBeforeAfter2.default, _PgConnectionArgOrderBy2.default, _PgConnectionArgCondition2.default, _PgAllRows2.default, _PgColumnsPlugin2.default, _PgForwardRelationPlugin2.default, _PgBackwardRelationPlugin2.default, _PgRowByUniqueConstraint2.default, _PgComputedColumnsPlugin2.default, _PgQueryProceduresPlugin2.default, _PgOrderAllColumnsPlugin2.default, _PgOrderByPrimaryKeyPlugin2.default, _PgRowNode2.default, _PgNodeAliasPostGraphQL2.default, _PgScalarFunctionConnectionPlugin2.default, // For PostGraphQL compatibility
var defaultPlugins = exports.defaultPlugins = [_PgBasicsPlugin2.default, _PgIntrospectionPlugin2.default, _PgTypesPlugin2.default, _PgJWTPlugin2.default, _PgTablesPlugin2.default, _PgConnectionArgFirstLastBeforeAfter2.default, _PgConnectionArgOrderBy2.default, _PgConnectionArgOrderByDefaultValue2.default, _PgConnectionArgCondition2.default, _PgAllRows2.default, _PgColumnsPlugin2.default, _PgColumnDeprecationPlugin2.default, _PgForwardRelationPlugin2.default, _PgBackwardRelationPlugin2.default, _PgRowByUniqueConstraint2.default, _PgComputedColumnsPlugin2.default, _PgQueryProceduresPlugin2.default, _PgOrderAllColumnsPlugin2.default, _PgOrderByPrimaryKeyPlugin2.default, _PgRowNode2.default, _PgNodeAliasPostGraphQL2.default, _PgScalarFunctionConnectionPlugin2.default, // For PostGraphQL compatibility
_PageInfoStartEndCursor2.default, // For PostGraphQL compatibility

@@ -162,5 +170,7 @@ _PgConnectionTotalCount2.default,

exports.PgConnectionArgOrderBy = _PgConnectionArgOrderBy2.default;
exports.PgConnectionArgOrderByDefaultValue = _PgConnectionArgOrderByDefaultValue2.default;
exports.PgConnectionArgCondition = _PgConnectionArgCondition2.default;
exports.PgAllRows = _PgAllRows2.default;
exports.PgColumnsPlugin = _PgColumnsPlugin2.default;
exports.PgColumnDeprecationPlugin = _PgColumnDeprecationPlugin2.default;
exports.PgForwardRelationPlugin = _PgForwardRelationPlugin2.default;

@@ -167,0 +177,0 @@ exports.PgBackwardRelationPlugin = _PgBackwardRelationPlugin2.default;

8

node7minus/plugins/makeProcField.js

@@ -115,3 +115,3 @@ "use strict";

}
return returnsSet || type.arrayItemType ? (0, _pluralize2.default)(name) : name;
return returnsSet || type.isPgArray ? (0, _pluralize2.default)(name) : name;
}

@@ -140,3 +140,3 @@ if (computed && isMutation) {

var rawReturnType = introspectionResultsByKind.typeById[proc.returnTypeId];
var returnType = rawReturnType.arrayItemType || rawReturnType;
var returnType = rawReturnType.isPgArray ? rawReturnType.arrayItemType : rawReturnType;
var returnTypeTable = introspectionResultsByKind.classById[returnType.classId];

@@ -171,3 +171,3 @@ if (!returnType) {

type = TableType;
if (rawReturnType.arrayItemType) {
if (rawReturnType.isPgArray) {
type = new GraphQLList(type);

@@ -199,3 +199,3 @@ }

type = Type;
if (rawReturnType.arrayItemType) {
if (rawReturnType.isPgArray) {
type = new GraphQLList(type);

@@ -202,0 +202,0 @@ }

@@ -13,6 +13,12 @@ "use strict";

var defaultPgColumnFilter = function defaultPgColumnFilter(_attr, _build, _context) {
return true;
};
exports.default = function PgBasicsPlugin(builder, _ref) {
var pgInflection = _ref.pgInflection,
_ref$pgStrictFunction = _ref.pgStrictFunctions,
pgStrictFunctions = _ref$pgStrictFunction === undefined ? false : _ref$pgStrictFunction;
pgStrictFunctions = _ref$pgStrictFunction === undefined ? false : _ref$pgStrictFunction,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? defaultPgColumnFilter : _ref$pgColumnFilter;

@@ -23,3 +29,4 @@ builder.hook("build", function (build) {

pgInflection,
pgStrictFunctions
pgStrictFunctions,
pgColumnFilter
});

@@ -26,0 +33,0 @@ });

@@ -21,11 +21,4 @@ "use strict";

var defaultPgColumnFilter = function defaultPgColumnFilter(_attr, _build, _context) {
return true;
};
exports.default = function PgColumnsPlugin(builder, _ref) {
var inflection = _ref.pgInflection,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? defaultPgColumnFilter : _ref$pgColumnFilter;
var inflection = _ref.pgInflection;

@@ -42,3 +35,4 @@ builder.hook("GraphQLObjectType:fields", function (fields, build, context) {

getAliasFromResolveInfo = build.getAliasFromResolveInfo,
pgTweakFragmentForType = build.pgTweakFragmentForType;
pgTweakFragmentForType = build.pgTweakFragmentForType,
pgColumnFilter = build.pgColumnFilter;
var _context$scope = context.scope,

@@ -84,8 +78,15 @@ isPgRowType = _context$scope.isPgRowType,

var getSelectValueForFieldAndType = function getSelectValueForFieldAndType(sqlFullName, type) {
if (type.arrayItemType) {
if (type.isPgArray) {
var ident = sql.identifier((0, _symbol2.default)());
return sql.fragment`
(
select json_agg(${getSelectValueForFieldAndType(ident, type.arrayItemType)})
from unnest(${sqlFullName}) as ${ident}
case
when ${sqlFullName} is null then null
when coalesce(array_length(${sqlFullName}, 1), 0) = 0 then '[]'::json
else
(
select json_agg(${getSelectValueForFieldAndType(ident, type.arrayItemType)})
from unnest(${sqlFullName}) as ${ident}
)
end
)

@@ -96,3 +97,3 @@ `;

var jsonBuildObject = (0, _queryFromResolveData2.default)(sql.identifier((0, _symbol2.default)()), // Ignore!
sqlFullName, resolveData, { onlyJsonField: true });
sqlFullName, resolveData, { onlyJsonField: true, addNullCase: true });
return jsonBuildObject;

@@ -126,3 +127,4 @@ } else {

GraphQLString = _build$graphql2.GraphQLString,
GraphQLNonNull = _build$graphql2.GraphQLNonNull;
GraphQLNonNull = _build$graphql2.GraphQLNonNull,
pgColumnFilter = build.pgColumnFilter;
var _context$scope2 = context.scope,

@@ -129,0 +131,0 @@ isPgRowType = _context$scope2.isPgRowType,

@@ -7,11 +7,4 @@ "use strict";

var defaultPgColumnFilter = function defaultPgColumnFilter(_attr, _build, _context) {
return true;
};
exports.default = function PgConnectionArgCondition(builder, _ref) {
var inflection = _ref.pgInflection,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? defaultPgColumnFilter : _ref$pgColumnFilter;
var inflection = _ref.pgInflection;

@@ -24,3 +17,4 @@ builder.hook("init", function (_, build) {

GraphQLInputObjectType = _build$graphql.GraphQLInputObjectType,
GraphQLString = _build$graphql.GraphQLString;
GraphQLString = _build$graphql.GraphQLString,
pgColumnFilter = build.pgColumnFilter;

@@ -68,3 +62,4 @@ introspectionResultsByKind.class.filter(function (table) {

pgGetGqlTypeByTypeId = build.pgGetGqlTypeByTypeId,
introspectionResultsByKind = build.pgIntrospectionResultsByKind;
introspectionResultsByKind = build.pgIntrospectionResultsByKind,
pgColumnFilter = build.pgColumnFilter;
var _context$scope = context.scope,

@@ -71,0 +66,0 @@ isPgFieldConnection = _context$scope.isPgFieldConnection,

@@ -54,3 +54,6 @@ "use strict";

pgGetGqlTypeByTypeId = _ref3.pgGetGqlTypeByTypeId,
sql = _ref3.pgSql;
sql = _ref3.pgSql,
_ref3$graphql = _ref3.graphql,
GraphQLList = _ref3$graphql.GraphQLList,
GraphQLNonNull = _ref3$graphql.GraphQLNonNull;
var _ref4$scope = _ref4.scope,

@@ -72,20 +75,28 @@ isPgFieldConnection = _ref4$scope.isPgFieldConnection,

return {
pgCursorPrefix: orderBy && orderBy.alias && sql.literal(orderBy && orderBy.alias),
pgCursorPrefix: orderBy && orderBy.some(function (item) {
return item.alias;
}) ? orderBy.filter(function (item) {
return item.alias;
}).map(function (item) {
return sql.literal(item.alias);
}) : null,
pgQuery: function pgQuery(queryBuilder) {
if (orderBy != null) {
var specs = orderBy.specs,
unique = orderBy.unique;
orderBy.forEach(function (item) {
var specs = item.specs,
unique = item.unique;
var orders = Array.isArray(specs[0]) || specs.length === 0 ? specs : [specs];
orders.forEach(function (_ref6) {
var _ref7 = (0, _slicedToArray3.default)(_ref6, 2),
col = _ref7[0],
ascending = _ref7[1];
var orders = Array.isArray(specs[0]) || specs.length === 0 ? specs : [specs];
orders.forEach(function (_ref6) {
var _ref7 = (0, _slicedToArray3.default)(_ref6, 2),
col = _ref7[0],
ascending = _ref7[1];
var expr = (0, _isString2.default)(col) ? sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(col)}` : col;
queryBuilder.orderBy(expr, ascending);
var expr = (0, _isString2.default)(col) ? sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(col)}` : col;
queryBuilder.orderBy(expr, ascending);
});
if (unique) {
queryBuilder.setOrderIsUnique();
}
});
if (unique) {
queryBuilder.setOrderIsUnique();
}
}

@@ -95,5 +106,2 @@ }

});
var defaultValueEnum = TableOrderByType.getValues().find(function (v) {
return v.name === "PRIMARY_KEY_ASC";
}) || TableOrderByType.getValues()[0];

@@ -103,4 +111,3 @@ return extend(args, {

description: `The method to use when ordering \`${tableTypeName}\`.`,
type: TableOrderByType,
defaultValue: defaultValueEnum && defaultValueEnum.value
type: new GraphQLList(new GraphQLNonNull(TableOrderByType))
}

@@ -107,0 +114,0 @@ });

@@ -27,2 +27,4 @@ "use strict";

var _utils = require("../utils");
var _fs = require("fs");

@@ -45,2 +47,3 @@

var debug = (0, _debug2.default)("graphile-build-pg");
var INTROSPECTION_PATH = `${__dirname}/../../res/introspection-query.sql`;

@@ -112,2 +115,16 @@ var WATCH_FIXTURES_PATH = `${__dirname}/../../res/watch-fixtures.sql`;

// Parse tags from comments
["namespace", "class", "attribute", "type", "procedure"].forEach(function (kind) {
introspectionResultsByKind[kind].forEach(function (object) {
if (pgEnableTags && object.description) {
var parsed = (0, _utils.parseTags)(object.description);
object.tags = parsed.tags;
object.description = parsed.text;
} else {
object.tags = {};
}
});
});
xByY = function xByY(arrayOfX, attrKey) {

@@ -170,3 +187,3 @@ return arrayOfX.reduce(function (memo, x) {

case 26:
case 27:
case "end":

@@ -198,3 +215,4 @@ return _context.stop();

var pgConfig = _ref.pgConfig,
schemas = _ref.pgSchemas;
schemas = _ref.pgSchemas,
pgEnableTags = _ref.pgEnableTags;
var introspectionResultsByKind, pgClient, releasePgClient, listener, stopListening;

@@ -201,0 +219,0 @@ return _regenerator2.default.wrap(function _callee6$(_context6) {

@@ -37,7 +37,3 @@ "use strict";

var inflection = _ref.pgInflection,
pgDisableDefaultMutations = _ref.pgDisableDefaultMutations,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? function (_attr, _build, _context) {
return true;
} : _ref$pgColumnFilter;
pgDisableDefaultMutations = _ref.pgDisableDefaultMutations;

@@ -62,3 +58,4 @@ if (pgDisableDefaultMutations) {

GraphQLNonNull = _build$graphql.GraphQLNonNull,
GraphQLString = _build$graphql.GraphQLString;
GraphQLString = _build$graphql.GraphQLString,
pgColumnFilter = build.pgColumnFilter;

@@ -150,5 +147,5 @@ if (!isRootMutation) {

var parsedResolveInfoFragment, resolveData, insertedRowAlias, query, sqlColumns, sqlValues, inputData, mutationQuery, row, result;
return _regenerator2.default.wrap(function _callee$(_context2) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context.prev = _context.next) {
case 0:

@@ -181,32 +178,32 @@ parsedResolveInfoFragment = parseResolveInfo(resolveInfo);

row = void 0;
_context2.prev = 10;
_context2.next = 13;
_context.prev = 10;
_context.next = 13;
return pgClient.query("SAVEPOINT graphql_mutation");
case 13:
_context2.next = 15;
_context.next = 15;
return (0, _viaTemporaryTable2.default)(pgClient, sql.identifier(table.namespace.name, table.name), mutationQuery, insertedRowAlias, query);
case 15:
result = _context2.sent;
result = _context.sent;
row = result.rows[0];
_context2.next = 19;
_context.next = 19;
return pgClient.query("RELEASE SAVEPOINT graphql_mutation");
case 19:
_context2.next = 26;
_context.next = 26;
break;
case 21:
_context2.prev = 21;
_context2.t0 = _context2["catch"](10);
_context2.next = 25;
_context.prev = 21;
_context.t0 = _context["catch"](10);
_context.next = 25;
return pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation");
case 25:
throw _context2.t0;
throw _context.t0;
case 26:
return _context2.abrupt("return", {
return _context.abrupt("return", {
clientMutationId: input.clientMutationId,

@@ -218,3 +215,3 @@ data: row

case "end":
return _context2.stop();
return _context.stop();
}

@@ -221,0 +218,0 @@ }

@@ -44,11 +44,2 @@ "use strict";

*/
var argTypes = proc.argTypeIds.map(function (typeId) {
return introspectionResultsByKind.typeById[typeId];
});
if (argTypes.some(function (type) {
return type.type === "c" && type.class && type.class.isSelectable;
})) {
// It selects a table, don't add it at root level (see Computed Columns plugin)
return memo;
}

@@ -55,0 +46,0 @@ var fieldName = inflection.functionName(proc.name, proc.namespace.name);

@@ -61,17 +61,13 @@ "use strict";

var inflection = _ref.pgInflection,
pgDisableDefaultMutations = _ref.pgDisableDefaultMutations,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? function (_attr, _build, _context) {
return true;
} : _ref$pgColumnFilter;
return _regenerator2.default.wrap(function _callee4$(_context5) {
pgDisableDefaultMutations = _ref.pgDisableDefaultMutations;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context4.prev = _context4.next) {
case 0:
if (!pgDisableDefaultMutations) {
_context5.next = 2;
_context4.next = 2;
break;
}
return _context5.abrupt("return");
return _context4.abrupt("return");

@@ -85,2 +81,3 @@ case 2:

nodeIdFieldName = build.nodeIdFieldName,
fieldDataGeneratorsByType = build.fieldDataGeneratorsByType,
extend = build.extend,

@@ -100,3 +97,4 @@ parseResolveInfo = build.parseResolveInfo,

GraphQLObjectType = _build$graphql.GraphQLObjectType,
GraphQLID = _build$graphql.GraphQLID;
GraphQLID = _build$graphql.GraphQLID,
pgColumnFilter = build.pgColumnFilter;

@@ -115,5 +113,5 @@ if (!isRootMutation) {

var parsedResolveInfoFragment, resolveData, sqlTypeIdentifier, sqlMutationQuery, sqlColumns, sqlValues, inputData, modifiedRowAlias, query, row, result;
return _regenerator2.default.wrap(function _callee$(_context2) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context.prev = _context.next) {
case 0:

@@ -126,3 +124,3 @@ parsedResolveInfoFragment = parseResolveInfo(resolveInfo);

if (!(mode === "update")) {
_context2.next = 14;
_context.next = 14;
break;

@@ -150,7 +148,7 @@ }

if (!(sqlColumns.length === 0)) {
_context2.next = 11;
_context.next = 11;
break;
}
return _context2.abrupt("return", null);
return _context.abrupt("return", null);

@@ -164,3 +162,3 @@ case 11:

returning *`;
_context2.next = 15;
_context.next = 15;
break;

@@ -178,33 +176,33 @@

row = void 0;
_context2.prev = 18;
_context2.next = 21;
_context.prev = 18;
_context.next = 21;
return pgClient.query("SAVEPOINT graphql_mutation");
case 21:
_context2.next = 23;
_context.next = 23;
return (0, _viaTemporaryTable2.default)(pgClient, sqlTypeIdentifier, sqlMutationQuery, modifiedRowAlias, query);
case 23:
result = _context2.sent;
result = _context.sent;
row = result.rows[0];
_context2.next = 27;
_context.next = 27;
return pgClient.query("RELEASE SAVEPOINT graphql_mutation");
case 27:
_context2.next = 34;
_context.next = 34;
break;
case 29:
_context2.prev = 29;
_context2.t0 = _context2["catch"](18);
_context2.next = 33;
_context.prev = 29;
_context.t0 = _context["catch"](18);
_context.next = 33;
return pgClient.query("ROLLBACK TO SAVEPOINT graphql_mutation");
case 33:
throw _context2.t0;
throw _context.t0;
case 34:
if (row) {
_context2.next = 36;
_context.next = 36;
break;

@@ -216,3 +214,3 @@ }

case 36:
return _context2.abrupt("return", {
return _context.abrupt("return", {
clientMutationId: input.clientMutationId,

@@ -224,3 +222,3 @@ data: row

case "end":
return _context2.stop();
return _context.stop();
}

@@ -256,6 +254,9 @@ }

fields: function fields(_ref5) {
var recurseDataGeneratorsForField = _ref5.recurseDataGeneratorsForField;
var recurseDataGeneratorsForField = _ref5.recurseDataGeneratorsForField,
fieldWithHooks = _ref5.fieldWithHooks;
var tableName = inflection.tableName(table.name, table.namespace.name);
recurseDataGeneratorsForField(tableName);
// This should really be `-node-id` but for compatibility with PostGraphQL v3 we haven't made that change.
var deletedNodeIdFieldName = (0, _camelCase2.default)(`deleted-${_pluralize2.default.singular(table.name)}-id`);
return (0, _assign2.default)({

@@ -274,8 +275,22 @@ clientMutationId: {

}, mode === "delete" ? {
[(0, _camelCase2.default)(`deleted-${_pluralize2.default.singular(table.name)}-id`)]: {
type: GraphQLID,
resolve(data) {
return data.data.__identifiers && getNodeIdForTypeAndIdentifiers.apply(undefined, [Table].concat((0, _toConsumableArray3.default)(data.data.__identifiers)));
[deletedNodeIdFieldName]: fieldWithHooks(deletedNodeIdFieldName, function (_ref6) {
var addDataGenerator = _ref6.addDataGenerator;
var fieldDataGeneratorsByTableType = fieldDataGeneratorsByType.get(TableType);
var gens = fieldDataGeneratorsByTableType && fieldDataGeneratorsByTableType[nodeIdFieldName];
if (gens) {
gens.forEach(function (gen) {
return addDataGenerator(gen);
});
}
}
return {
type: GraphQLID,
resolve(data) {
return data.data.__identifiers && getNodeIdForTypeAndIdentifiers.apply(undefined, [Table].concat((0, _toConsumableArray3.default)(data.data.__identifiers)));
}
};
}, {
isPgMutationPayloadDeletedNodeIdField: true
})
} : null);

@@ -344,17 +359,17 @@ }

},
resolve(parent, _ref6, _ref7, resolveInfo) {
resolve(parent, _ref7, _ref8, resolveInfo) {
var _this = this;
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() {
var input = _ref6.input;
var pgClient = _ref7.pgClient;
var input = _ref7.input;
var pgClient = _ref8.pgClient;
var nodeId, _JSON$parse, _JSON$parse2, alias, identifiers, NodeTypeByAlias;
return _regenerator2.default.wrap(function _callee2$(_context3) {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context2.prev = _context2.next) {
case 0:
nodeId = input[nodeIdFieldName];
_context3.prev = 1;
_context2.prev = 1;
_JSON$parse = JSON.parse(base64Decode(nodeId)), _JSON$parse2 = (0, _toArray3.default)(_JSON$parse), alias = _JSON$parse2[0], identifiers = _JSON$parse2.slice(1);

@@ -364,3 +379,3 @@ NodeTypeByAlias = getNodeType(alias);

if (!(NodeTypeByAlias !== TableType)) {
_context3.next = 6;
_context2.next = 6;
break;

@@ -373,3 +388,3 @@ }

if (!(identifiers.length !== primaryKeys.length)) {
_context3.next = 8;
_context2.next = 8;
break;

@@ -381,3 +396,3 @@ }

case 8:
return _context3.abrupt("return", commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(primaryKeys.map(function (key, idx) {
return _context2.abrupt("return", commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(primaryKeys.map(function (key, idx) {
return sql.fragment`${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], key.type)}`;

@@ -387,11 +402,11 @@ }), ") and (")})`, context));

case 11:
_context3.prev = 11;
_context3.t0 = _context3["catch"](1);
_context2.prev = 11;
_context2.t0 = _context2["catch"](1);
debug(_context3.t0);
return _context3.abrupt("return", null);
debug(_context2.t0);
return _context2.abrupt("return", null);
case 15:
case "end":
return _context3.stop();
return _context2.stop();
}

@@ -469,13 +484,13 @@ }

},
resolve(parent, _ref8, _ref9, resolveInfo) {
resolve(parent, _ref9, _ref10, resolveInfo) {
var _this2 = this;
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() {
var input = _ref8.input;
var pgClient = _ref9.pgClient;
return _regenerator2.default.wrap(function _callee3$(_context4) {
var input = _ref9.input;
var pgClient = _ref10.pgClient;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context3.prev = _context3.next) {
case 0:
return _context4.abrupt("return", commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(keys.map(function (key) {
return _context3.abrupt("return", commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(keys.map(function (key) {
return sql.fragment`${sql.identifier(key.name)} = ${gql2pg(input[inflection.column(key.name, key.class.name, key.class.namespace.name)], key.type)}`;

@@ -486,3 +501,3 @@ }), ") and (")})`, context));

case "end":
return _context4.stop();
return _context3.stop();
}

@@ -508,3 +523,3 @@ }

case "end":
return _context5.stop();
return _context4.stop();
}

@@ -511,0 +526,0 @@ }

@@ -8,11 +8,8 @@ "use strict";

exports.default = function PgOrderAllColumnsPlugin(builder, _ref) {
var inflection = _ref.pgInflection,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? function (_attr, _build, _context) {
return true;
} : _ref$pgColumnFilter;
var inflection = _ref.pgInflection;
builder.hook("GraphQLEnumType:values", function (values, build, context) {
var extend = build.extend,
introspectionResultsByKind = build.pgIntrospectionResultsByKind;
introspectionResultsByKind = build.pgIntrospectionResultsByKind,
pgColumnFilter = build.pgColumnFilter;
var _context$scope = context.scope,

@@ -19,0 +16,0 @@ isPgRowSortEnum = _context$scope.isPgRowSortEnum,

@@ -22,7 +22,3 @@ "use strict";

exports.default = function PgTablesPlugin(builder, _ref) {
var inflection = _ref.pgInflection,
_ref$pgColumnFilter = _ref.pgColumnFilter,
pgColumnFilter = _ref$pgColumnFilter === undefined ? function (_attr, _build, _context) {
return true;
} : _ref$pgColumnFilter;
var inflection = _ref.pgInflection;

@@ -47,3 +43,4 @@ builder.hook("init", function (_, build) {

GraphQLList = _build$graphql.GraphQLList,
GraphQLInputObjectType = _build$graphql.GraphQLInputObjectType;
GraphQLInputObjectType = _build$graphql.GraphQLInputObjectType,
pgColumnFilter = build.pgColumnFilter;

@@ -50,0 +47,0 @@ var Cursor = getTypeByName("Cursor");

@@ -11,2 +11,6 @@ "use strict";

var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray");
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _getIterator2 = require("babel-runtime/core-js/get-iterator");

@@ -149,3 +153,3 @@

return pg2gql(val, type.domainBaseType);
} else if (type.arrayItemType) {
} else if (type.isPgArray) {
if (!Array.isArray(val)) {

@@ -169,3 +173,3 @@ throw new Error(`Expected array when converting PostgreSQL data into GraphQL; failing type: '${type.namespaceName}.${type.name}'`);

return gql2pg(val, type.domainBaseType);
} else if (type.arrayItemType) {
} else if (type.isPgArray) {
if (!Array.isArray(val)) {

@@ -245,2 +249,8 @@ throw new Error(`Expected array when converting GraphQL data into PostgreSQL data; failing type: '${type.namespaceName}.${type.name}' (type: ${type === null ? "null" : typeof type})`);

}, {});
var BigFloat = stringType("BigFloat", "A floating point number that requires more precision than IEEE 754 binary 64");
var BitString = stringType("BitString", "A string representing a series of binary bits");
addType(BigFloat);
addType(BitString);
var categoryLookup = {

@@ -254,3 +264,3 @@ B: function B() {

N: function N() {
return _graphql.GraphQLString;
return BigFloat;
},

@@ -294,3 +304,3 @@

return pgTweakFragmentForType(fragment, type.domainBaseType);
} else if (type.arrayItemType) {
} else if (type.isPgArray) {
var error = new Error("Internal graphile-build-pg error: should not attempt to tweak an array, please process array before tweaking (type: `${type.namespaceName}.${type.name}`)");

@@ -317,3 +327,42 @@ if (process.env.NODE_ENV === "test") {

var SimpleUUID = stringType("UUID", "A universally unique identifier as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122).");
var oidLookup = (0, _assign2.default)({
// pgExtendedTypes might change what types we use for things
var JSONType = pgExtendedTypes ? _graphqlTypeJson2.default : SimpleJSON;
var UUIDType = SimpleUUID; // GraphQLUUID
var DateType = SimpleDate; // GraphQLDate
var DateTimeType = SimpleDatetime; // GraphQLDateTime
var TimeType = SimpleTime; // GraphQLTime
// 'point' in PostgreSQL is a 16-byte type that's comprised of two 8-byte floats.
var Point = new _graphql.GraphQLObjectType({
name: "Point",
fields: {
x: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
},
y: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
}
}
});
var PointInput = new _graphql.GraphQLInputObjectType({
name: "PointInput",
fields: {
x: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
},
y: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
}
}
});
// Other plugins might want to use JSON
addType(JSONType);
addType(UUIDType);
addType(DateType);
addType(DateTimeType);
addType(TimeType);
var oidLookup = {
"20": stringType("BigInt", "A signed eight-byte integer. The upper big integer values are greater then the max value for a JavaScript number. Therefore all big integers will be output as strings and not numbers."), // bitint - even though this is int8, it's too big for JS int, so cast to string.

@@ -324,32 +373,28 @@ "21": _graphql.GraphQLInt, // int2

"701": _graphql.GraphQLFloat, // float8
"1700": _graphql.GraphQLString, // numeric
"1700": BigFloat, // numeric
"790": _graphql.GraphQLFloat, // money
"1186": GQLInterval, // interval
"1082": SimpleDate, // date
"1114": SimpleDatetime, // timestamp
"1184": SimpleDatetime, // timestamptz
"1083": SimpleTime, // time
"1266": SimpleTime, // timetz
"1082": DateType, // date
"1114": DateTimeType, // timestamp
"1184": DateTimeType, // timestamptz
"1083": TimeType, // time
"1266": TimeType, // timetz
"114": SimpleJSON, // json
"3802": SimpleJSON, // jsonb
"2950": SimpleUUID, // uuid
"114": JSONType, // json
"3802": JSONType, // jsonb
"2950": UUIDType, // uuid
"1560": _graphql.GraphQLString, // bit
"1562": _graphql.GraphQLString // varbit
}, pgExtendedTypes && {
"114": _graphqlTypeJson2.default,
"3802": _graphqlTypeJson2.default
/*
'1082': GraphQLDate, // date
'1114': GraphQLDateTime, // timestamp
'1184': GraphQLDateTime, // timestamptz
'1083': GraphQLTime, // time
'1266': GraphQLTime, // timetz
'2950': GraphQLUUID,
*/
});
"1560": BitString, // bit
"1562": BitString, // varbit
"18": _graphql.GraphQLString, // char
"25": _graphql.GraphQLString, // text
"1043": _graphql.GraphQLString, // varchar
"600": Point // point
};
var oidInputLookup = {
"1186": GQLIntervalInput // interval
"1186": GQLIntervalInput, // interval
"600": PointInput // point
};

@@ -436,2 +481,23 @@ var identity = function identity(_) {

// point
pg2GqlMapper[600] = {
map: function map(f) {
if (f[0] === "(" && f[f.length - 1] === ")") {
var _f$substr$split$map = f.substr(1, f.length - 2).split(",").map(function (f) {
return parseFloat(f);
}),
_f$substr$split$map2 = (0, _slicedToArray3.default)(_f$substr$split$map, 2),
x = _f$substr$split$map2[0],
y = _f$substr$split$map2[1];
return { x, y };
}
},
unmap: function unmap(o) {
return sql.fragment`point(${sql.value(o.x)}, ${sql.value(o.y)})`;
}
};
// TODO: add more support for geometric types
var depth = 0;

@@ -438,0 +504,0 @@ var enforceGqlTypeByPgType = function enforceGqlTypeByPgType(type) {

@@ -435,3 +435,3 @@ "use strict";

if (addNullCase) {
buildObject = sql.fragment`(case when ${this.getTableAlias()} is null then null else ${buildObject} end)`;
buildObject = sql.fragment`(case when ${this.getTableAlias()} is not distinct from null then null else ${buildObject} end)`;
}

@@ -438,0 +438,0 @@ return buildObject;

@@ -6,4 +6,12 @@ "use strict";

});
exports.upperCamelCase = exports.constantCase = exports.camelCase = exports.upperFirst = exports.formatInsideUnderscores = exports.constantCaseAll = exports.sqlJsonBuildObjectFromFragments = undefined;
exports.parseTags = exports.upperCamelCase = exports.constantCase = exports.camelCase = exports.upperFirst = exports.formatInsideUnderscores = exports.constantCaseAll = undefined;
var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _assign = require("babel-runtime/core-js/object/assign");
var _assign2 = _interopRequireDefault(_assign);
var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray");

@@ -13,6 +21,2 @@

var _pgSql = require("pg-sql2");
var _pgSql2 = _interopRequireDefault(_pgSql);
var _upperFirst = require("lodash/upperFirst");

@@ -28,12 +32,2 @@

var sqlJsonBuildObjectFromFragments = exports.sqlJsonBuildObjectFromFragments = function sqlJsonBuildObjectFromFragments(fragments) {
return _pgSql2.default.fragment`
json_build_object(
${_pgSql2.default.join(fragments.map(function (_ref) {
var sqlFragment = _ref.sqlFragment,
alias = _ref.alias;
return _pgSql2.default.fragment`${_pgSql2.default.literal(alias)}, ${sqlFragment}`;
}), ",\n")}
)`;
};
var constantCaseAll = exports.constantCaseAll = function constantCaseAll(str) {

@@ -66,2 +60,28 @@ return str.replace(/[^a-zA-Z0-9_]+/g, "_").replace(/[A-Z]+/g, "_$&").replace(/__+/g, "_").replace(/^[^a-zA-Z0-9]+/, "").replace(/^[0-9]/, "_$&") // GraphQL enums must not start with a number

};
var parseTags = exports.parseTags = function parseTags(str) {
return str.split(`\n`).reduce(function (prev, curr) {
if (prev.text !== "") {
return (0, _assign2.default)({}, prev, {
text: `${prev.text}\n${curr}`
});
}
var match = curr.match(/^@[a-zA-Z][a-zA-Z0-9_]*($|\s)/);
if (!match) {
return (0, _assign2.default)({}, prev, {
text: curr
});
}
var key = match[0].substr(1).trim();
var value = match[0] === curr ? true : curr.replace(match[0], "");
return (0, _assign2.default)({}, prev, {
tags: (0, _assign2.default)({}, prev.tags, {
[key]: !prev.tags.hasOwnProperty(key) ? value : Array.isArray(prev.tags[key]) ? [].concat((0, _toConsumableArray3.default)(prev.tags[key]), [value]) : [prev.tags[key], value]
})
});
}, {
tags: {},
text: ""
});
};
//# sourceMappingURL=utils.js.map

@@ -6,3 +6,3 @@ "use strict";

});
exports.constantCase = exports.camelCase = exports.upperFirst = exports.PgMutationPayloadEdgePlugin = exports.PgMutationProceduresPlugin = exports.PgMutationUpdateDeletePlugin = exports.PgMutationCreatePlugin = exports.PgConnectionTotalCount = exports.PageInfoStartEndCursor = exports.PgScalarFunctionConnectionPlugin = exports.PgNodeAliasPostGraphQL = exports.PgRowNode = exports.PgOrderByPrimaryKeyPlugin = exports.PgOrderAllColumnsPlugin = exports.PgQueryProceduresPlugin = exports.PgComputedColumnsPlugin = exports.PgRowByUniqueConstraint = exports.PgBackwardRelationPlugin = exports.PgForwardRelationPlugin = exports.PgColumnsPlugin = exports.PgAllRows = exports.PgConnectionArgCondition = exports.PgConnectionArgOrderBy = exports.PgConnectionArgFirstLastBeforeAfter = exports.PgTablesPlugin = exports.PgJWTPlugin = exports.PgTypesPlugin = exports.PgIntrospectionPlugin = exports.PgBasicsPlugin = exports.inflections = exports.defaultPlugins = undefined;
exports.constantCase = exports.camelCase = exports.upperFirst = exports.PgMutationPayloadEdgePlugin = exports.PgMutationProceduresPlugin = exports.PgMutationUpdateDeletePlugin = exports.PgMutationCreatePlugin = exports.PgConnectionTotalCount = exports.PageInfoStartEndCursor = exports.PgScalarFunctionConnectionPlugin = exports.PgNodeAliasPostGraphQL = exports.PgRowNode = exports.PgOrderByPrimaryKeyPlugin = exports.PgOrderAllColumnsPlugin = exports.PgQueryProceduresPlugin = exports.PgComputedColumnsPlugin = exports.PgRowByUniqueConstraint = exports.PgBackwardRelationPlugin = exports.PgForwardRelationPlugin = exports.PgColumnDeprecationPlugin = exports.PgColumnsPlugin = exports.PgAllRows = exports.PgConnectionArgCondition = exports.PgConnectionArgOrderByDefaultValue = exports.PgConnectionArgOrderBy = exports.PgConnectionArgFirstLastBeforeAfter = exports.PgTablesPlugin = exports.PgJWTPlugin = exports.PgTypesPlugin = exports.PgIntrospectionPlugin = exports.PgBasicsPlugin = exports.inflections = exports.defaultPlugins = undefined;

@@ -58,2 +58,6 @@ var _utils = require("./utils");

var _PgConnectionArgOrderByDefaultValue = require("./plugins/PgConnectionArgOrderByDefaultValue");
var _PgConnectionArgOrderByDefaultValue2 = _interopRequireDefault(_PgConnectionArgOrderByDefaultValue);
var _PgConnectionArgCondition = require("./plugins/PgConnectionArgCondition");

@@ -71,2 +75,6 @@

var _PgColumnDeprecationPlugin = require("./plugins/PgColumnDeprecationPlugin");
var _PgColumnDeprecationPlugin2 = _interopRequireDefault(_PgColumnDeprecationPlugin);
var _PgForwardRelationPlugin = require("./plugins/PgForwardRelationPlugin");

@@ -144,3 +152,3 @@

const defaultPlugins = exports.defaultPlugins = [_PgBasicsPlugin2.default, _PgIntrospectionPlugin2.default, _PgTypesPlugin2.default, _PgJWTPlugin2.default, _PgTablesPlugin2.default, _PgConnectionArgFirstLastBeforeAfter2.default, _PgConnectionArgOrderBy2.default, _PgConnectionArgCondition2.default, _PgAllRows2.default, _PgColumnsPlugin2.default, _PgForwardRelationPlugin2.default, _PgBackwardRelationPlugin2.default, _PgRowByUniqueConstraint2.default, _PgComputedColumnsPlugin2.default, _PgQueryProceduresPlugin2.default, _PgOrderAllColumnsPlugin2.default, _PgOrderByPrimaryKeyPlugin2.default, _PgRowNode2.default, _PgNodeAliasPostGraphQL2.default, _PgScalarFunctionConnectionPlugin2.default, // For PostGraphQL compatibility
const defaultPlugins = exports.defaultPlugins = [_PgBasicsPlugin2.default, _PgIntrospectionPlugin2.default, _PgTypesPlugin2.default, _PgJWTPlugin2.default, _PgTablesPlugin2.default, _PgConnectionArgFirstLastBeforeAfter2.default, _PgConnectionArgOrderBy2.default, _PgConnectionArgOrderByDefaultValue2.default, _PgConnectionArgCondition2.default, _PgAllRows2.default, _PgColumnsPlugin2.default, _PgColumnDeprecationPlugin2.default, _PgForwardRelationPlugin2.default, _PgBackwardRelationPlugin2.default, _PgRowByUniqueConstraint2.default, _PgComputedColumnsPlugin2.default, _PgQueryProceduresPlugin2.default, _PgOrderAllColumnsPlugin2.default, _PgOrderByPrimaryKeyPlugin2.default, _PgRowNode2.default, _PgNodeAliasPostGraphQL2.default, _PgScalarFunctionConnectionPlugin2.default, // For PostGraphQL compatibility
_PageInfoStartEndCursor2.default, // For PostGraphQL compatibility

@@ -162,5 +170,7 @@ _PgConnectionTotalCount2.default,

exports.PgConnectionArgOrderBy = _PgConnectionArgOrderBy2.default;
exports.PgConnectionArgOrderByDefaultValue = _PgConnectionArgOrderByDefaultValue2.default;
exports.PgConnectionArgCondition = _PgConnectionArgCondition2.default;
exports.PgAllRows = _PgAllRows2.default;
exports.PgColumnsPlugin = _PgColumnsPlugin2.default;
exports.PgColumnDeprecationPlugin = _PgColumnDeprecationPlugin2.default;
exports.PgForwardRelationPlugin = _PgForwardRelationPlugin2.default;

@@ -167,0 +177,0 @@ exports.PgBackwardRelationPlugin = _PgBackwardRelationPlugin2.default;

@@ -97,3 +97,3 @@ "use strict";

}
return returnsSet || type.arrayItemType ? (0, _pluralize2.default)(name) : name;
return returnsSet || type.isPgArray ? (0, _pluralize2.default)(name) : name;
}

@@ -118,3 +118,3 @@ if (computed && isMutation) {

const rawReturnType = introspectionResultsByKind.typeById[proc.returnTypeId];
const returnType = rawReturnType.arrayItemType || rawReturnType;
const returnType = rawReturnType.isPgArray ? rawReturnType.arrayItemType : rawReturnType;
const returnTypeTable = introspectionResultsByKind.classById[returnType.classId];

@@ -149,3 +149,3 @@ if (!returnType) {

type = TableType;
if (rawReturnType.arrayItemType) {
if (rawReturnType.isPgArray) {
type = new GraphQLList(type);

@@ -177,3 +177,3 @@ }

type = Type;
if (rawReturnType.arrayItemType) {
if (rawReturnType.isPgArray) {
type = new GraphQLList(type);

@@ -180,0 +180,0 @@ }

@@ -13,3 +13,9 @@ "use strict";

exports.default = function PgBasicsPlugin(builder, { pgInflection, pgStrictFunctions = false }) {
const defaultPgColumnFilter = (_attr, _build, _context) => true;
exports.default = function PgBasicsPlugin(builder, {
pgInflection,
pgStrictFunctions = false,
pgColumnFilter = defaultPgColumnFilter
}) {
builder.hook("build", build => {

@@ -19,3 +25,4 @@ return build.extend(build, {

pgInflection,
pgStrictFunctions
pgStrictFunctions,
pgColumnFilter
});

@@ -22,0 +29,0 @@ });

@@ -19,6 +19,3 @@ "use strict";

const defaultPgColumnFilter = (_attr, _build, _context) => true;
exports.default = function PgColumnsPlugin(builder, { pgInflection: inflection, pgColumnFilter = defaultPgColumnFilter }) {
exports.default = function PgColumnsPlugin(builder, { pgInflection: inflection }) {
builder.hook("GraphQLObjectType:fields", (fields, build, context) => {

@@ -33,3 +30,4 @@ const {

getAliasFromResolveInfo,
pgTweakFragmentForType
pgTweakFragmentForType,
pgColumnFilter
} = build;

@@ -66,8 +64,15 @@ const {

const getSelectValueForFieldAndType = (sqlFullName, type) => {
if (type.arrayItemType) {
if (type.isPgArray) {
const ident = sql.identifier((0, _symbol2.default)());
return sql.fragment`
(
select json_agg(${getSelectValueForFieldAndType(ident, type.arrayItemType)})
from unnest(${sqlFullName}) as ${ident}
case
when ${sqlFullName} is null then null
when coalesce(array_length(${sqlFullName}, 1), 0) = 0 then '[]'::json
else
(
select json_agg(${getSelectValueForFieldAndType(ident, type.arrayItemType)})
from unnest(${sqlFullName}) as ${ident}
)
end
)

@@ -78,3 +83,3 @@ `;

const jsonBuildObject = (0, _queryFromResolveData2.default)(sql.identifier((0, _symbol2.default)()), // Ignore!
sqlFullName, resolveData, { onlyJsonField: true });
sqlFullName, resolveData, { onlyJsonField: true, addNullCase: true });
return jsonBuildObject;

@@ -107,3 +112,4 @@ } else {

pgIntrospectionResultsByKind: introspectionResultsByKind,
graphql: { GraphQLString, GraphQLNonNull }
graphql: { GraphQLString, GraphQLNonNull },
pgColumnFilter
} = build;

@@ -110,0 +116,0 @@ const {

@@ -7,6 +7,3 @@ "use strict";

const defaultPgColumnFilter = (_attr, _build, _context) => true;
exports.default = function PgConnectionArgCondition(builder, { pgInflection: inflection, pgColumnFilter = defaultPgColumnFilter }) {
exports.default = function PgConnectionArgCondition(builder, { pgInflection: inflection }) {
builder.hook("init", (_, build) => {

@@ -17,3 +14,4 @@ const {

pgGetGqlInputTypeByTypeId,
graphql: { GraphQLInputObjectType, GraphQLString }
graphql: { GraphQLInputObjectType, GraphQLString },
pgColumnFilter
} = build;

@@ -53,3 +51,4 @@ introspectionResultsByKind.class.filter(table => table.isSelectable).filter(table => !!table.namespace).forEach(table => {

pgGetGqlTypeByTypeId,
pgIntrospectionResultsByKind: introspectionResultsByKind
pgIntrospectionResultsByKind: introspectionResultsByKind,
pgColumnFilter
} = build;

@@ -56,0 +55,0 @@ const {

@@ -40,3 +40,9 @@ "use strict";

});
builder.hook("GraphQLObjectType:fields:field:args", (args, { extend, getTypeByName, pgGetGqlTypeByTypeId, pgSql: sql }, {
builder.hook("GraphQLObjectType:fields:field:args", (args, {
extend,
getTypeByName,
pgGetGqlTypeByTypeId,
pgSql: sql,
graphql: { GraphQLList, GraphQLNonNull }
}, {
scope: { isPgFieldConnection, pgFieldIntrospection: table },

@@ -54,14 +60,16 @@ addArgDataGenerator

return {
pgCursorPrefix: orderBy && orderBy.alias && sql.literal(orderBy && orderBy.alias),
pgCursorPrefix: orderBy && orderBy.some(item => item.alias) ? orderBy.filter(item => item.alias).map(item => sql.literal(item.alias)) : null,
pgQuery: queryBuilder => {
if (orderBy != null) {
const { specs, unique } = orderBy;
const orders = Array.isArray(specs[0]) || specs.length === 0 ? specs : [specs];
orders.forEach(([col, ascending]) => {
const expr = (0, _isString2.default)(col) ? sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(col)}` : col;
queryBuilder.orderBy(expr, ascending);
orderBy.forEach(item => {
const { specs, unique } = item;
const orders = Array.isArray(specs[0]) || specs.length === 0 ? specs : [specs];
orders.forEach(([col, ascending]) => {
const expr = (0, _isString2.default)(col) ? sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(col)}` : col;
queryBuilder.orderBy(expr, ascending);
});
if (unique) {
queryBuilder.setOrderIsUnique();
}
});
if (unique) {
queryBuilder.setOrderIsUnique();
}
}

@@ -71,3 +79,2 @@ }

});
const defaultValueEnum = TableOrderByType.getValues().find(v => v.name === "PRIMARY_KEY_ASC") || TableOrderByType.getValues()[0];

@@ -77,4 +84,3 @@ return extend(args, {

description: `The method to use when ordering \`${tableTypeName}\`.`,
type: TableOrderByType,
defaultValue: defaultValueEnum && defaultValueEnum.value
type: new GraphQLList(new GraphQLNonNull(TableOrderByType))
}

@@ -81,0 +87,0 @@ });

@@ -19,2 +19,4 @@ "use strict";

var _utils = require("../utils");
var _fs = require("fs");

@@ -37,2 +39,3 @@

const debug = (0, _debug2.default)("graphile-build-pg");
const INTROSPECTION_PATH = `${__dirname}/../../res/introspection-query.sql`;

@@ -51,3 +54,3 @@ const WATCH_FIXTURES_PATH = `${__dirname}/../../res/watch-fixtures.sql`;

exports.default = async function PgIntrospectionPlugin(builder, { pgConfig, pgSchemas: schemas }) {
exports.default = async function PgIntrospectionPlugin(builder, { pgConfig, pgSchemas: schemas, pgEnableTags }) {
async function introspect() {

@@ -73,2 +76,16 @@ return (0, _withPgClient2.default)(pgConfig, async pgClient => {

});
// Parse tags from comments
["namespace", "class", "attribute", "type", "procedure"].forEach(kind => {
introspectionResultsByKind[kind].forEach(object => {
if (pgEnableTags && object.description) {
const parsed = (0, _utils.parseTags)(object.description);
object.tags = parsed.tags;
object.description = parsed.text;
} else {
object.tags = {};
}
});
});
const xByY = (arrayOfX, attrKey) => arrayOfX.reduce((memo, x) => {

@@ -75,0 +92,0 @@ memo[x[attrKey]] = x;

@@ -27,7 +27,3 @@ "use strict";

exports.default = function PgMutationCreatePlugin(builder, {
pgInflection: inflection,
pgDisableDefaultMutations,
pgColumnFilter = (_attr, _build, _context) => true
}) {
exports.default = function PgMutationCreatePlugin(builder, { pgInflection: inflection, pgDisableDefaultMutations }) {
if (pgDisableDefaultMutations) {

@@ -51,3 +47,4 @@ return;

GraphQLString
}
},
pgColumnFilter
} = build;

@@ -54,0 +51,0 @@ if (!isRootMutation) {

@@ -38,7 +38,2 @@ "use strict";

*/
const argTypes = proc.argTypeIds.map(typeId => introspectionResultsByKind.typeById[typeId]);
if (argTypes.some(type => type.type === "c" && type.class && type.class.isSelectable)) {
// It selects a table, don't add it at root level (see Computed Columns plugin)
return memo;
}

@@ -45,0 +40,0 @@ const fieldName = inflection.functionName(proc.name, proc.namespace.name);

@@ -40,7 +40,3 @@ "use strict";

exports.default = async function PgMutationUpdateDeletePlugin(builder, {
pgInflection: inflection,
pgDisableDefaultMutations,
pgColumnFilter = (_attr, _build, _context) => true
}) {
exports.default = async function PgMutationUpdateDeletePlugin(builder, { pgInflection: inflection, pgDisableDefaultMutations }) {
if (pgDisableDefaultMutations) {

@@ -54,2 +50,3 @@ return;

nodeIdFieldName,
fieldDataGeneratorsByType,
extend,

@@ -70,3 +67,4 @@ parseResolveInfo,

GraphQLID
}
},
pgColumnFilter
} = build;

@@ -141,5 +139,10 @@ if (!isRootMutation) {

description: `The output of our ${mode} \`${tableTypeName}\` mutation.`,
fields: ({ recurseDataGeneratorsForField }) => {
fields: ({
recurseDataGeneratorsForField,
fieldWithHooks
}) => {
const tableName = inflection.tableName(table.name, table.namespace.name);
recurseDataGeneratorsForField(tableName);
// This should really be `-node-id` but for compatibility with PostGraphQL v3 we haven't made that change.
const deletedNodeIdFieldName = (0, _camelCase2.default)(`deleted-${_pluralize2.default.singular(table.name)}-id`);
return (0, _assign2.default)({

@@ -158,8 +161,18 @@ clientMutationId: {

}, mode === "delete" ? {
[(0, _camelCase2.default)(`deleted-${_pluralize2.default.singular(table.name)}-id`)]: {
type: GraphQLID,
resolve(data) {
return data.data.__identifiers && getNodeIdForTypeAndIdentifiers(Table, ...data.data.__identifiers);
[deletedNodeIdFieldName]: fieldWithHooks(deletedNodeIdFieldName, ({ addDataGenerator }) => {
const fieldDataGeneratorsByTableType = fieldDataGeneratorsByType.get(TableType);
const gens = fieldDataGeneratorsByTableType && fieldDataGeneratorsByTableType[nodeIdFieldName];
if (gens) {
gens.forEach(gen => addDataGenerator(gen));
}
}
return {
type: GraphQLID,
resolve(data) {
return data.data.__identifiers && getNodeIdForTypeAndIdentifiers(Table, ...data.data.__identifiers);
}
};
}, {
isPgMutationPayloadDeletedNodeIdField: true
})
} : null);

@@ -166,0 +179,0 @@ }

@@ -7,10 +7,8 @@ "use strict";

exports.default = function PgOrderAllColumnsPlugin(builder, {
pgInflection: inflection,
pgColumnFilter = (_attr, _build, _context) => true
}) {
exports.default = function PgOrderAllColumnsPlugin(builder, { pgInflection: inflection }) {
builder.hook("GraphQLEnumType:values", (values, build, context) => {
const {
extend,
pgIntrospectionResultsByKind: introspectionResultsByKind
pgIntrospectionResultsByKind: introspectionResultsByKind,
pgColumnFilter
} = build;

@@ -17,0 +15,0 @@ const { scope: { isPgRowSortEnum, pgIntrospection: table } } = context;

@@ -15,6 +15,3 @@ "use strict";

exports.default = function PgTablesPlugin(builder, {
pgInflection: inflection,
pgColumnFilter = (_attr, _build, _context) => true
}) {
exports.default = function PgTablesPlugin(builder, { pgInflection: inflection }) {
builder.hook("init", (_, build) => {

@@ -40,3 +37,4 @@ const {

GraphQLInputObjectType
}
},
pgColumnFilter
} = build;

@@ -43,0 +41,0 @@ const Cursor = getTypeByName("Cursor");

@@ -132,3 +132,3 @@ "use strict";

return pg2gql(val, type.domainBaseType);
} else if (type.arrayItemType) {
} else if (type.isPgArray) {
if (!Array.isArray(val)) {

@@ -150,3 +150,3 @@ throw new Error(`Expected array when converting PostgreSQL data into GraphQL; failing type: '${type.namespaceName}.${type.name}'`);

return gql2pg(val, type.domainBaseType);
} else if (type.arrayItemType) {
} else if (type.isPgArray) {
if (!Array.isArray(val)) {

@@ -224,2 +224,8 @@ throw new Error(`Expected array when converting GraphQL data into PostgreSQL data; failing type: '${type.namespaceName}.${type.name}' (type: ${type === null ? "null" : typeof type})`);

}, {});
const BigFloat = stringType("BigFloat", "A floating point number that requires more precision than IEEE 754 binary 64");
const BitString = stringType("BitString", "A string representing a series of binary bits");
addType(BigFloat);
addType(BitString);
const categoryLookup = {

@@ -230,3 +236,3 @@ B: () => _graphql.GraphQLBoolean,

// default.
N: () => _graphql.GraphQLString,
N: () => BigFloat,

@@ -263,3 +269,3 @@ A: type => new _graphql.GraphQLList(enforceGqlTypeByPgType(pgTypeById[type.arrayItemTypeId]))

return pgTweakFragmentForType(fragment, type.domainBaseType);
} else if (type.arrayItemType) {
} else if (type.isPgArray) {
const error = new Error("Internal graphile-build-pg error: should not attempt to tweak an array, please process array before tweaking (type: `${type.namespaceName}.${type.name}`)");

@@ -286,3 +292,42 @@ if (process.env.NODE_ENV === "test") {

const SimpleUUID = stringType("UUID", "A universally unique identifier as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122).");
const oidLookup = (0, _assign2.default)({
// pgExtendedTypes might change what types we use for things
const JSONType = pgExtendedTypes ? _graphqlTypeJson2.default : SimpleJSON;
const UUIDType = SimpleUUID; // GraphQLUUID
const DateType = SimpleDate; // GraphQLDate
const DateTimeType = SimpleDatetime; // GraphQLDateTime
const TimeType = SimpleTime; // GraphQLTime
// 'point' in PostgreSQL is a 16-byte type that's comprised of two 8-byte floats.
const Point = new _graphql.GraphQLObjectType({
name: "Point",
fields: {
x: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
},
y: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
}
}
});
const PointInput = new _graphql.GraphQLInputObjectType({
name: "PointInput",
fields: {
x: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
},
y: {
type: new _graphql.GraphQLNonNull(_graphql.GraphQLFloat)
}
}
});
// Other plugins might want to use JSON
addType(JSONType);
addType(UUIDType);
addType(DateType);
addType(DateTimeType);
addType(TimeType);
const oidLookup = {
"20": stringType("BigInt", "A signed eight-byte integer. The upper big integer values are greater then the max value for a JavaScript number. Therefore all big integers will be output as strings and not numbers."), // bitint - even though this is int8, it's too big for JS int, so cast to string.

@@ -293,32 +338,28 @@ "21": _graphql.GraphQLInt, // int2

"701": _graphql.GraphQLFloat, // float8
"1700": _graphql.GraphQLString, // numeric
"1700": BigFloat, // numeric
"790": _graphql.GraphQLFloat, // money
"1186": GQLInterval, // interval
"1082": SimpleDate, // date
"1114": SimpleDatetime, // timestamp
"1184": SimpleDatetime, // timestamptz
"1083": SimpleTime, // time
"1266": SimpleTime, // timetz
"1082": DateType, // date
"1114": DateTimeType, // timestamp
"1184": DateTimeType, // timestamptz
"1083": TimeType, // time
"1266": TimeType, // timetz
"114": SimpleJSON, // json
"3802": SimpleJSON, // jsonb
"2950": SimpleUUID, // uuid
"114": JSONType, // json
"3802": JSONType, // jsonb
"2950": UUIDType, // uuid
"1560": _graphql.GraphQLString, // bit
"1562": _graphql.GraphQLString // varbit
}, pgExtendedTypes && {
"114": _graphqlTypeJson2.default,
"3802": _graphqlTypeJson2.default
/*
'1082': GraphQLDate, // date
'1114': GraphQLDateTime, // timestamp
'1184': GraphQLDateTime, // timestamptz
'1083': GraphQLTime, // time
'1266': GraphQLTime, // timetz
'2950': GraphQLUUID,
*/
});
"1560": BitString, // bit
"1562": BitString, // varbit
"18": _graphql.GraphQLString, // char
"25": _graphql.GraphQLString, // text
"1043": _graphql.GraphQLString, // varchar
"600": Point // point
};
const oidInputLookup = {
"1186": GQLIntervalInput // interval
"1186": GQLIntervalInput, // interval
"600": PointInput // point
};

@@ -371,2 +412,15 @@ const identity = _ => _;

// point
pg2GqlMapper[600] = {
map: f => {
if (f[0] === "(" && f[f.length - 1] === ")") {
const [x, y] = f.substr(1, f.length - 2).split(",").map(f => parseFloat(f));
return { x, y };
}
},
unmap: o => sql.fragment`point(${sql.value(o.x)}, ${sql.value(o.y)})`
};
// TODO: add more support for geometric types
let depth = 0;

@@ -373,0 +427,0 @@ const enforceGqlTypeByPgType = type => {

@@ -315,3 +315,3 @@ "use strict";

if (addNullCase) {
buildObject = sql.fragment`(case when ${this.getTableAlias()} is null then null else ${buildObject} end)`;
buildObject = sql.fragment`(case when ${this.getTableAlias()} is not distinct from null then null else ${buildObject} end)`;
}

@@ -318,0 +318,0 @@ return buildObject;

@@ -6,7 +6,7 @@ "use strict";

});
exports.upperCamelCase = exports.constantCase = exports.camelCase = exports.upperFirst = exports.formatInsideUnderscores = exports.constantCaseAll = exports.sqlJsonBuildObjectFromFragments = undefined;
exports.parseTags = exports.upperCamelCase = exports.constantCase = exports.camelCase = exports.upperFirst = exports.formatInsideUnderscores = exports.constantCaseAll = undefined;
var _pgSql = require("pg-sql2");
var _assign = require("babel-runtime/core-js/object/assign");
var _pgSql2 = _interopRequireDefault(_pgSql);
var _assign2 = _interopRequireDefault(_assign);

@@ -23,8 +23,2 @@ var _upperFirst = require("lodash/upperFirst");

const sqlJsonBuildObjectFromFragments = exports.sqlJsonBuildObjectFromFragments = fragments => {
return _pgSql2.default.fragment`
json_build_object(
${_pgSql2.default.join(fragments.map(({ sqlFragment, alias }) => _pgSql2.default.fragment`${_pgSql2.default.literal(alias)}, ${sqlFragment}`), ",\n")}
)`;
};
const constantCaseAll = exports.constantCaseAll = str => str.replace(/[^a-zA-Z0-9_]+/g, "_").replace(/[A-Z]+/g, "_$&").replace(/__+/g, "_").replace(/^[^a-zA-Z0-9]+/, "").replace(/^[0-9]/, "_$&") // GraphQL enums must not start with a number

@@ -46,2 +40,28 @@ .toUpperCase();

const upperCamelCase = exports.upperCamelCase = str => upperFirst(camelCase(str));
const parseTags = exports.parseTags = str => {
return str.split(`\n`).reduce((prev, curr) => {
if (prev.text !== "") {
return (0, _assign2.default)({}, prev, {
text: `${prev.text}\n${curr}`
});
}
const match = curr.match(/^@[a-zA-Z][a-zA-Z0-9_]*($|\s)/);
if (!match) {
return (0, _assign2.default)({}, prev, {
text: curr
});
}
const key = match[0].substr(1).trim();
const value = match[0] === curr ? true : curr.replace(match[0], "");
return (0, _assign2.default)({}, prev, {
tags: (0, _assign2.default)({}, prev.tags, {
[key]: !prev.tags.hasOwnProperty(key) ? value : Array.isArray(prev.tags[key]) ? [...prev.tags[key], value] : [prev.tags[key], value]
})
});
}, {
tags: {},
text: ""
});
};
//# sourceMappingURL=utils.js.map
{
"name": "graphile-build-pg",
"version": "0.1.0-alpha.36",
"version": "0.1.0-alpha.37",
"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.36",
"graphile-build": "^0.1.0-alpha.37",
"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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc