How to use the webiny-api/graphql.NotFoundResponse function in webiny-api

To help you get started, we’ve selected a few webiny-api 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-security / src / plugins / graphql / userResolvers / updateCurrentUser.js View on Github external
const currentUser: ?Entity = await User.findById(user.id);
    if (currentUser) {
        try {
            currentUser.populate(args.data);
            await currentUser.save();
            return new Response(currentUser);
        } catch (e) {
            return new ErrorResponse({
                code: e.code,
                message: e.message,
                data: e.data || null
            });
        }
    }

    return new NotFoundResponse("User not found!");
};
github webiny / webiny-js / packages / webiny-api-page-builder / src / plugins / graphql / pageResolvers / setHomePage.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const Page = context.getEntity("PbPage");
    const Settings = context.getEntity("PbSettings");
    const { id } = args;

    const newHomePage = await Page.findById(id);

    if (!newHomePage) {
        return new NotFoundResponse(id);
    }

    const settings = await Settings.load();
    if (settings.data.pages.home === newHomePage.parent) {
        return new ErrorResponse({
            code: "ALREADY_HOMEPAGE",
            message: `The page is already set as homepage.`
        });
    }

    if (!newHomePage.published) {
        newHomePage.published = true;
        await newHomePage.save();
    }

    settings.data.pages.home = newHomePage.parent;