Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show graphql operation name for graphql requests #1521

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ function buildToolbar(commandPayload, copyToClipboard: (text: string) => void) {
return toolbarItems
}

export function formatOperationName(requestData: string): string {
try {
const parsedData = JSON.parse(requestData)
return parsedData?.operationName?.toString() || ""
} catch (_err) {
return ""
}
}

const ApiResponseCommand: FunctionComponent<Props> = ({
command,
copyToClipboard,
Expand All @@ -137,7 +146,9 @@ const ApiResponseCommand: FunctionComponent<Props> = ({
const { duration, request, response } = payload

const cleanedUrl = request.url.replace(/^http(s):\/\/[^/]+/i, "").replace(/\?.*$/i, "")
const preview = `${(request.method || "").toUpperCase()} ${cleanedUrl}`
const operationName = formatOperationName(request.data)

const preview = `${(request.method || "").toUpperCase()} ${cleanedUrl} ${operationName}`
yurik256 marked this conversation as resolved.
Show resolved Hide resolved

const summary = {
"Status Code": response.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const TEST_COMMANDS = [
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } },
{ type: "log", payload: { debug: "LOGDEBUG" } },
{ type: "client.intro", payload: { connection: "SEARCHCONNECTION" } },
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
]

const TESTS = [
Expand Down Expand Up @@ -51,6 +59,20 @@ const TESTS = [
search: "SEARCHURL",
result: [{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } }],
},
{
name: "payload.request.data",
search: "SEARCHDATA",
result: [
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
],
},
{
name: "log => debug",
search: "debug",
Expand Down Expand Up @@ -82,6 +104,14 @@ const TESTS = [
{ type: "ADUMMYOBJ", payload: { triggerType: "SEARCHTRIGGERTYPE" } },
{ type: "ADUMMYOBJ", payload: { description: "SEARCHDESCRIPTION" } },
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } },
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
],
},
{
Expand All @@ -96,6 +126,14 @@ const TESTS = [
{ type: "ADUMMYOBJ", payload: { triggerType: "SEARCHTRIGGERTYPE" } },
{ type: "ADUMMYOBJ", payload: { description: "SEARCHDESCRIPTION" } },
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } },
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
],
},
{
Expand All @@ -104,6 +142,14 @@ const TESTS = [
result: [
{ type: "ADUMMYOBJ", payload: { message: "SEARCHMESSAGE" } },
{ type: "ADUMMYOBJ", payload: { name: "SEARCHNAME" } },
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
],
},
{
Expand All @@ -112,6 +158,14 @@ const TESTS = [
result: [
{ type: "ADUMMYOBJ", payload: { message: "SEARCHMESSAGE" } },
{ type: "ADUMMYOBJ", payload: { name: "SEARCHNAME" } },
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
],
},
{
Expand All @@ -125,6 +179,14 @@ const TESTS = [
{ type: "ADUMMYOBJ", payload: { triggerType: "SEARCHTRIGGERTYPE" } },
{ type: "ADUMMYOBJ", payload: { description: "SEARCHDESCRIPTION" } },
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } },
{
type: "ADUMMYOBJ",
payload: {
request: {
data: '{"operationName":"SEARCHDATA","variables":{"testing":{"nested":"thing"}},"query":"query LaunchList {\\n launches {\\n id\\n }\\n}\\n"}',
},
},
},
],
},
]
Expand Down
3 changes: 2 additions & 1 deletion lib/reactotron-core-ui/src/utils/filterCommands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const COMMON_MATCHING_PATHS = [
path("payload", "triggerType"),
path("payload", "description"),
path("payload", "request", "url"),
path("payload", "request", "data"),
]

export function filterSearch(commands: any[], search: string) {
Expand All @@ -34,7 +35,7 @@ export function filterSearch(commands: any[], search: string) {
const searchRegex = new RegExp(trimmedSearch.replace(/\s/, "."), "i")

const matching = (value: string) => {
if(!value) {
if (!value) {
return false
}

Expand Down