Files
BrowserOS/apps/agent/lib/graphql/getQueryKeyFromDocument.ts
Nikhil cb8aa6c60e feat: fix new cdp tests for tools (#358)
* feat: new tools tests

* fix: lint warnings by disabling or TODO

* fix: minore update to branch cleaner
2026-02-23 16:08:34 -08:00

26 lines
746 B
TypeScript

import { parse } from 'graphql'
import type { TypedDocumentString } from '@/generated/graphql/graphql'
const getOperationName = <T, V>(
doc: TypedDocumentString<T, V>,
): string | null => {
// Fallback to parsing
const parsed = parse(doc.toString())
const operation = parsed.definitions.find(
(def) => def.kind === 'OperationDefinition',
)
return operation?.name ? operation.name.value : null
}
export const getQueryKeyFromDocument = <
TResult,
// biome-ignore lint/suspicious/noExplicitAny: TODO(dani) type GraphQL variables properly
TVariables extends Record<string, any> | undefined = undefined,
>(
doc: TypedDocumentString<TResult, TVariables>,
) => {
const queryName = getOperationName(doc)
return queryName
}