Skip to content

Commit 8d5ca12

Browse files
authored
fix(graph): serve full project graph when navigating from PDV (#33897)
1 parent 4493157 commit 8d5ca12

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

graph/client/src/app/routes.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export function getRoutesForEnvironment() {
3030
}
3131
}
3232

33-
const workspaceDataLoader = async (selectedWorkspaceId: string) => {
33+
const workspaceDataLoader = async (
34+
selectedWorkspaceId: string,
35+
requestFull = false
36+
) => {
3437
const workspaceInfo = appConfig.workspaces.find(
3538
(graph) => graph.id === selectedWorkspaceId
3639
);
@@ -43,7 +46,8 @@ const workspaceDataLoader = async (selectedWorkspaceId: string) => {
4346

4447
const projectGraph: ProjectGraphClientResponse =
4548
await projectGraphDataService.getProjectGraph(
46-
workspaceInfo.projectGraphUrl
49+
workspaceInfo.projectGraphUrl,
50+
requestFull
4751
);
4852

4953
const targetsSet = new Set<string>();
@@ -291,7 +295,7 @@ export const devRoutes: RouteObject[] = [
291295
loader: async ({ params }) => {
292296
const selectedWorkspaceId =
293297
params.selectedWorkspaceId ?? appConfig.defaultWorkspaceId;
294-
return workspaceDataLoader(selectedWorkspaceId);
298+
return workspaceDataLoader(selectedWorkspaceId, true);
295299
},
296300
children: childRoutes,
297301
},
@@ -314,7 +318,7 @@ export const releaseRoutes: RouteObject[] = [
314318
id: 'selectedWorkspace',
315319
loader: async () => {
316320
const selectedWorkspaceId = appConfig.defaultWorkspaceId;
317-
return workspaceDataLoader(selectedWorkspaceId);
321+
return workspaceDataLoader(selectedWorkspaceId, true);
318322
},
319323
shouldRevalidate: () => {
320324
return false;

graph/shared/src/lib/project-graph-data-service/fetch-project-graph-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export class FetchProjectGraphService implements ProjectGraphService {
1616
return response.json();
1717
}
1818

19-
async getProjectGraph(url: string): Promise<ProjectGraphClientResponse> {
20-
const request = new Request(url, { mode: 'no-cors' });
19+
async getProjectGraph(
20+
url: string,
21+
requestFull = false
22+
): Promise<ProjectGraphClientResponse> {
23+
const requestUrl = requestFull ? `${url}?full=true` : url;
24+
const request = new Request(requestUrl, { mode: 'no-cors' });
2125

2226
const response = await fetch(request);
2327

graph/shared/src/lib/project-graph-data-service/get-project-graph-data-service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ let projectGraphService: ProjectGraphService;
1212

1313
export interface ProjectGraphService {
1414
getHash: () => Promise<string>;
15-
getProjectGraph: (url: string) => Promise<ProjectGraphClientResponse>;
15+
getProjectGraph: (
16+
url: string,
17+
requestFull?: boolean
18+
) => Promise<ProjectGraphClientResponse>;
1619
getTaskGraph: (url: string) => Promise<TaskGraphClientResponse>;
1720
getSpecificTaskGraph?: (
1821
url: string,

packages/nx/src/command-line/graph/graph.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ async function startServer(
641641

642642
currentSourceMapsClientResponse = sourceMapResponse;
643643

644+
isFilteredGraph = !!(focus || exclude.length > 0);
645+
644646
const app = http.createServer(async (req, res) => {
645647
// parse URL
646648
const parsedUrl = new URL(req.url, `http://${host}:${port}`);
@@ -653,6 +655,21 @@ async function startServer(
653655

654656
const sanitizePath = basename(parsedUrl.pathname);
655657
if (sanitizePath === 'project-graph.json') {
658+
const requestFull = parsedUrl.searchParams.get('full') === 'true';
659+
660+
// If client requests full graph and current is filtered, regenerate
661+
if (requestFull && isFilteredGraph) {
662+
const { projectGraphClientResponse, sourceMapResponse } =
663+
await createProjectGraphAndSourceMapClientResponse([], null, []);
664+
665+
currentProjectGraphClientResponse = projectGraphClientResponse;
666+
currentProjectGraphClientResponse.focus = null;
667+
currentProjectGraphClientResponse.groupByFolder = false;
668+
currentProjectGraphClientResponse.exclude = [];
669+
currentSourceMapsClientResponse = sourceMapResponse;
670+
isFilteredGraph = false;
671+
}
672+
656673
res.writeHead(200, { 'Content-Type': 'application/json' });
657674
res.end(JSON.stringify(currentProjectGraphClientResponse));
658675
return;
@@ -802,6 +819,7 @@ let currentProjectGraphClientResponse: ProjectGraphClientResponse = {
802819
errors: [],
803820
};
804821
let currentSourceMapsClientResponse: ConfigurationSourceMaps = {};
822+
let isFilteredGraph = false;
805823

806824
function debounce(fn: (...args) => void, time: number) {
807825
let timeout: NodeJS.Timeout;
@@ -834,8 +852,8 @@ function createFileWatcher() {
834852
const { projectGraphClientResponse, sourceMapResponse } =
835853
await createProjectGraphAndSourceMapClientResponse(
836854
[],
837-
currentProjectGraphClientResponse.focus,
838-
currentProjectGraphClientResponse.exclude
855+
isFilteredGraph ? currentProjectGraphClientResponse.focus : null,
856+
isFilteredGraph ? currentProjectGraphClientResponse.exclude : []
839857
);
840858

841859
if (

0 commit comments

Comments
 (0)