private function resolveGraph(array ...$packages): array
    {
        $graph = array_reduce(
            $packages,
            function (array $carry, array $package): array {
                foreach (array_keys($package['require'] ?? []) as $link) {
                    if (!preg_match('/^[^\/]+\/[^\/]+$/', $link)) {
                        // Most likely a platform requirement.
                        // E.g.: php
                        // E.g.: ext-openssl
                        continue;
                    }

                    if (!array_key_exists($link, $carry)) {
                        $carry[$link] = [];
                    }

                    if (!in_array($package['name'], $carry[$link], true)) {
                        $carry[$link][] = $package['name'];
                    }
                }

                return $carry;
            },
            []
        );

        // While the graph keeps receiving updates, keep on resolving.
        for ($previousGraph = []; $graph !== $previousGraph;) {
            // Do not update the previous graph before the current iteration
            // has started.
            $previousGraph = $graph;

            // For each package and its dependents in the graph ...
            foreach ($graph as $package => $dependents) {
                // ... Update the dependents of the package with grandparents.
                $graph[$package] = array_reduce(
                    // Determine grandparents by looking up the parents of the
                    // available dependents.
                    $dependents,
                    function (array $carry, string $parent) use ($graph): array {
                        foreach ($graph[$parent] ?? [] as $grandparent) {
                            if (!in_array($grandparent, $carry, true)) {
                                $carry[] = $grandparent;
                            }
                        }

                        return $carry;
                    },
                    // Start out with the current list of dependents.
                    $dependents
                );
            }
        }

        return $graph;
    }