How to use the @webiny/api.ListResponse 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 / api-cms / src / plugins / fieldTypes / ref.js View on Github external
});
                }

                // Load "many" entries
                const { where = {}, ...rest } = args;
                where["id_in"] = refValue || [];

                try {
                    const { entries, meta } = await findEntries({
                        model: refModel,
                        args: { where, ...rest },
                        context,
                        info
                    });

                    return new ListResponse(entries, meta);
                } catch (err) {
                    return new ListErrorResponse({
                        code: err.code,
                        error: err.message
                    });
                }
            };
        }
github webiny / webiny-js / packages / api-files / src / plugins / resolvers / listFiles.js View on Github external
tags: { $in: tags.map(tag => tag.toLowerCase()) }
        });
    }

    if (Array.isArray(ids) && ids.length > 0) {
        $and.push({
            id: { $in: ids }
        });
    }

    if ($and.length) {
        findArgs.query = { $and };
    }

    const data = await File.find(findArgs);
    return new ListResponse(data, data.getMeta());
};
github webiny / webiny-js / packages / api-page-builder / src / plugins / graphql / pageResolvers / listPublishedPages.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const data = await listPublishedPages({ args, context });
    return new ListResponse(data, data.getMeta());
};
github webiny / webiny-js / packages / api-forms / src / plugins / graphql / formResolvers / listForms.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const plugin = context.plugins.byName("forms-resolver-list-forms");

    if (!plugin) {
        throw Error(`Resolver plugin "forms-resolver-list-forms" is not configured!`);
    }

    const { forms, totalCount } = await plugin.resolve({ root, args, context });

    if (!Array.isArray(forms) || !Number.isInteger(totalCount)) {
        throw Error(
            `Resolver plugin "forms-resolver-list-forms" must return { forms: [Form], totalCount: Int }!`
        );
    }

    return new ListResponse(
        forms,
        createPaginationMeta({
            page: args.page,
            perPage: args.perPage,
            totalCount: totalCount ? totalCount : 0
        })
    );
};
github webiny / webiny-js / packages / api-mailchimp / src / index.js View on Github external
throw Error("Mailchimp API key not set.");
                        }

                        const mailchimp = new MailchimpApi({ apiKey: settings.data.apiKey });

                        try {
                            const listsResponse = await mailchimp.get({
                                path: `/lists/`
                            });

                            const output = listsResponse.body.lists.map(item => ({
                                id: item.id,
                                name: item.name
                            }));

                            return new ListResponse(output);
                        } catch (e) {
                            return new ListErrorResponse(e);
                        }
                    },
                    getSettings: resolveGetSettings(({ models }) => models.MailchimpSettings)
github webiny / webiny-js / packages / api-forms / src / plugins / graphql / formResolvers / listPublishedForms.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const plugin = getListPublishedFormsResolver(context);
    const { forms, totalCount } = await plugin.resolve({ root, args, context });

    if (!Array.isArray(forms) || !Number.isInteger(totalCount)) {
        throw Error(
            `Resolver plugin "forms-resolver-list-published-forms" must return { forms: [Form], totalCount: Int }!`
        );
    }

    return new ListResponse(
        forms,
        createPaginationMeta({
            page: args.page,
            perPage: args.perPage,
            totalCount: totalCount ? totalCount : 0
        })
    );
};
github webiny / webiny-js / packages / commodo-graphql / src / crudResolvers.js View on Github external
page: args.page,
        perPage: args.perPage,
        sort: args.sort
    };

    if (args.search && args.search.query) {
        find.search = {
            query: args.search.query,
            fields: args.search.fields,
            operator: args.search.operator || "or"
        };
    }

    const data = await Model.find(find);

    return new ListResponse(data, data.getMeta());
};
github webiny / webiny-js / packages / api-page-builder / src / plugins / graphql / pageResolvers / listPages.js View on Github external
export default async (root: any, args: Object, context: Object) => {
    const plugin = context.plugins.byName("pb-resolver-list-pages");

    if (!plugin) {
        throw Error(`Resolver plugin "pb-resolver-list-pages" is not configured!`);
    }

    const { pages, totalCount } = await plugin.resolve({ args, context });

    return new ListResponse(
        pages,
        createPaginationMeta({
            page: args.page,
            perPage: args.perPage,
            totalCount: totalCount ? totalCount : 0
        })
    );
};