graphile-build-pg
Advanced tools
Comparing version 4.0.0-rc.2 to 4.0.0-rc.3
@@ -210,3 +210,6 @@ "use strict"; | ||
const value = args[gqlArgName]; | ||
const sqlValue = gql2pg(value, argTypes[argIndex]); | ||
const variant = variantFromTags(proc.tags, argIndex) || variantFromName(argNames[argIndex], type); | ||
const sqlValue = gql2pg(value, argTypes[argIndex], variant); | ||
if (argIndex + 1 > requiredArgCount && haveNames && value == null) { | ||
@@ -213,0 +216,0 @@ // No need to pass argument to function |
@@ -67,3 +67,3 @@ "use strict"; | ||
const tableEntity = entity; | ||
if ((permission === _omit.READ || permission === _omit.ALL || permission === _omit.MANY) && !tableEntity.aclSelectable) { | ||
if ((permission === _omit.READ || permission === _omit.ALL || permission === _omit.MANY) && !tableEntity.aclSelectable && !tableEntity.attributes.some(attr => attr.aclSelectable)) { | ||
return true; | ||
@@ -70,0 +70,0 @@ } else if (permission === _omit.CREATE && !tableEntity.aclInsertable && !tableEntity.attributes.some(attr => attr.aclInsertable)) { |
@@ -130,3 +130,3 @@ "use strict"; | ||
type: nullableIf(GraphQLNonNull, isPgBaseInput || isPgPatch || !attr.isNotNull && !attr.type.domainIsNotNull || attr.hasDefault, pgGetGqlInputTypeByTypeIdAndModifier(attr.typeId, attr.typeModifier) || GraphQLString) | ||
}), { pgFieldIntrospection: attr }); | ||
}, attr.typeModifier), { pgFieldIntrospection: attr }); | ||
return memo; | ||
@@ -133,0 +133,0 @@ }, {}), `Adding columns to input object '${Self.name}'`); |
@@ -83,3 +83,3 @@ "use strict"; | ||
if (val != null) { | ||
queryBuilder.where(sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(attr.name)} = ${gql2pg(val, attr.type)}`); | ||
queryBuilder.where(sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(attr.name)} = ${gql2pg(val, attr.type, attr.typeModifier)}`); | ||
} else if (val === null) { | ||
@@ -86,0 +86,0 @@ queryBuilder.where(sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(attr.name)} IS NULL`); |
@@ -125,3 +125,3 @@ "use strict"; | ||
sqlColumns.push(sql.identifier(attr.name)); | ||
sqlValues.push(gql2pg(val, attr.type)); | ||
sqlValues.push(gql2pg(val, attr.type, attr.typeModifier)); | ||
} | ||
@@ -128,0 +128,0 @@ }); |
@@ -69,3 +69,3 @@ "use strict"; | ||
const inputData = input[inflection.patchField(inflection.tableFieldName(table))]; | ||
introspectionResultsByKind.attribute.filter(attr => attr.classId === table.id).filter(attr => pgColumnFilter(attr, build, context)).forEach(attr => { | ||
introspectionResultsByKind.attribute.filter(attr => attr.classId === table.id).filter(attr => pgColumnFilter(attr, build, context)).filter(attr => !omit(attr, "update")).forEach(attr => { | ||
const fieldName = inflection.column(attr); | ||
@@ -76,3 +76,3 @@ if (fieldName in inputData /* Because we care about null! */ | ||
sqlColumns.push(sql.identifier(attr.name)); | ||
sqlValues.push(gql2pg(val, attr.type)); | ||
sqlValues.push(gql2pg(val, attr.type, attr.typeModifier)); | ||
} | ||
@@ -175,3 +175,3 @@ }); | ||
} | ||
const primaryKeys = primaryKeyConstraint && primaryKeyConstraint.keyAttributeNums.map(num => attributes.filter(attr => attr.num === num)[0]); | ||
const primaryKeys = primaryKeyConstraint && primaryKeyConstraint.keyAttributeNums.map(num => attributes.find(attr => attr.num === num)); | ||
const fieldName = inflection[mode === "update" ? "updateNode" : "deleteNode"](table); | ||
@@ -227,3 +227,3 @@ const InputType = newWithHooks(GraphQLInputObjectType, { | ||
return commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(primaryKeys.map((key, idx) => sql.fragment`${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], key.type)}`), ") and (")})`, context); | ||
return commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(primaryKeys.map((key, idx) => sql.fragment`${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], key.type, key.typeModifier)}`), ") and (")})`, context); | ||
} catch (e) { | ||
@@ -247,3 +247,3 @@ debug(e); | ||
} | ||
const keys = constraint.keyAttributeNums.map(num => attributes.filter(attr => attr.num === num)[0]); | ||
const keys = constraint.keyAttributeNums.map(num => attributes.find(attr => attr.num === num)); | ||
if (!keys.every(_ => _)) { | ||
@@ -296,3 +296,3 @@ throw new Error("Consistency error: could not find an attribute!"); | ||
async resolve(parent, { input }, { pgClient }, resolveInfo) { | ||
return commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(keys.map(key => sql.fragment`${sql.identifier(key.name)} = ${gql2pg(input[inflection.column(key)], key.type)}`), ") and (")})`, context); | ||
return commonCodeRenameMe(pgClient, resolveInfo, getDataFromParsedResolveInfoFragment, PayloadType, input, sql.fragment`(${sql.join(keys.map(key => sql.fragment`${sql.identifier(key.name)} = ${gql2pg(input[inflection.column(key)], key.type, key.typeModifier)}`), ") and (")})`, context); | ||
} | ||
@@ -299,0 +299,0 @@ }; |
@@ -44,3 +44,3 @@ "use strict"; | ||
} | ||
const keys = constraint.keyAttributeNums.map(num => attributes.filter(attr => attr.num === num)[0]); | ||
const keys = constraint.keyAttributeNums.map(num => attributes.find(attr => attr.num === num)); | ||
if (keys.some(key => omit(key, "read"))) { | ||
@@ -71,3 +71,3 @@ return; | ||
keys.forEach(key => { | ||
builder.where(sql.fragment`${builder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(args[inflection.column(key)], key.type)}`); | ||
builder.where(sql.fragment`${builder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(args[inflection.column(key)], key.type, key.typeModifier)}`); | ||
}); | ||
@@ -74,0 +74,0 @@ }); |
@@ -43,3 +43,3 @@ "use strict"; | ||
primaryKeys.forEach((key, idx) => { | ||
builder.where(sql.fragment`${builder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], primaryKeys[idx].type)}`); | ||
builder.where(sql.fragment`${builder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], primaryKeys[idx].type, primaryKeys[idx].typeModifier)}`); | ||
}); | ||
@@ -111,3 +111,3 @@ }); | ||
primaryKeys.forEach((key, idx) => { | ||
builder.where(sql.fragment`${builder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], primaryKeys[idx].type)}`); | ||
builder.where(sql.fragment`${builder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], primaryKeys[idx].type, primaryKeys[idx].typeModifier)}`); | ||
}); | ||
@@ -114,0 +114,0 @@ }); |
@@ -54,3 +54,2 @@ "use strict"; | ||
}, | ||
pgColumnFilter, | ||
inflection | ||
@@ -132,28 +131,8 @@ } = build; | ||
cb(TableType); | ||
const pgInputFields = {}; | ||
const pgCreateInputFields = {}; | ||
const pgPatchInputFields = {}; | ||
const pgBaseInputFields = {}; | ||
newWithHooks(GraphQLInputObjectType, { | ||
description: `An input for mutations affecting \`${tableTypeName}\``, | ||
name: inflection.inputType(TableType), | ||
fields: context => { | ||
pg2GqlMapper[tablePgType.id] = { | ||
map: _ => _, | ||
unmap: obj => { | ||
return sql.fragment`row(${sql.join(attributes.map(attr => { | ||
if (!pgColumnFilter(attr, build, context)) { | ||
return sql.null; // TODO: return default instead. | ||
} | ||
const fieldName = inflection.column(attr); | ||
const pgInputField = pgInputFields[fieldName]; | ||
const v = obj[fieldName]; | ||
if (pgInputField && v != null) { | ||
const { type } = pgInputField; | ||
return sql.fragment`${gql2pg(v, type)}::${sql.identifier(type.namespaceName, type.name)}`; | ||
} else { | ||
return sql.null; // TODO: return default instead. | ||
} | ||
}), ",")})::${sql.identifier(tablePgType.namespaceName, tablePgType.name)}`; | ||
} | ||
}; | ||
return {}; | ||
} | ||
name: inflection.inputType(TableType) | ||
}, { | ||
@@ -164,6 +143,7 @@ pgIntrospection: table, | ||
isPgCompoundType: !table.isSelectable, | ||
pgAddSubfield(fieldName, attrName, pgType, spec) { | ||
pgInputFields[fieldName] = { | ||
pgAddSubfield(fieldName, attrName, pgType, spec, typeModifier) { | ||
pgCreateInputFields[fieldName] = { | ||
name: attrName, | ||
type: pgType | ||
type: pgType, | ||
typeModifier | ||
}; | ||
@@ -189,4 +169,8 @@ return spec; | ||
isPgPatch: true, | ||
pgAddSubfield(fieldName, _attrName, _type, spec) { | ||
// We don't use this currently | ||
pgAddSubfield(fieldName, attrName, pgType, spec, typeModifier) { | ||
pgPatchInputFields[fieldName] = { | ||
name: attrName, | ||
type: pgType, | ||
typeModifier | ||
}; | ||
return spec; | ||
@@ -204,4 +188,8 @@ } | ||
isPgBaseInput: true, | ||
pgAddSubfield(fieldName, _attrName, _type, spec) { | ||
// We don't use this currently | ||
pgAddSubfield(fieldName, attrName, pgType, spec, typeModifier) { | ||
pgBaseInputFields[fieldName] = { | ||
name: attrName, | ||
type: pgType, | ||
typeModifier | ||
}; | ||
return spec; | ||
@@ -212,2 +200,31 @@ } | ||
pg2GqlMapper[tablePgType.id] = { | ||
map: _ => _, | ||
unmap: (obj, modifier) => { | ||
let fieldLookup; | ||
if (modifier === "patch") { | ||
fieldLookup = pgPatchInputFields; | ||
} else if (modifier === "base") { | ||
fieldLookup = pgBaseInputFields; | ||
} else { | ||
fieldLookup = pgCreateInputFields; | ||
} | ||
const attr2sql = attr => { | ||
// TODO: this should use `fieldInput[*].name` to find the attribute | ||
const fieldName = inflection.column(attr); | ||
const inputField = fieldLookup[fieldName]; | ||
const v = obj[fieldName]; | ||
if (inputField && v != null) { | ||
const { type, typeModifier } = inputField; | ||
return sql.fragment`${gql2pg(v, type, typeModifier)}::${sql.identifier(type.namespaceName, type.name)}`; | ||
} else { | ||
return sql.null; // TODO: return default instead. | ||
} | ||
}; | ||
return sql.fragment`row(${sql.join(attributes.map(attr2sql), ",")})::${sql.identifier(tablePgType.namespaceName, tablePgType.name)}`; | ||
} | ||
}; | ||
const EdgeType = newWithHooks(GraphQLObjectType, { | ||
@@ -214,0 +231,0 @@ description: `A \`${tableTypeName}\` edge in the connection.`, |
@@ -124,3 +124,15 @@ "use strict"; | ||
}; | ||
const gql2pg = (val, type) => { | ||
const gql2pg = (val, type, modifier) => { | ||
if (modifier === undefined) { | ||
let stack; | ||
try { | ||
throw new Error(); | ||
} catch (e) { | ||
stack = e.stack; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.warn("gql2pg should be called with three arguments, the third being the type modifier (or `null`); " + (stack || "")); | ||
// Hack for backwards compatibility: | ||
modifier = null; | ||
} | ||
if (val == null) { | ||
@@ -130,5 +142,5 @@ return sql.null; | ||
if (pg2GqlMapper[type.id]) { | ||
return pg2GqlMapper[type.id].unmap(val); | ||
return pg2GqlMapper[type.id].unmap(val, modifier); | ||
} else if (type.domainBaseType) { | ||
return gql2pg(val, type.domainBaseType); | ||
return gql2pg(val, type.domainBaseType, type.domainTypeModifier); | ||
} else if (type.isPgArray) { | ||
@@ -138,3 +150,3 @@ if (!Array.isArray(val)) { | ||
} | ||
return sql.fragment`array[${sql.join(val.map(v => gql2pg(v, type.arrayItemType)), ", ")}]::${sql.identifier(type.namespaceName)}.${sql.identifier(type.name)}`; | ||
return sql.fragment`array[${sql.join(val.map(v => gql2pg(v, type.arrayItemType, modifier)), ", ")}]::${sql.identifier(type.namespaceName)}.${sql.identifier(type.name)}`; | ||
} else { | ||
@@ -144,19 +156,2 @@ return sql.value(val); | ||
}; | ||
/* | ||
type = | ||
{ kind: 'type', | ||
id: '1021', | ||
name: '_float4', | ||
description: null, | ||
namespaceId: '11', | ||
namespaceName: 'pg_catalog', | ||
type: 'b', | ||
category: 'A', | ||
domainIsNotNull: false, | ||
arrayItemTypeId: '700', | ||
classId: null, | ||
domainBaseTypeId: null, | ||
enumVariants: null, | ||
rangeSubTypeId: null } | ||
*/ | ||
@@ -582,4 +577,4 @@ const makeIntervalFields = () => { | ||
// Ref: https://www.postgresql.org/docs/9.6/static/rangetypes.html#RANGETYPES-CONSTRUCT | ||
const lower = start && gql2pg(start.value, subtype) || sql.null; | ||
const upper = end && gql2pg(end.value, subtype) || sql.null; | ||
const lower = start && gql2pg(start.value, subtype, null) || sql.null; | ||
const upper = end && gql2pg(end.value, subtype, null) || sql.null; | ||
const lowerInclusive = start && !start.inclusive ? "(" : "["; | ||
@@ -586,0 +581,0 @@ const upperInclusive = end && !end.inclusive ? ")" : "]"; |
{ | ||
"name": "graphile-build-pg", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0-rc.3", | ||
"description": "Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build", | ||
@@ -30,3 +30,3 @@ "main": "node8plus/index.js", | ||
], | ||
"author": "Benjie Gillam <benjie@jemjie.com>", | ||
"author": "Benjie Gillam <code@benjiegillam.com>", | ||
"license": "MIT", | ||
@@ -36,7 +36,7 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/graphile/graphile-build#readme", | ||
"homepage": "https://github.com/graphile/graphile-build/tree/master/packages/graphile-build-pg", | ||
"dependencies": { | ||
"chalk": "^2.1.0", | ||
"debug": ">=2 <3", | ||
"graphile-build": "4.0.0-rc.2", | ||
"graphile-build": "4.0.0-rc.3", | ||
"graphql-iso-date": "^3.2.0", | ||
@@ -43,0 +43,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
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
1056401
5678
+ Addedgraphile-build@4.0.0-rc.3(transitive)
+ Addedgraphql-parse-resolve-info@4.0.0-rc.3(transitive)
- Removedgraphile-build@4.0.0-rc.2(transitive)
- Removedgraphql-parse-resolve-info@4.0.0-rc.2(transitive)
Updatedgraphile-build@4.0.0-rc.3