How to use the @webiny/commodo-graphql.InvalidFieldsError.from function in @webiny/commodo-graphql

To help you get started, we’ve selected a few @webiny/commodo-graphql 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 / api-security / src / plugins / graphql / installResolvers / install.js View on Github external
// Update user's data
            user.firstName = data.firstName;
            user.lastName = data.lastName;
            await user.save();
        }

        try {
            await authPlugin.createUser({ data: args.data, user, permanent: true }, context);
            result.authUser = true;
        } catch {
            // Update firstName/lastName, but do not touch the existing password
            await authPlugin.updateUser({ data: omit(args.data, ["password"]), user }, context);
        }
    } catch (e) {
        if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
            const attrError = InvalidFieldsError.from(e);
            return new ErrorResponse({
                code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
                message: attrError.message,
                data: attrError.data
            });
        }
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data
        });
    }

    return new Response(result);
};
github webiny / webiny-js / packages / api-security / src / plugins / graphql / userResolvers / createUser.js View on Github external
try {
        await user.populate(args.data).save();

        const authPlugin = context.plugins
            .byType("security-authentication-provider")
            .filter(pl => pl.hasOwnProperty("createUser"))
            .pop();

        try {
            await authPlugin.createUser({ data: args.data, user }, context);
        } catch {
            // If user already exists we don't do anything on the auth provider side.
        }
    } catch (e) {
        if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
            const attrError = InvalidFieldsError.from(e);
            return new ErrorResponse({
                code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
                message: attrError.message,
                data: attrError.data
            });
        }
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data
        });
    }
    return new Response(user);
};
github webiny / webiny-js / packages / api-files / src / plugins / resolvers / updateFileBySrc.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const { File } = context.models;

    const model = await File.findOne({ query: { src: args.src } });
    if (!model) {
        return new NotFoundResponse();
    }

    try {
        await model.populate(args.data).save();
    } catch (e) {
        if (
            e instanceof WithFieldsError &&
            e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS
        ) {
            const attrError = InvalidFieldsError.from(e);
            return new ErrorResponse({
                code: attrError.code || "VALIDATION_FAILED_INVALID_FIELDS",
                message: attrError.message,
                data: attrError.data
            });
        }
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data || null
        });
    }
    return new Response(model);
};
github webiny / webiny-js / packages / api-security / src / plugins / graphql / userResolvers / updateUser.js View on Github external
if (!user) {
        return new NotFoundResponse(id ? `User "${id}" not found!` : "User not found!");
    }

    try {
        await user.populate(data).save();

        const authPlugin = context.plugins
            .byType("security-authentication-provider")
            .filter(pl => pl.hasOwnProperty("updateUser"))
            .pop();

        await authPlugin.updateUser({ data: args.data, user }, context);
    } catch (e) {
        if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
            const attrError = InvalidFieldsError.from(e);
            return new ErrorResponse({
                code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
                message: attrError.message,
                data: attrError.data
            });
        }
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data
        });
    }
    return new Response(user);
};