How to use the @webiny/commodo-graphql.Response 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-cms / src / utils / resolveGet.js View on Github external
export const resolveGet = ({ model }: Object) => async (
    root: any,
    args: Object,
    context: Object
) => {
    if (args.id) {
        args.where = { _id: ObjectId(args.id) };
    }

    const entry = await findEntry({ model, args, context });

    if (!entry) {
        return entryNotFound();
    }
    return new Response(entry);
};
github webiny / webiny-js / packages / api-security / src / plugins / graphql / userResolvers / getCurrentUser.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const { user } = context;

    if (user) {
        const { SecurityUser } = context.models;
        const instance = await SecurityUser.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 / api-security / src / plugins / graphql / userResolvers / updateCurrentUser.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const { SecurityUser } = context.models;

    const { user } = context;

    const currentUser = await SecurityUser.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 / api-cms / src / utils / resolveCreate.js View on Github external
) => {
    const entry = {};

    try {
        const params = { models, model, context };
        await populateEntry(entry, args.data, params);
        entry._id = await saveEntry(entry, params);
    } catch (e) {
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data || null
        });
    }

    return new Response(entry);
};
github webiny / webiny-js / packages / api-cms / src / utils / resolveUpdate.js View on Github external
if (!entry) {
        return entryNotFound(args.id);
    }

    try {
        await populateEntry(entry, args.data, { models, model, context });
        await saveEntry(entry, { models, model, context });
    } catch (e) {
        return new ErrorResponse({
            code: e.code,
            message: e.message,
            data: e.data || null
        });
    }

    return new Response(entry);
};
github webiny / webiny-js / packages / api-security / src / plugins / graphql / userResolvers / getCurrentUser.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const { user } = context;

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

        return new Response(instance);
    }

    return new Response(null);
};