Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resolve: async (root: any, args: Object) => {
const entity = await entityClass.findById(args.id);
if (!entity) {
throw Error(`Entity with id "${args.id}" not found.`);
}
try {
await entity.populate(args.data).save();
} catch (e) {
if (e instanceof ModelError && e.code === ModelError.INVALID_ATTRIBUTES) {
throw InvalidAttributesError.from(e);
}
throw e;
}
return entity;
}
};
export const resolveCreate = (entityFetcher: EntityFetcher) => async (
root: any,
args: Object,
context: Object
) => {
const EntityClass = getEntityClass(context, entityFetcher);
const entity = new EntityClass();
try {
await entity.populate(args.data).save();
} catch (e) {
if (e instanceof ModelError && e.code === ModelError.INVALID_ATTRIBUTES) {
const attrError = InvalidAttributesError.from(e);
return new ErrorResponse({
code: attrError.code || "INVALID_ATTRIBUTES",
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(entity);
};
async resolve(root, args) {
const entity = await entityClass.findById(args.id);
try {
await entity.populate(args.data).save();
} catch (e) {
if (e instanceof ModelError && e.code === ModelError.INVALID_ATTRIBUTES) {
throw new FormattedInvalidAttributesModelError(e);
}
throw e;
}
return entity;
}
};
async resolve(root: any, args: Object) {
const entity = new entityClass();
if (!entity) {
throw Error(`Entity with id "${args.id}" not found.`);
}
try {
await entity.populate(args.data).save();
} catch (e) {
if (e instanceof ModelError && e.code === ModelError.INVALID_ATTRIBUTES) {
throw InvalidAttributesError.from(e);
}
throw e;
}
return entity;
}
};
async resolve(root, args) {
const entity = new ApiToken();
try {
await entity.populate(args.data).save();
await entity.activate();
await entity.save();
} catch (e) {
if (e instanceof ModelError && e.code === ModelError.INVALID_ATTRIBUTES) {
throw InvalidAttributesError.from(e);
}
throw e;
}
return entity;
}
};