#Hide a field from the API

5 messages · Page 1 of 1 (latest)

stoic pond
#

I have the following fields in a block:

  {
    name: "lexical",
    type: "richText",
    virtual: true,
    hooks: {
      afterRead: [
        async ({ siblingData }) => {
          if (siblingData["content"]) {
            return await convertToLexical(siblingData["content"]);
          }
        },
      ],
      beforeChange: [
        async ({ value, siblingData }) => {
          if (value) {
            siblingData["content"] = await convertToMarkdown(value);
          }
        },
      ],
    },
  },
  {
    name: "content",
    type: "text",
    admin: {
      hidden: true,
    },
  },

Is there a way to hide the lexical field in the API?

atomic mistBOT
stoic pond
#

A bit of a hacky solution, but i just added a check to see if the pathname starts with "/admin" to my afterRead hook:

async ({ siblingData, req }) => {
  if (
    siblingData["content"] &&
    req.pathname.startsWith("/admin")
  ) {
    return await convertToLexical(siblingData["content"]);
  }
},
atomic mistBOT