Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private generateSearchableXConnectionType(ctx: TransformerContext, def: ObjectTypeDefinitionNode): void {
const searchableXConnectionName = `Searchable${def.name.value}Connection`;
if (this.typeExist(searchableXConnectionName, ctx)) {
return;
}
// Create the TableXConnection
const connectionType = blankObject(searchableXConnectionName);
ctx.addObject(connectionType);
// Create TableXConnection type with items and nextToken
let connectionTypeExtension = blankObjectExtension(searchableXConnectionName);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [
makeField('items', [], makeListType(makeNamedType(def.name.value))),
]);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [
makeField('nextToken', [], makeNamedType('String')),
makeField('total', [], makeNamedType('Int')),
]);
ctx.addObjectExtension(connectionTypeExtension);
}
} else {
deleteFieldNameOverride = directiveArguments.mutations.delete
}
}
// Create the mutations.
if (shouldMakeCreate) {
const createInput = makeCreateInputObject(def, nonModelArray, ctx)
if (!ctx.getType(createInput.name.value)) {
ctx.addInput(createInput)
}
const createResolver = this.resources.makeCreateResolver(def.name.value, createFieldNameOverride)
const resourceId = ResolverResourceIDs.DynamoDBCreateResolverResourceID(typeName);
ctx.setResource(resourceId, createResolver)
ctx.mapResourceToStack(typeName, resourceId);
mutationFields.push(makeField(
createResolver.Properties.FieldName,
[makeInputValueDefinition('input', makeNonNullType(makeNamedType(createInput.name.value)))],
makeNamedType(def.name.value)
));
}
if (shouldMakeUpdate) {
const updateInput = makeUpdateInputObject(def, nonModelArray, ctx)
if (!ctx.getType(updateInput.name.value)) {
ctx.addInput(updateInput)
}
const updateResolver = this.resources.makeUpdateResolver(def.name.value, updateFieldNameOverride)
const resourceId = ResolverResourceIDs.DynamoDBUpdateResolverResourceID(typeName);
ctx.setResource(resourceId, updateResolver);
ctx.mapResourceToStack(typeName, resourceId);
mutationFields.push(makeField(
const searchableXConnectionName = `Searchable${def.name.value}Connection`;
if (this.typeExist(searchableXConnectionName, ctx)) {
return;
}
// Create the TableXConnection
const connectionType = blankObject(searchableXConnectionName);
ctx.addObject(connectionType);
// Create TableXConnection type with items and nextToken
let connectionTypeExtension = blankObjectExtension(searchableXConnectionName);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [
makeField('items', [], makeListType(makeNamedType(def.name.value))),
]);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [
makeField('nextToken', [], makeNamedType('String')),
makeField('total', [], makeNamedType('Int')),
]);
ctx.addObjectExtension(connectionTypeExtension);
}
export function makeSubscriptionField(fieldName: string, returnTypeName: string, mutations: string[]): FieldDefinitionNode {
return makeField(fieldName, [], makeNamedType(returnTypeName), [
makeDirective('aws_subscribe', [makeArgument('mutations', makeValueNode(mutations))]),
]);
}
private addOwner(ctx: TransformerContext, parent: string) {
const modelType: any = ctx.getType(parent);
const fields = getFieldArguments(modelType);
if (!("owner" in fields)) {
modelType.fields.push(
makeField(
DEFAULT_OWNER_FIELD,
[],
makeNamedType('String'),
)
)
}
ctx.putType(modelType);
}
makeInputValueDefinition('filter', makeNamedType(ModelResourceIDs.ModelFilterInputTypeName(returnTypeName))),
makeInputValueDefinition('sortDirection', makeNamedType('ModelSortDirection')),
makeInputValueDefinition('limit', makeNamedType('Int')),
makeInputValueDefinition('nextToken', makeNamedType('String')),
];
if (sortKeyInfo) {
let namedType: NamedTypeNode;
if (sortKeyInfo.typeName === 'Composite') {
namedType = makeNamedType(ModelResourceIDs.ModelCompositeKeyConditionInputTypeName(sortKeyInfo.model, toUpper(sortKeyInfo.keyName)));
} else {
namedType = makeNamedType(ModelResourceIDs.ModelKeyConditionInputTypeName(sortKeyInfo.typeName));
}
args.unshift(makeInputValueDefinition(sortKeyInfo.fieldName, namedType));
}
return makeField(fieldName, args, makeNamedType(ModelResourceIDs.ModelConnectionTypeName(returnTypeName)), directives);
}