From 97a0747b396e609dbc920906d93e96ccdcedc0fe Mon Sep 17 00:00:00 2001 From: Amr Elsagaei Date: Sat, 28 Mar 2026 13:16:50 -0300 Subject: [PATCH 1/3] Fix #12 GraphQL request detection --- .../frontend/src/views/GraphQLViewMode.vue | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/views/GraphQLViewMode.vue b/packages/frontend/src/views/GraphQLViewMode.vue index 67f21a4..14dca18 100644 --- a/packages/frontend/src/views/GraphQLViewMode.vue +++ b/packages/frontend/src/views/GraphQLViewMode.vue @@ -30,6 +30,7 @@ type MinimalEditorView = { }; const cachedEditorView = ref(undefined); +const cachedRawData = ref(""); const originalQuery = ref(""); const originalVariables = ref("{}"); @@ -79,14 +80,27 @@ const parseHttpRaw = (raw: string) => { return { method, headers, body }; }; -const getRawData = computed((): string => { +const isHttpRequestRaw = (raw: string): boolean => { + if (raw === undefined || raw === "") return false; + const firstLine = raw.trimStart().split(/\r?\n/)[0] ?? ""; + return /^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+/i.test(firstLine); +}; + +const resolveRawData = (): string => { if (isReplayTab.value) { const editor = props.sdk.window?.getActiveEditor?.(); if (editor !== undefined && editor !== null) { const editorView = editor.getEditorView(); if (editorView !== undefined && editorView !== null) { const raw = editorView.state.doc.toString(); - if (raw !== undefined && raw !== null && raw !== "") return raw; + if ( + raw !== undefined && + raw !== null && + raw !== "" && + isHttpRequestRaw(raw) + ) { + return raw; + } } } } @@ -96,8 +110,27 @@ const getRawData = computed((): string => { } return ""; +}; + +const getRawData = computed((): string => { + const raw = resolveRawData(); + if (raw !== "") { + return raw; + } + + return cachedRawData.value; }); +watch( + getRawData, + (newValue) => { + if (newValue !== "" && isHttpRequestRaw(newValue)) { + cachedRawData.value = newValue; + } + }, + { immediate: true }, +); + const tryGetEditorView = () => { const editor = props.sdk.window?.getActiveEditor?.(); if (editor !== undefined && editor !== null) { From 110eebffca4763d586b00644ccd0df43aba716f0 Mon Sep 17 00:00:00 2001 From: Amr Elsagaei Date: Thu, 2 Apr 2026 09:48:09 -0300 Subject: [PATCH 2/3] Update GraphQLViewMode.vue --- .../frontend/src/views/GraphQLViewMode.vue | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/packages/frontend/src/views/GraphQLViewMode.vue b/packages/frontend/src/views/GraphQLViewMode.vue index 14dca18..0db6681 100644 --- a/packages/frontend/src/views/GraphQLViewMode.vue +++ b/packages/frontend/src/views/GraphQLViewMode.vue @@ -30,7 +30,6 @@ type MinimalEditorView = { }; const cachedEditorView = ref(undefined); -const cachedRawData = ref(""); const originalQuery = ref(""); const originalVariables = ref("{}"); @@ -80,13 +79,11 @@ const parseHttpRaw = (raw: string) => { return { method, headers, body }; }; -const isHttpRequestRaw = (raw: string): boolean => { - if (raw === undefined || raw === "") return false; - const firstLine = raw.trimStart().split(/\r?\n/)[0] ?? ""; - return /^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+/i.test(firstLine); +const isResponseContent = (raw: string): boolean => { + return raw.trimStart().startsWith("HTTP/"); }; -const resolveRawData = (): string => { +const getRawData = computed((): string => { if (isReplayTab.value) { const editor = props.sdk.window?.getActiveEditor?.(); if (editor !== undefined && editor !== null) { @@ -97,12 +94,24 @@ const resolveRawData = (): string => { raw !== undefined && raw !== null && raw !== "" && - isHttpRequestRaw(raw) + !isResponseContent(raw) ) { return raw; } } } + + if (cachedEditorView.value !== undefined) { + const raw = cachedEditorView.value.state.doc.toString(); + if ( + raw !== undefined && + raw !== null && + raw !== "" && + !isResponseContent(raw) + ) { + return raw; + } + } } if (props.request?.raw) { @@ -110,27 +119,8 @@ const resolveRawData = (): string => { } return ""; -}; - -const getRawData = computed((): string => { - const raw = resolveRawData(); - if (raw !== "") { - return raw; - } - - return cachedRawData.value; }); -watch( - getRawData, - (newValue) => { - if (newValue !== "" && isHttpRequestRaw(newValue)) { - cachedRawData.value = newValue; - } - }, - { immediate: true }, -); - const tryGetEditorView = () => { const editor = props.sdk.window?.getActiveEditor?.(); if (editor !== undefined && editor !== null) { From b68c2a759929b4f71359b50218a418bfe0f20602 Mon Sep 17 00:00:00 2001 From: Amr Elsagaei Date: Fri, 10 Apr 2026 09:52:27 -0300 Subject: [PATCH 3/3] adding isResponseContent to avoid dupes --- .mise/config.toml | 10 ++++++++++ packages/frontend/src/views/GraphQLViewMode.vue | 17 ++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.mise/config.toml b/.mise/config.toml index 8147ce5..322620f 100644 --- a/.mise/config.toml +++ b/.mise/config.toml @@ -1,3 +1,13 @@ [tools] node = "22" pnpm = "9" + +[tasks.validate] +description = "Run all validation checks (install, typecheck, lint, test, knip)" +run = """ +pnpm install --frozen-lockfile +pnpm typecheck +pnpm lint +pnpm test +pnpm knip +""" diff --git a/packages/frontend/src/views/GraphQLViewMode.vue b/packages/frontend/src/views/GraphQLViewMode.vue index 0db6681..d3c4560 100644 --- a/packages/frontend/src/views/GraphQLViewMode.vue +++ b/packages/frontend/src/views/GraphQLViewMode.vue @@ -79,7 +79,8 @@ const parseHttpRaw = (raw: string) => { return { method, headers, body }; }; -const isResponseContent = (raw: string): boolean => { +const isResponseContent = (raw: string | undefined): boolean => { + if (raw === undefined || raw === "") return true; return raw.trimStart().startsWith("HTTP/"); }; @@ -90,12 +91,7 @@ const getRawData = computed((): string => { const editorView = editor.getEditorView(); if (editorView !== undefined && editorView !== null) { const raw = editorView.state.doc.toString(); - if ( - raw !== undefined && - raw !== null && - raw !== "" && - !isResponseContent(raw) - ) { + if (!isResponseContent(raw)) { return raw; } } @@ -103,12 +99,7 @@ const getRawData = computed((): string => { if (cachedEditorView.value !== undefined) { const raw = cachedEditorView.value.state.doc.toString(); - if ( - raw !== undefined && - raw !== null && - raw !== "" && - !isResponseContent(raw) - ) { + if (!isResponseContent(raw)) { return raw; } }