Skip to content

Instantly share code, notes, and snippets.

@KANE-99
Created January 30, 2026 11:14
Show Gist options
  • Select an option

  • Save KANE-99/2db304dc3b5c75109da4054eebb0d2b0 to your computer and use it in GitHub Desktop.

Select an option

Save KANE-99/2db304dc3b5c75109da4054eebb0d2b0 to your computer and use it in GitHub Desktop.

Frontend / CMS Interview – Practical Problem

Problem: Resolve CMS Entry References

Context

In our CMS, content entries can reference other entries (components, blocks, authors, assets, etc.).
Before rendering on the frontend, these references need to be resolved into a fully expanded structure.

This exercise focuses on:

  • Problem-solving approach
  • Code clarity
  • Handling real-world edge cases (like circular references)

Data Shape

Each entry has the following structure:

type Entry = {
  id: string;
  type: string;
  fields: Record<string, any>;
};

A reference to another entry is represented as:

{ ref: "entryId" }

Task

Write a function:

resolveEntry(rootId: string, entries: Record<string, Entry>): any

That:

  • Takes a root entry ID

  • Resolves all { ref: "id" } objects recursively

  • Returns a fully expanded entry

  • Detects circular references

If a circular reference is found, return:

{ circular: true }

Input Example

const entries = {
  "1": {
    id: "1",
    type: "page",
    fields: {
      title: "Home",
      hero: { ref: "2" },
      footer: { ref: "3" }
    }
  },
  "2": {
    id: "2",
    type: "hero",
    fields: {
      heading: "Welcome",
      cta: { ref: "4" }
    }
  },
  "3": {
    id: "3",
    type: "footer",
    fields: {
      text: "© 2026"
    }
  },
  "4": {
    id: "4",
    type: "button",
    fields: {
      label: "Get Started",
      link: "/start"
    }
  }
};

Call:

resolveEntry("1", entries)

Expected Output (Simplified)

{
  id: "1",
  type: "page",
  fields: {
    title: "Home",
    hero: {
      id: "2",
      type: "hero",
      fields: {
        heading: "Welcome",
        cta: {
          id: "4",
          type: "button",
          fields: {
            label: "Get Started",
            link: "/start"
          }
        }
      }
    },
    footer: {
      id: "3",
      type: "footer",
      fields: {
        text: "© 2026"
      }
    }
  }
}

Circular Reference Example

const entries = {
  "A": {
    id: "A",
    type: "page",
    fields: {
      child: { ref: "B" }
    }
  },
  "B": {
    id: "B",
    type: "block",
    fields: {
      parent: { ref: "A" }
    }
  }
};

Expected output:

{ circular: true }

Notes

  • You can assume entries contains all referenced IDs

  • Focus on correctness, readability, and approach

  • Pseudocode is acceptable if you get stuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment