Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new InvalidDirectiveError(inputFieldNames[0] + ' field is not of type ' + getBaseType(tablePKType))
}
if (numFields > keySchema.length && keySchema.length !== 2) {
throw new InvalidDirectiveError('Too many fields passed in to @connection directive.')
}
if (numFields === 2) {
const sortAttributeName = keySchema[1].AttributeName;
const tableSKType = relatedTypeFields.find(f => f.name.value === sortAttributeName).type;
const querySKType = parentFields.find(f => f.name.value === inputFieldNames[1]).type;
if (getBaseType(tableSKType) !== getBaseType(querySKType)) {
throw new InvalidDirectiveError(inputFieldNames[1] + ' field is not of type ' + getBaseType(tableSKType))
}
} else if (numFields > 2) {
const tableSortFields = keySchema[1].AttributeName.split(ModelResourceIDs.ModelCompositeKeySeparator());
const tableSortKeyTypes = tableSortFields.map(name => relatedTypeFields.find(f => f.name.value === name).type);
const querySortFields = inputFieldNames.slice(1);
const querySortKeyTypes = querySortFields.map(name => parentFields.find(f => f.name.value === name).type);
// Check that types of each attribute match types of the fields that make up the composite sort key for the
// table or index being queried.
querySortKeyTypes.forEach((fieldType, index) => {
if (getBaseType(fieldType) !== getBaseType(tableSortKeyTypes[index])) {
throw new InvalidDirectiveError(
querySortFields[index] + ' field is not of type ' + getBaseType(tableSortKeyTypes[index])
)
}
})
}
}
public makeCompositeSortKeyName(sortKeyName: string) {
const attributeNames = sortKeyName.split(ModelResourceIDs.ModelCompositeKeySeparator());
return toCamelCase(attributeNames)
}
private getSortKeyNames(compositeSK: string) {
return compositeSK.split(ModelResourceIDs.ModelCompositeKeySeparator());
}
function condenseRangeKey(fields: string[]) {
return fields.join(ModelResourceIDs.ModelCompositeKeySeparator());
}
private condenseRangeKey(fields: string[]) {
return fields.join(ModelResourceIDs.ModelCompositeKeySeparator());
}