How to use the webiny-api/graphql/responses.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-page-builder / src / plugins / graphql / pageResolvers / getPublishedPage.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    if (!args.parent && !args.url) {
        return new NotFoundResponse("Page parent or URL missing.");
    }

    // We utilize the same query used for listing published pages (single source of truth = less maintenance).
    const Page = context.getEntity("PbPage");
    const Category = context.getEntity("PbCategory");
    const [page] = await listPublishedPages({ Page, Category, args: { ...args, perPage: 1 } });

    if (!page) {
        return new NotFoundResponse("The requested page was not found.");
    }

    return new Response(page);
};
github webiny / webiny-js / packages / webiny-api-page-builder / src / plugins / graphql / pageResolvers / getPublishedPage.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    if (!args.parent && !args.url) {
        return new NotFoundResponse("Page parent or URL missing.");
    }

    // We utilize the same query used for listing published pages (single source of truth = less maintenance).
    const Page = context.getEntity("PbPage");
    const Category = context.getEntity("PbCategory");
    const [page] = await listPublishedPages({ Page, Category, args: { ...args, perPage: 1 } });

    if (!page) {
        return new NotFoundResponse("The requested page was not found.");
    }

    return new Response(page);
};
github webiny / webiny-js / packages / webiny-api-page-builder / src / plugins / graphql / menuResolvers / getMenuBySlug.js View on Github external
export default (entityFetcher: EntityFetcher) => async (
    root: any,
    args: Object,
    context: Object
) => {
    const { slug } = args;
    const entityClass = entityFetcher(context);

    const entity = await entityClass.findOne({ query: { slug } });
    if (!entity) {
        return new NotFoundResponse("Menu not found.");
    }

    return new Response({
        id: entity.id,
        title: entity.title,
        items: prepareMenuItems({ entity, context })
    });
};