Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rows.push(row);
}
// Save CSV file and return its URL to the client.
const csv = await parseAsync(rows, { fields: Object.values(fields) });
const buffer = Buffer.from(csv);
const result = await uploadFile({
context,
buffer,
file: {
size: buffer.length,
name: "form_submissions_export.csv",
type: "text/csv"
}
});
return new Response(result);
};
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] = await listPublishedPages({ context, args: { ...args, perPage: 1 } });
if (!page) {
return new NotFoundResponse("The requested page was not found.");
}
return new Response(page);
};
let submissions = [];
const { FormSubmission } = context.models;
if (ids) {
submissions = await FormSubmission.find({ query: { id: { $in: args.ids } } });
} else {
if (form) {
submissions = await FormSubmission.find({ query: { "form.revision": form } });
} else if (parent) {
submissions = await FormSubmission.find({ query: { "form.parent": parent } });
}
}
// Take first submission, get parent Form entity, and get all distinct fields through all revisions.
if (submissions.length === 0) {
return new NotFoundResponse("No form submissions found.");
}
const parentForm = await submissions[0].form.parent;
const revisions = await parentForm.revisions;
const rows = [];
const fields = {};
// First extract all distinct fields across all form submissions.
for (let i = 0; i < revisions.length; i++) {
let revision = revisions[i];
for (let j = 0; j < revision.fields.length; j++) {
let field = revision.fields[j];
if (!fields[field.fieldId]) {
fields[field.fieldId] = field.label.value;
}
export default async (root: any, args: Object, context: Object) => {
if (!args.id && !args.parent && !args.slug) {
return new NotFoundResponse("Form ID or slug missing.");
}
// We utilize the same query used for listing published forms (single source of truth = less maintenance).
const listArgs = { ...args, perPage: 1 };
if (!listArgs.version) {
listArgs.sort = { version: -1 };
}
const plugin = getListPublishedFormsResolver(context);
const { forms, totalCount } = await plugin.resolve({ root, args: listArgs, context });
if (!Array.isArray(forms) || !Number.isInteger(totalCount)) {
throw Error(
`Resolver plugin "forms-resolver-list-published-forms" must return { forms: [Form], totalCount: Int }!`
);
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] = await listPublishedPages({ context, args: { ...args, perPage: 1 } });
if (!page) {
return new NotFoundResponse("The requested page was not found.");
}
return new Response(page);
};
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] = await listPublishedPages({ context, args: { ...args, perPage: 1 } });
if (!page) {
return new NotFoundResponse("The requested page was not found.");
}
return new Response(page);
};
});
}
// 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
});
}
};
}
// @flow
import { createHandler, PluginsContainer } from "@webiny/api";
import createConfig from "service-config";
import servicePlugins from "@webiny/api/plugins/service";
import securityPlugins from "@webiny/api-security/plugins";
const plugins = new PluginsContainer([servicePlugins, securityPlugins]);
let apolloHandler;
export const handler = async (event: Object, context: Object) => {
if (!apolloHandler) {
const config = await createConfig();
const { handler } = await createHandler({ plugins, config });
apolloHandler = handler;
}
return apolloHandler(event, context);
};
// @flow
import { createHandler, PluginsContainer } from "@webiny/api";
import createConfig from "service-config";
import servicePlugins from "@webiny/api/plugins/service";
import securityPlugins from "@webiny/api-security/plugins/service";
import filesPlugins from "@webiny/api-files/plugins";
const plugins = new PluginsContainer([servicePlugins, securityPlugins, filesPlugins]);
let apolloHandler;
export const handler = async (event: Object, context: Object) => {
if (!apolloHandler) {
const config = await createConfig();
const { handler } = await createHandler({ plugins, config });
apolloHandler = handler;
}
return apolloHandler(event, context);
};
// @flow
import { createHandler, PluginsContainer } from "@webiny/api";
import servicePlugins from "@webiny/api/plugins/service";
import securityPlugins from "@webiny/api-security/plugins/service";
import headlessPlugins from "@webiny/api-headless/plugins";
import createConfig from "service-config";
const plugins = new PluginsContainer([servicePlugins, securityPlugins, headlessPlugins]);
export const handler = async (context: Object) => {
const config = await createConfig(context);
return await createHandler({ config, plugins });
};