How to use the webiny-api/graphql.Response 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
export default (entityFetcher: EntityFetcher) => async (
    root: any,
    args: Object,
    context: Object
) => {
    const User = entityFetcher(context);

    const { user } = context;

    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 / createRevisionFrom.js View on Github external
title: sourceRev.title,
            snippet: sourceRev.snippet,
            settings: sourceRev.settings,
            content: sourceRev.content,
            category: await sourceRev.category,
            parent: sourceRev.parent
        });
        await newRevision.save();
    } catch (e) {
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data
        });
    }
    return new Response(newRevision);
};
github webiny / webiny-js / packages / webiny-api-security / src / plugins / graphql / userResolvers / getCurrentUser.js View on Github external
export default (entityFetcher: EntityFetcher) => async (
    root: any,
    args: Object,
    context: Object
) => {
    const User = entityFetcher(context);

    const { user } = context;

    if (user) {
        const instance = await User.findById(user.id);
        if (!instance) {
            return new NotFoundResponse(`User with ID ${user.id} was not found!`);
        }

        return new Response(instance);
    }

    return new Response(null);
};
github webiny / webiny-js / packages / webiny-api-page-builder / src / plugins / graphql / pageResolvers / setHomePage.js View on Github external
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;
    await settings.save();

    return new Response(newHomePage);
};
github webiny / webiny-js / packages / webiny-api-security / src / plugins / graphql / userResolvers / getCurrentUser.js View on Github external
context: Object
) => {
    const User = entityFetcher(context);

    const { user } = context;

    if (user) {
        const instance = await User.findById(user.id);
        if (!instance) {
            return new NotFoundResponse(`User with ID ${user.id} was not found!`);
        }

        return new Response(instance);
    }

    return new Response(null);
};