How to use the webiny-model.ModelError.INVALID_ATTRIBUTES function in webiny-model

To help you get started, we’ve selected a few webiny-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / webiny-api / src / graphql / fields / crud / fieldUpdate.js View on Github external
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;
        }
    };
github webiny / webiny-js / packages / webiny-api / src / graphql / crudResolvers.js View on Github external
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);
};
github webiny / webiny-js / packages / webiny-api / src / graphql / utils / entityToSchema.js View on Github external
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;
        }
    };
github webiny / webiny-js / packages / webiny-api / src / graphql / fields / crud / fieldCreate.js View on Github external
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;
        }
    };
github webiny / webiny-js / packages / webiny-api / src / security / graphql / overrideCreateApiTokenMutation.js View on Github external
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;
        }
    };