Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var mutationNameMap = directiveArguments.mutations;
// Create the mutations.
if (shouldMakeCreate) {
var createResolver = _this.resources.makeCreateResolver(def.name.value, createFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBCreateResolverResourceID(typeName), createResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(createResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(createInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeUpdate) {
var updateResolver = _this.resources.makeUpdateResolver(def.name.value, updateFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBUpdateResolverResourceID(typeName), updateResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(updateResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(updateInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeDelete) {
var deleteResolver = _this.resources.makeDeleteResolver(def.name.value, deleteFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBDeleteResolverResourceID(typeName), deleteResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(deleteResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(deleteInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
ctx.addObjectExtension(mutationType);
if (shouldMakeQuery || shouldMakeList) {
if (!_this.typeExist('ModelSortDirection', ctx)) {
var tableSortDirection = definitions_1.makeModelSortDirectionEnumObject();
ctx.addEnum(tableSortDirection);
}
}
// Create query queries
if (shouldMakeQuery) {
_this.generateModelXConnectionType(ctx, def);
var queryResolver = _this.resources.makeQueryResolver(def.name.value, queryFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBQueryResolverResourceID(typeName), queryResolver);
queryType = graphql_transformer_common_1.extensionWithFields(queryType, [definitions_1.makeModelConnectionField(queryResolver.Properties.FieldName, def.name.value)]);
_this.generateFilterInputs(ctx, def);
}
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);
}
ctx.addEnum(tableSortDirection);
}
}
// Create query queries
if (shouldMakeQuery) {
_this.generateModelXConnectionType(ctx, def);
var queryResolver = _this.resources.makeQueryResolver(def.name.value, queryFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBQueryResolverResourceID(typeName), queryResolver);
queryType = graphql_transformer_common_1.extensionWithFields(queryType, [definitions_1.makeModelConnectionField(queryResolver.Properties.FieldName, def.name.value)]);
_this.generateFilterInputs(ctx, def);
}
// Create get queries
if (shouldMakeGet) {
var getResolver = _this.resources.makeGetResolver(def.name.value, getFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBGetResolverResourceID(typeName), getResolver);
queryType = graphql_transformer_common_1.extensionWithFields(queryType, [graphql_transformer_common_1.makeField(getResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('id', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('ID')))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeList) {
_this.generateModelXConnectionType(ctx, def);
// Create the list resolver
var listResolver = _this.resources.makeListResolver(def.name.value, listFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBListResolverResourceID(typeName), listResolver);
_this.generateFilterInputs(ctx, def);
// Extend the query type to include listX
queryType = graphql_transformer_common_1.extensionWithFields(queryType, [definitions_1.makeModelConnectionField(listResolver.Properties.FieldName, def.name.value)]);
}
ctx.addObjectExtension(queryType);
};
_this.resources = new resources_1.ResourceFactory();
updateFieldNameOverride = directiveArguments.mutations.update;
}
if (!directiveArguments.mutations.delete) {
shouldMakeDelete = false;
}
else {
deleteFieldNameOverride = directiveArguments.mutations.delete;
}
}
var queryNameMap = directiveArguments.queries;
var mutationNameMap = directiveArguments.mutations;
// Create the mutations.
if (shouldMakeCreate) {
var createResolver = _this.resources.makeCreateResolver(def.name.value, createFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBCreateResolverResourceID(typeName), createResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(createResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(createInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeUpdate) {
var updateResolver = _this.resources.makeUpdateResolver(def.name.value, updateFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBUpdateResolverResourceID(typeName), updateResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(updateResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(updateInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeDelete) {
var deleteResolver = _this.resources.makeDeleteResolver(def.name.value, deleteFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBDeleteResolverResourceID(typeName), deleteResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(deleteResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(deleteInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
ctx.addObjectExtension(mutationType);
if (shouldMakeQuery || shouldMakeList) {
if (!_this.typeExist('ModelSortDirection', ctx)) {
var tableSortDirection = definitions_1.makeModelSortDirectionEnumObject();
ctx.addEnum(tableSortDirection);
_this.generateFilterInputs(ctx, def);
}
// Create get queries
if (shouldMakeGet) {
var getResolver = _this.resources.makeGetResolver(def.name.value, getFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBGetResolverResourceID(typeName), getResolver);
queryType = graphql_transformer_common_1.extensionWithFields(queryType, [graphql_transformer_common_1.makeField(getResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('id', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType('ID')))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeList) {
_this.generateModelXConnectionType(ctx, def);
// Create the list resolver
var listResolver = _this.resources.makeListResolver(def.name.value, listFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBListResolverResourceID(typeName), listResolver);
_this.generateFilterInputs(ctx, def);
// Extend the query type to include listX
queryType = graphql_transformer_common_1.extensionWithFields(queryType, [definitions_1.makeModelConnectionField(listResolver.Properties.FieldName, def.name.value)]);
}
ctx.addObjectExtension(queryType);
};
_this.resources = new resources_1.ResourceFactory();
else {
deleteFieldNameOverride = directiveArguments.mutations.delete;
}
}
var queryNameMap = directiveArguments.queries;
var mutationNameMap = directiveArguments.mutations;
// Create the mutations.
if (shouldMakeCreate) {
var createResolver = _this.resources.makeCreateResolver(def.name.value, createFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBCreateResolverResourceID(typeName), createResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(createResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(createInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeUpdate) {
var updateResolver = _this.resources.makeUpdateResolver(def.name.value, updateFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBUpdateResolverResourceID(typeName), updateResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(updateResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(updateInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
if (shouldMakeDelete) {
var deleteResolver = _this.resources.makeDeleteResolver(def.name.value, deleteFieldNameOverride);
ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBDeleteResolverResourceID(typeName), deleteResolver);
mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(deleteResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(deleteInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
}
ctx.addObjectExtension(mutationType);
if (shouldMakeQuery || shouldMakeList) {
if (!_this.typeExist('ModelSortDirection', ctx)) {
var tableSortDirection = definitions_1.makeModelSortDirectionEnumObject();
ctx.addEnum(tableSortDirection);
}
}
// Create query queries
if (shouldMakeQuery) {
_this.generateModelXConnectionType(ctx, def);
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);
}
export function makeModelConnectionType(typeName: string, isSync: Boolean = false): ObjectTypeExtensionNode {
const connectionName = ModelResourceIDs.ModelConnectionTypeName(typeName);
let connectionTypeExtension = blankObjectExtension(connectionName);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [makeField('items', [], makeListType(makeNamedType(typeName)))]);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [makeField('nextToken', [], makeNamedType('String'))]);
if (isSync) {
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [makeField('startedAt', [], makeNamedType('AWSTimestamp'))]);
}
return connectionTypeExtension;
}
export function makeModelConnectionType(typeName: string, isSync: Boolean = false): ObjectTypeExtensionNode {
const connectionName = ModelResourceIDs.ModelConnectionTypeName(typeName);
let connectionTypeExtension = blankObjectExtension(connectionName);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [makeField('items', [], makeListType(makeNamedType(typeName)))]);
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [makeField('nextToken', [], makeNamedType('String'))]);
if (isSync) {
connectionTypeExtension = extensionWithFields(connectionTypeExtension, [makeField('startedAt', [], makeNamedType('AWSTimestamp'))]);
}
return connectionTypeExtension;
}