graphile-build-pg
Advanced tools
Comparing version 4.0.0-beta.7 to 4.0.0-beta.7.1
@@ -66,3 +66,4 @@ "use strict"; | ||
computed = false, | ||
isMutation = false | ||
isMutation = false, | ||
forceList = false | ||
}) { | ||
@@ -125,2 +126,5 @@ const { pluralize, camelCase } = inflection; | ||
type = new GraphQLList(TableType); | ||
} else if (forceList) { | ||
type = new GraphQLList(TableType); | ||
fieldScope.isPgFieldSimpleCollection = true; | ||
} else { | ||
@@ -149,18 +153,17 @@ const ConnectionType = getTypeByName(inflection.connection(TableType.name)); | ||
const ConnectionType = getTypeByName(connectionTypeName); | ||
if (ConnectionType) { | ||
if (isMutation) { | ||
// Cannot return a connection because it would have to run the mutation again | ||
type = new GraphQLList(Type); | ||
returnFirstValueAsValue = true; | ||
} else { | ||
type = new GraphQLNonNull(ConnectionType); | ||
fieldScope.isPgFieldConnection = true; | ||
// We don't return the first value as the value here because it gets | ||
// sent down into PgScalarFunctionConnectionPlugin so the relevant | ||
// EdgeType can return cursor / node; i.e. we might want to add an | ||
// `__cursor` field so we can't just use a scalar. | ||
} | ||
} else { | ||
if (isMutation) { | ||
// Cannot return a connection because it would have to run the mutation again | ||
type = new GraphQLList(Type); | ||
returnFirstValueAsValue = true; | ||
} else if (forceList || !ConnectionType) { | ||
type = new GraphQLList(Type); | ||
returnFirstValueAsValue = true; | ||
fieldScope.isPgFieldSimpleCollection = true; | ||
} else { | ||
type = new GraphQLNonNull(ConnectionType); | ||
fieldScope.isPgFieldConnection = true; | ||
// We don't return the first value as the value here because it gets | ||
// sent down into PgScalarFunctionConnectionPlugin so the relevant | ||
// EdgeType can return cursor / node; i.e. we might want to add an | ||
// `__cursor` field so we can't just use a scalar. | ||
} | ||
@@ -219,6 +222,6 @@ } else { | ||
const query = (0, _queryFromResolveData2.default)(sqlMutationQuery, functionAlias, resolveData, { | ||
withPagination: !isMutation && proc.returnsSet, | ||
withPaginationAsFields: !isMutation && proc.returnsSet && !computed, | ||
asJson: !proc.returnsSet && computed && !returnFirstValueAsValue, | ||
asJsonAggregate: !proc.returnsSet && computed && rawReturnType.isPgArray, | ||
withPagination: !forceList && !isMutation && proc.returnsSet, | ||
withPaginationAsFields: !forceList && !isMutation && proc.returnsSet && !computed, | ||
asJson: computed && (forceList || !proc.returnsSet && !returnFirstValueAsValue), | ||
asJsonAggregate: computed && (forceList || !proc.returnsSet && rawReturnType.isPgArray), | ||
addNullCase: !proc.returnsSet && !rawReturnType.isPgArray && isTableLike | ||
@@ -326,7 +329,7 @@ }, innerQueryBuilder => { | ||
if (returnFirstValueAsValue) { | ||
if (proc.returnsSet) { | ||
if (proc.returnsSet && !forceList) { | ||
// EITHER `isMutation` is true, or `ConnectionType` does not | ||
// exist - either way, we're not returning a connection. | ||
return value.data.map(firstValue).map(v => pg2gql(v, returnType)); | ||
} else if (rawReturnType.isPgArray) { | ||
} else if (proc.returnsSet || rawReturnType.isPgArray) { | ||
return value.map(firstValue).map(v => pg2gql(v, returnType)); | ||
@@ -337,3 +340,3 @@ } else { | ||
} else { | ||
if (proc.returnsSet && !isMutation) { | ||
if (proc.returnsSet && !isMutation && !forceList) { | ||
return (0, _addStartEndCursor2.default)({ | ||
@@ -379,3 +382,3 @@ ...value, | ||
if (returnFirstValueAsValue) { | ||
if (proc.returnsSet && !isMutation) { | ||
if (proc.returnsSet && !isMutation && !forceList) { | ||
// EITHER `isMutation` is true, or `ConnectionType` does | ||
@@ -391,3 +394,3 @@ // not exist - either way, we're not returning a | ||
} else { | ||
if (proc.returnsSet && !isMutation) { | ||
if (proc.returnsSet && !isMutation && !forceList) { | ||
// Connection | ||
@@ -394,0 +397,0 @@ return (0, _addStartEndCursor2.default)({ |
@@ -27,3 +27,5 @@ "use strict"; | ||
exports.default = async function PgAllRows(builder, { pgViewUniqueKey: viewUniqueKey }) { | ||
exports.default = async function PgAllRows(builder, { pgViewUniqueKey: viewUniqueKey, pgSimpleCollections }) { | ||
const hasConnections = pgSimpleCollections !== "only"; | ||
const hasSimpleCollections = pgSimpleCollections === "only" || pgSimpleCollections === "both"; | ||
builder.hook("GraphQLObjectType:fields", (fields, { | ||
@@ -36,3 +38,4 @@ parseResolveInfo, | ||
pgIntrospectionResultsByKind: introspectionResultsByKind, | ||
inflection | ||
inflection, | ||
graphql: { GraphQLList, GraphQLNonNull } | ||
}, { fieldWithHooks, scope: { isRootQuery } }) => { | ||
@@ -62,8 +65,8 @@ if (!isRootQuery) { | ||
const sqlFullTableName = sql.identifier(schema.name, table.name); | ||
if (TableType && ConnectionType) { | ||
const fieldName = inflection.allRows(table); | ||
function makeField(isConnection) { | ||
const fieldName = isConnection ? inflection.allRows(table) : inflection.allRowsSimple(table); | ||
memo[fieldName] = fieldWithHooks(fieldName, ({ getDataFromParsedResolveInfoFragment }) => { | ||
return { | ||
description: `Reads and enables pagination through a set of \`${tableTypeName}\`.`, | ||
type: ConnectionType, | ||
description: isConnection ? `Reads and enables pagination through a set of \`${tableTypeName}\`.` : `Reads a set of \`${tableTypeName}\`.`, | ||
type: isConnection ? ConnectionType : new GraphQLList(new GraphQLNonNull(TableType)), | ||
args: {}, | ||
@@ -74,3 +77,3 @@ async resolve(parent, args, { pgClient }, resolveInfo) { | ||
const query = (0, _queryFromResolveData2.default)(sqlFullTableName, undefined, resolveData, { | ||
withPaginationAsFields: true | ||
withPaginationAsFields: isConnection | ||
}, builder => { | ||
@@ -100,11 +103,23 @@ if (primaryKeys) { | ||
if (debugSql.enabled) debugSql(text); | ||
const { rows: [row] } = await pgClient.query(text, values); | ||
return (0, _addStartEndCursor2.default)(row); | ||
const result = await pgClient.query(text, values); | ||
if (isConnection) { | ||
const { rows: [row] } = result; | ||
return (0, _addStartEndCursor2.default)(row); | ||
} else { | ||
return result.rows; | ||
} | ||
} | ||
}; | ||
}, { | ||
isPgFieldConnection: true, | ||
isPgFieldConnection: isConnection, | ||
isPgFieldSimpleCollection: !isConnection, | ||
pgFieldIntrospection: table | ||
}); | ||
} | ||
if (TableType && ConnectionType && hasConnections) { | ||
makeField(true); | ||
} | ||
if (TableType && hasSimpleCollections) { | ||
makeField(false); | ||
} | ||
return memo; | ||
@@ -111,0 +126,0 @@ }, {}), `Adding 'all*' relations to root Query`); |
@@ -31,3 +31,5 @@ "use strict"; | ||
exports.default = function PgBackwardRelationPlugin(builder, { pgLegacyRelations }) { | ||
exports.default = function PgBackwardRelationPlugin(builder, { pgLegacyRelations, pgSimpleCollections }) { | ||
const hasConnections = pgSimpleCollections !== "only"; | ||
const hasSimpleCollections = pgSimpleCollections === "only" || pgSimpleCollections === "both"; | ||
const legacyRelationMode = { | ||
@@ -44,3 +46,3 @@ only: ONLY, | ||
getAliasFromResolveInfo, | ||
graphql: { GraphQLNonNull }, | ||
graphql: { GraphQLNonNull, GraphQLList }, | ||
inflection | ||
@@ -100,3 +102,2 @@ }, { | ||
const manyRelationFieldName = inflection.manyRelationByKeys(keys, table, foreignTable, constraint); | ||
const singleRelationFieldName = isUnique ? inflection.singleRelationByKeys(keys, table, foreignTable, constraint) : null; | ||
@@ -147,55 +148,79 @@ | ||
} | ||
if (shouldAddManyRelation && !(0, _omit2.default)(table, "many")) { | ||
memo[manyRelationFieldName] = fieldWithHooks(manyRelationFieldName, ({ getDataFromParsedResolveInfoFragment, addDataGenerator }) => { | ||
addDataGenerator(parsedResolveInfoFragment => { | ||
return { | ||
pgQuery: queryBuilder => { | ||
queryBuilder.select(() => { | ||
const resolveData = getDataFromParsedResolveInfoFragment(parsedResolveInfoFragment, ConnectionType); | ||
const tableAlias = sql.identifier(Symbol()); | ||
const foreignTableAlias = queryBuilder.getTableAlias(); | ||
const query = (0, _queryFromResolveData2.default)(sql.identifier(schema.name, table.name), tableAlias, resolveData, { | ||
withPagination: true, | ||
withPaginationAsFields: false | ||
}, innerQueryBuilder => { | ||
if (primaryKeys) { | ||
innerQueryBuilder.beforeLock("orderBy", () => { | ||
// append order by primary key to the list of orders | ||
if (!innerQueryBuilder.isOrderUnique(false)) { | ||
innerQueryBuilder.data.cursorPrefix = ["primary_key_asc"]; | ||
primaryKeys.forEach(key => { | ||
innerQueryBuilder.orderBy(sql.fragment`${innerQueryBuilder.getTableAlias()}.${sql.identifier(key.name)}`, true); | ||
}); | ||
innerQueryBuilder.setOrderIsUnique(); | ||
} | ||
function makeFields(isConnection) { | ||
if (isUnique && !isConnection) { | ||
// Don't need this, use the singular instead | ||
return; | ||
} | ||
if (shouldAddManyRelation && !(0, _omit2.default)(table, "many")) { | ||
const manyRelationFieldName = isConnection ? inflection.manyRelationByKeys(keys, table, foreignTable, constraint) : inflection.manyRelationByKeysSimple(keys, table, foreignTable, constraint); | ||
memo[manyRelationFieldName] = fieldWithHooks(manyRelationFieldName, ({ | ||
getDataFromParsedResolveInfoFragment, | ||
addDataGenerator | ||
}) => { | ||
addDataGenerator(parsedResolveInfoFragment => { | ||
return { | ||
pgQuery: queryBuilder => { | ||
queryBuilder.select(() => { | ||
const resolveData = getDataFromParsedResolveInfoFragment(parsedResolveInfoFragment, isConnection ? ConnectionType : TableType); | ||
const tableAlias = sql.identifier(Symbol()); | ||
const foreignTableAlias = queryBuilder.getTableAlias(); | ||
const query = (0, _queryFromResolveData2.default)(sql.identifier(schema.name, table.name), tableAlias, resolveData, { | ||
withPagination: isConnection, | ||
withPaginationAsFields: false, | ||
asJsonAggregate: !isConnection | ||
}, innerQueryBuilder => { | ||
if (primaryKeys) { | ||
innerQueryBuilder.beforeLock("orderBy", () => { | ||
// append order by primary key to the list of orders | ||
if (!innerQueryBuilder.isOrderUnique(false)) { | ||
innerQueryBuilder.data.cursorPrefix = ["primary_key_asc"]; | ||
primaryKeys.forEach(key => { | ||
innerQueryBuilder.orderBy(sql.fragment`${innerQueryBuilder.getTableAlias()}.${sql.identifier(key.name)}`, true); | ||
}); | ||
innerQueryBuilder.setOrderIsUnique(); | ||
} | ||
}); | ||
} | ||
keys.forEach((key, i) => { | ||
innerQueryBuilder.where(sql.fragment`${tableAlias}.${sql.identifier(key.name)} = ${foreignTableAlias}.${sql.identifier(foreignKeys[i].name)}`); | ||
}); | ||
} | ||
keys.forEach((key, i) => { | ||
innerQueryBuilder.where(sql.fragment`${tableAlias}.${sql.identifier(key.name)} = ${foreignTableAlias}.${sql.identifier(foreignKeys[i].name)}`); | ||
}); | ||
}); | ||
return sql.fragment`(${query})`; | ||
}, parsedResolveInfoFragment.alias); | ||
} | ||
return sql.fragment`(${query})`; | ||
}, parsedResolveInfoFragment.alias); | ||
} | ||
}; | ||
}); | ||
const ConnectionType = getTypeByName(inflection.connection(gqlTableType.name)); | ||
const TableType = pgGetGqlTypeByTypeId(table.type.id); | ||
return { | ||
description: `Reads and enables pagination through a set of \`${tableTypeName}\`.`, | ||
type: isConnection ? new GraphQLNonNull(ConnectionType) : new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(TableType))), | ||
args: {}, | ||
resolve: (data, _args, _context, resolveInfo) => { | ||
const alias = getAliasFromResolveInfo(resolveInfo); | ||
if (isConnection) { | ||
return (0, _addStartEndCursor2.default)(data[alias]); | ||
} else { | ||
return data[alias]; | ||
} | ||
}, | ||
deprecationReason: isDeprecated ? // $FlowFixMe | ||
`Please use ${singleRelationFieldName} instead` : undefined | ||
}; | ||
}, { | ||
isPgFieldConnection: isConnection, | ||
isPgFieldSimpleCollection: !isConnection, | ||
isPgBackwardRelationField: true, | ||
pgFieldIntrospection: table | ||
}); | ||
const ConnectionType = getTypeByName(inflection.connection(gqlTableType.name)); | ||
return { | ||
description: `Reads and enables pagination through a set of \`${tableTypeName}\`.`, | ||
type: new GraphQLNonNull(ConnectionType), | ||
args: {}, | ||
resolve: (data, _args, _context, resolveInfo) => { | ||
const alias = getAliasFromResolveInfo(resolveInfo); | ||
return (0, _addStartEndCursor2.default)(data[alias]); | ||
}, | ||
deprecationReason: isDeprecated ? // $FlowFixMe | ||
`Please use ${singleRelationFieldName} instead` : undefined | ||
}; | ||
}, { | ||
isPgFieldConnection: true, | ||
isPgBackwardRelationField: true, | ||
pgFieldIntrospection: table | ||
}); | ||
} | ||
} | ||
if (hasConnections) { | ||
makeFields(true); | ||
} | ||
if (hasSimpleCollections) { | ||
makeFields(false); | ||
} | ||
return memo; | ||
@@ -202,0 +227,0 @@ }, {}), `Adding backward relations for ${Self.name}`); |
@@ -199,2 +199,5 @@ "use strict"; | ||
}, | ||
allRowsSimple(table) { | ||
return this.camelCase(`all-${this.pluralize(this._singularizedTableName(table))}-list`); | ||
}, | ||
functionMutationName(proc) { | ||
@@ -206,2 +209,5 @@ return this.camelCase(this._functionName(proc)); | ||
}, | ||
functionQueryNameList(proc) { | ||
return this.camelCase(`${this._functionName(proc)}-list`); | ||
}, | ||
functionPayloadType(proc) { | ||
@@ -222,2 +228,5 @@ return this.upperCamelCase(`${this._functionName(proc)}-payload`); | ||
}, | ||
computedColumnList(pseudoColumnName, proc, _table) { | ||
return proc.tags.fieldName ? proc.tags.fieldName + "List" : this.camelCase(`${pseudoColumnName}-list`); | ||
}, | ||
singleRelationByKeys(detailedKeys, table, _foreignTable, constraint) { | ||
@@ -235,2 +244,8 @@ if (constraint.tags.fieldName) { | ||
}, | ||
manyRelationByKeysSimple(detailedKeys, table, _foreignTable, constraint) { | ||
if (constraint.tags.foreignFieldName) { | ||
return constraint.tags.foreignFieldName; | ||
} | ||
return this.camelCase(`${this.pluralize(this._singularizedTableName(table))}-by-${detailedKeys.map(key => this.column(key)).join("-and-")}-list`); | ||
}, | ||
rowByUniqueKeys(detailedKeys, table, constraint) { | ||
@@ -237,0 +252,0 @@ if (constraint.tags.fieldName) { |
@@ -17,3 +17,5 @@ "use strict"; | ||
exports.default = function PgComputedColumnsPlugin(builder) { | ||
exports.default = function PgComputedColumnsPlugin(builder, { pgSimpleCollections }) { | ||
const hasConnections = pgSimpleCollections !== "only"; | ||
const hasSimpleCollections = pgSimpleCollections === "only" || pgSimpleCollections === "both"; | ||
builder.hook("GraphQLObjectType:fields", (fields, build, { | ||
@@ -63,7 +65,16 @@ scope: { | ||
const pseudoColumnName = proc.name.substr(table.name.length + 1); | ||
const fieldName = inflection.computedColumn(pseudoColumnName, proc, table); | ||
memo[fieldName] = (0, _makeProcField2.default)(fieldName, proc, build, { | ||
fieldWithHooks, | ||
computed: true | ||
}); | ||
function makeField(forceList) { | ||
const fieldName = forceList ? inflection.computedColumnList(pseudoColumnName, proc, table) : inflection.computedColumn(pseudoColumnName, proc, table); | ||
memo[fieldName] = (0, _makeProcField2.default)(fieldName, proc, build, { | ||
fieldWithHooks, | ||
computed: true, | ||
forceList | ||
}); | ||
} | ||
if (!proc.returnsSet || hasConnections) { | ||
makeField(false); | ||
} | ||
if (proc.returnsSet && hasSimpleCollections) { | ||
makeField(true); | ||
} | ||
return memo; | ||
@@ -70,0 +81,0 @@ }, {}), `Adding computed column to '${Self.name}'`); |
@@ -61,3 +61,7 @@ "use strict"; | ||
const { | ||
scope: { isPgFieldConnection, pgFieldIntrospection: table }, | ||
scope: { | ||
isPgFieldConnection, | ||
isPgFieldSimpleCollection, | ||
pgFieldIntrospection: table | ||
}, | ||
addArgDataGenerator, | ||
@@ -67,3 +71,4 @@ Self, | ||
} = context; | ||
if (!isPgFieldConnection || !table || table.kind !== "class" || !table.namespace || (0, _omit2.default)(table, "filter")) { | ||
const shouldAddCondition = isPgFieldConnection || isPgFieldSimpleCollection; | ||
if (!shouldAddCondition || !table || table.kind !== "class" || !table.namespace || (0, _omit2.default)(table, "filter")) { | ||
return args; | ||
@@ -74,2 +79,4 @@ } | ||
const relevantAttributes = introspectionResultsByKind.attribute.filter(attr => attr.classId === table.id).filter(attr => pgColumnFilter(attr, build, context)).filter(attr => !(0, _omit2.default)(attr, "filter")); | ||
addArgDataGenerator(function connectionCondition({ condition }) { | ||
@@ -79,3 +86,3 @@ return { | ||
if (condition != null) { | ||
introspectionResultsByKind.attribute.filter(attr => attr.classId === table.id).filter(attr => pgColumnFilter(attr, build, context)).filter(attr => !(0, _omit2.default)(attr, "filter")).forEach(attr => { | ||
relevantAttributes.forEach(attr => { | ||
const fieldName = inflection.column(attr); | ||
@@ -82,0 +89,0 @@ const val = condition[fieldName]; |
@@ -12,3 +12,7 @@ "use strict"; | ||
builder.hook("GraphQLObjectType:fields:field:args", (args, { extend, getTypeByName, graphql: { GraphQLInt } }, { | ||
scope: { isPgFieldConnection, pgFieldIntrospection: source }, | ||
scope: { | ||
isPgFieldConnection, | ||
isPgFieldSimpleCollection, | ||
pgFieldIntrospection: source | ||
}, | ||
addArgDataGenerator, | ||
@@ -18,3 +22,3 @@ field, | ||
}) => { | ||
if (!isPgFieldConnection || !source || source.kind !== "class" && source.kind !== "procedure") { | ||
if (!(isPgFieldConnection || isPgFieldSimpleCollection) || !source || source.kind !== "class" && source.kind !== "procedure") { | ||
return args; | ||
@@ -33,8 +37,2 @@ } | ||
pgQuery: queryBuilder => { | ||
if (after != null) { | ||
addCursorConstraint(after, true); | ||
} | ||
if (before != null) { | ||
addCursorConstraint(before, false); | ||
} | ||
if (first != null) { | ||
@@ -46,10 +44,18 @@ queryBuilder.first(first); | ||
} | ||
if (last != null) { | ||
if (first != null) { | ||
throw new Error("We don't support setting both first and last"); | ||
if (isPgFieldConnection) { | ||
if (after != null) { | ||
addCursorConstraint(after, true); | ||
} | ||
if (offset != null) { | ||
throw new Error("We don't support setting both offset and last"); | ||
if (before != null) { | ||
addCursorConstraint(before, false); | ||
} | ||
queryBuilder.last(last); | ||
if (last != null) { | ||
if (first != null) { | ||
throw new Error("We don't support setting both first and last"); | ||
} | ||
if (offset != null) { | ||
throw new Error("We don't support setting both offset and last"); | ||
} | ||
queryBuilder.last(last); | ||
} | ||
} | ||
@@ -70,21 +76,25 @@ | ||
}, | ||
last: { | ||
description: "Only read the last `n` values of the set.", | ||
type: GraphQLInt | ||
}, | ||
...(isPgFieldConnection ? { | ||
last: { | ||
description: "Only read the last `n` values of the set.", | ||
type: GraphQLInt | ||
} | ||
} : null), | ||
offset: { | ||
description: "Skip the first `n` values from our `after` cursor, an alternative to cursor based pagination. May not be used with `last`.", | ||
description: isPgFieldConnection ? "Skip the first `n` values from our `after` cursor, an alternative to cursor based pagination. May not be used with `last`." : "Skip the first `n` values.", | ||
type: GraphQLInt | ||
}, | ||
before: { | ||
description: "Read all values in the set before (above) this cursor.", | ||
type: Cursor | ||
}, | ||
after: { | ||
description: "Read all values in the set after (below) this cursor.", | ||
type: Cursor | ||
} | ||
}, `Adding connection pagination args to field '${field.name}' of '${Self.name}'`); | ||
...(isPgFieldConnection ? { | ||
before: { | ||
description: "Read all values in the set before (above) this cursor.", | ||
type: Cursor | ||
}, | ||
after: { | ||
description: "Read all values in the set after (below) this cursor.", | ||
type: Cursor | ||
} | ||
} : null) | ||
}, isPgFieldConnection ? `Adding connection pagination args to field '${field.name}' of '${Self.name}'` : `Adding simple collection args to field '${field.name}' of '${Self.name}'`); | ||
}); | ||
}; | ||
//# sourceMappingURL=PgConnectionArgFirstLastBeforeAfter.js.map |
@@ -53,3 +53,7 @@ "use strict"; | ||
}, { | ||
scope: { isPgFieldConnection, pgFieldIntrospection: table }, | ||
scope: { | ||
isPgFieldConnection, | ||
isPgFieldSimpleCollection, | ||
pgFieldIntrospection: table | ||
}, | ||
addArgDataGenerator, | ||
@@ -59,3 +63,4 @@ Self, | ||
}) => { | ||
if (!isPgFieldConnection || !table || table.kind !== "class" || !table.namespace || !table.isSelectable || (0, _omit2.default)(table, "order")) { | ||
const shouldAddOrderBy = isPgFieldConnection || isPgFieldSimpleCollection; | ||
if (!shouldAddOrderBy || !table || table.kind !== "class" || !table.namespace || !table.isSelectable || (0, _omit2.default)(table, "order")) { | ||
return args; | ||
@@ -66,2 +71,16 @@ } | ||
const TableOrderByType = getTypeByName(inflection.orderByType(tableTypeName)); | ||
const cursorPrefixFromOrderBy = orderBy => { | ||
if (orderBy) { | ||
let cursorPrefixes = []; | ||
for (const item of orderBy) { | ||
if (item.alias) { | ||
cursorPrefixes.push(sql.literal(item.alias)); | ||
} | ||
} | ||
if (cursorPrefixes.length > 0) { | ||
return cursorPrefixes; | ||
} | ||
} | ||
return null; | ||
}; | ||
@@ -71,3 +90,3 @@ addArgDataGenerator(function connectionOrderBy({ orderBy: rawOrderBy }) { | ||
return { | ||
pgCursorPrefix: orderBy && orderBy.some(item => item.alias) ? orderBy.filter(item => item.alias).map(item => sql.literal(item.alias)) : null, | ||
pgCursorPrefix: cursorPrefixFromOrderBy(orderBy), | ||
pgQuery: queryBuilder => { | ||
@@ -74,0 +93,0 @@ if (orderBy != null) { |
@@ -27,3 +27,5 @@ "use strict"; | ||
exports.default = function PgQueryProceduresPlugin(builder) { | ||
exports.default = function PgQueryProceduresPlugin(builder, { pgSimpleCollections }) { | ||
const hasConnections = pgSimpleCollections !== "only"; | ||
const hasSimpleCollections = pgSimpleCollections === "only" || pgSimpleCollections === "both"; | ||
builder.hook("GraphQLObjectType:fields", (fields, build, { scope: { isRootQuery }, fieldWithHooks }) => { | ||
@@ -64,12 +66,21 @@ if (!isRootQuery) { | ||
const fieldName = inflection.functionQueryName(proc); | ||
try { | ||
memo[fieldName] = (0, _makeProcField2.default)(fieldName, proc, build, { | ||
fieldWithHooks | ||
}); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.warn(_chalk2.default.bold.yellow(`Failed to add function '${proc.namespace.name}.${proc.name}'; run with 'DEBUG="graphile-build-pg:warn"' to view the error`)); | ||
debugWarn(e); | ||
function makeField(forceList) { | ||
const fieldName = forceList ? inflection.functionQueryNameList(proc) : inflection.functionQueryName(proc); | ||
try { | ||
memo[fieldName] = (0, _makeProcField2.default)(fieldName, proc, build, { | ||
fieldWithHooks, | ||
forceList | ||
}); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.warn(_chalk2.default.bold.yellow(`Failed to add function '${proc.namespace.name}.${proc.name}'; run with 'DEBUG="graphile-build-pg:warn"' to view the error`)); | ||
debugWarn(e); | ||
} | ||
} | ||
if (!proc.returnsSet || hasConnections) { | ||
makeField(false); | ||
} | ||
if (proc.returnsSet && hasSimpleCollections) { | ||
makeField(true); | ||
} | ||
return memo; | ||
@@ -76,0 +87,0 @@ }, {}), `Adding query procedures to root Query type`); |
@@ -9,5 +9,20 @@ "use strict"; | ||
const hasNonNullKey = row => { | ||
if (Array.isArray(row.__identifiers) && row.__identifiers.every(i => i != null)) { | ||
return true; | ||
} | ||
for (const k in row) { | ||
if (row.hasOwnProperty(k)) { | ||
if ((k[0] !== "_" || k[1] !== "_") && row[k] !== null) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
exports.default = function PgTablesPlugin(builder, { pgForbidSetofFunctionsToReturnNull = false }) { | ||
const handleNullRow = pgForbidSetofFunctionsToReturnNull ? row => row : row => { | ||
if (Object.keys(row).filter(str => !str.startsWith("__")).some(key => row[key] !== null) || Array.isArray(row.__identifiers) && row.__identifiers.every(i => i != null)) { | ||
if (hasNonNullKey(row)) { | ||
return row; | ||
@@ -14,0 +29,0 @@ } else { |
@@ -21,2 +21,4 @@ "use strict"; | ||
const identity = _ => _ !== null && _ !== undefined; | ||
exports.default = (from, fromAlias, resolveData, options, withBuilder) => { | ||
@@ -33,3 +35,3 @@ const { | ||
const usesCursor = explicitlyUsesCursor && explicitlyUsesCursor.length > 0 || calculateHasNextPage && calculateHasNextPage.length > 0 || calculateHasPreviousPage && calculateHasPreviousPage.length > 0 || false; | ||
const rawCursorPrefix = reallyRawCursorPrefix && reallyRawCursorPrefix.filter(_ => _); | ||
const rawCursorPrefix = reallyRawCursorPrefix && reallyRawCursorPrefix.filter(identity); | ||
@@ -36,0 +38,0 @@ const queryBuilder = new _QueryBuilder2.default(); |
{ | ||
"name": "graphile-build-pg", | ||
"version": "4.0.0-beta.7", | ||
"version": "4.0.0-beta.7.1", | ||
"description": "Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build", | ||
@@ -39,3 +39,3 @@ "main": "node8plus/index.js", | ||
"debug": ">=2 <3", | ||
"graphile-build": "4.0.0-beta.7", | ||
"graphile-build": "4.0.0-beta.7.1", | ||
"graphql-iso-date": "^3.2.0", | ||
@@ -42,0 +42,0 @@ "jsonwebtoken": "^8.1.1", |
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
995621
5409
+ Addedgraphile-build@4.0.0-beta.7.1(transitive)
+ Addedgraphql-parse-resolve-info@4.0.0-beta.7.1(transitive)
- Removedgraphile-build@4.0.0-beta.7(transitive)
- Removedgraphql-parse-resolve-info@4.0.0-beta.7(transitive)