refine-sanity
Version:
Data provider for refine with sanity. refine is a React-based framework for building internal tools, rapidly. Sanity is headless CMS.
22 lines (21 loc) • 688 B
JavaScript
export const generateSelect = (fields) => {
if (!fields) {
return '';
}
if (typeof fields === 'string')
return fields;
if (!Array.isArray(fields)) {
console.log(fields);
}
const selected = fields.map(f => {
if (typeof f === 'string')
return f;
const field = f;
if (field.operation || field.fields) {
// TODO: Doesn't support nested yet, have to add it.
throw new Error("Sorry, nested fields are not implemented yet");
}
return Object.keys(field).map((key) => `"${key}": ${generateSelect(field[key])}`).join(", ");
});
return `{${selected.join(", ")}}`;
};