Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private generateModelXConnectionType(ctx: TransformerContext, typeDef: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode): void {
const tableXConnectionName = ModelResourceIDs.ModelConnectionTypeName(typeDef.name.value)
if (this.typeExist(tableXConnectionName, ctx)) {
return
}
// Create the ModelXConnection
const connectionType = blankObject(tableXConnectionName)
ctx.addObject(connectionType)
ctx.addObjectExtension(makeModelConnectionType(typeDef.name.value))
}
private generateModelXConnectionType(ctx: TransformerContext, typeDef: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode): void {
const tableXConnectionName = ModelResourceIDs.ModelConnectionTypeName(typeDef.name.value)
if (this.typeExist(tableXConnectionName, ctx)) {
return
}
// Create the ModelXConnection
const connectionType = blankObject(tableXConnectionName)
ctx.addObject(connectionType)
ctx.addObjectExtension(makeModelConnectionType(typeDef.name.value))
}
private generateFilterAndKeyConditionInputs(
ctx: TransformerContext, field: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string, typeName: string }
): void {
const scalarFilters = makeScalarFilterInputs()
for (const filter of scalarFilters) {
if (!this.typeExist(filter.name.value, ctx)) {
ctx.addInput(filter)
}
}
// Create the ModelXFilterInput
const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx)
if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
ctx.addInput(tableXQueryFilterInput)
}
// Create sort key condition inputs for valid sort key types
// We only create the KeyConditionInput if it is being used.
// Don't create a key condition input for composite sort keys since it already done by @key.
if (sortKeyInfo && (sortKeyInfo.typeName !== "Composite")) {
const sortKeyConditionInput = makeScalarKeyConditionForType(makeNamedType(sortKeyInfo.typeName))
if (!this.typeExist(sortKeyConditionInput.name.value, ctx)) {
ctx.addInput(sortKeyConditionInput);
}
}
}
}
private generateFilterAndKeyConditionInputs(
ctx: TransformerContext, field: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string, typeName: string }
): void {
const scalarFilters = makeScalarFilterInputs()
for (const filter of scalarFilters) {
if (!this.typeExist(filter.name.value, ctx)) {
ctx.addInput(filter)
}
}
// Create the ModelXFilterInput
const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx)
if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
ctx.addInput(tableXQueryFilterInput)
}
// Create sort key condition inputs for valid sort key types
// We only create the KeyConditionInput if it is being used.
if (sortKeyInfo) {
const sortKeyConditionInput = makeScalarKeyConditionForType(makeNamedType(sortKeyInfo.typeName))
if (!this.typeExist(sortKeyConditionInput.name.value, ctx)) {
ctx.addInput(sortKeyConditionInput);
}
}
}
private generateFilterAndKeyConditionInputs(
ctx: TransformerContext, field: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string, typeName: string }
): void {
const scalarFilters = makeScalarFilterInputs()
for (const filter of scalarFilters) {
if (!this.typeExist(filter.name.value, ctx)) {
ctx.addInput(filter)
}
}
// Create the ModelXFilterInput
const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx)
if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
ctx.addInput(tableXQueryFilterInput)
}
// Create sort key condition inputs for valid sort key types
// We only create the KeyConditionInput if it is being used.
// Don't create a key condition input for composite sort keys since it already done by @key.
if (sortKeyInfo && (sortKeyInfo.typeName !== "Composite")) {
private generateFilterAndKeyConditionInputs(
ctx: TransformerContext, field: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
sortKeyInfo?: { fieldName: string, typeName: string }
): void {
const scalarFilters = makeScalarFilterInputs()
for (const filter of scalarFilters) {
if (!this.typeExist(filter.name.value, ctx)) {
ctx.addInput(filter)
}
}
// Create the ModelXFilterInput
const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx)
if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
ctx.addInput(tableXQueryFilterInput)
}
// Create sort key condition inputs for valid sort key types
// We only create the KeyConditionInput if it is being used.
if (sortKeyInfo) {
const sortKeyConditionInput = makeScalarKeyConditionForType(makeNamedType(sortKeyInfo.typeName))
(f: FieldDefinitionNode) => {
if (f.name.value === field.name.value) {
const updated = makeModelConnectionField(field.name.value, returnType.name.value, sortKeyInfo)
updated.directives = f.directives
return updated
}
return f;
}
)
(f: FieldDefinitionNode) => {
if (f.name.value === field.name.value) {
const updated = makeModelConnectionField(field.name.value, returnType.name.value, sortKeyInfo)
updated.directives = f.directives
return updated
}
return f;
}
)
if (f.name.value === field.name.value) {
const updated = makeModelConnectionField(field.name.value, returnType.name.value, sortKeyInfo)
updated.directives = f.directives
return updated
}
return f;
}
)
const updatedType = {
...type,
fields: newFields
}
ctx.putType(updatedType)
if (!this.typeExist('ModelSortDirection', ctx)) {
const modelSortDirection = makeModelSortDirectionEnumObject()
ctx.addEnum(modelSortDirection)
}
this.generateFilterAndKeyConditionInputs(ctx, returnType, sortKeyInfo)
} else {
throw new InvalidDirectiveError(`Could not find a object or interface type named ${parent.name.value}.`)
}
}
if (f.name.value === field.name.value) {
const updated = makeModelConnectionField(field.name.value, returnType.name.value, sortKeyInfo)
updated.directives = f.directives
return updated
}
return f;
}
)
const updatedType = {
...type,
fields: newFields
}
ctx.putType(updatedType)
if (!this.typeExist('ModelSortDirection', ctx)) {
const modelSortDirection = makeModelSortDirectionEnumObject()
ctx.addEnum(modelSortDirection)
}
this.generateFilterAndKeyConditionInputs(ctx, returnType, sortKeyInfo)
} else {
throw new InvalidDirectiveError(`Could not find a object or interface type named ${parent.name.value}.`)
}
}