From 320f173f98c21ef27aab584730cbcd9846871593 Mon Sep 17 00:00:00 2001 From: Beast Date: Thu, 13 Aug 2026 13:18:18 +0800 Subject: [PATCH] fix: search query --- src/api/search.tsx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/api/search.tsx b/src/api/search.tsx index e4d99ef..15a217a 100644 --- a/src/api/search.tsx +++ b/src/api/search.tsx @@ -51,6 +51,17 @@ export const getSearchVariables = (oriKeyword: string) => { }; }; +/** Only include variables declared by the query for this shape. */ +function graphqlVariablesForShape( + variables: ReturnType +) { + const { shape, keyword, keyword_number, limit } = variables; + if (shape === 'numeric') { + return { keyword, keyword_number, limit }; + } + return { keyword, limit }; +} + const SEARCH_HEX = gql` query SearchHex($keyword: String, $limit: Int) { transactions: unified_transaction( @@ -170,11 +181,7 @@ export const search = (fetcher: DataFetcher) => ({ const result = await fetcher.graphql>( { query: getGqlString(document), - variables: { - keyword: variables.keyword, - keyword_number: variables.keyword_number, - limit: variables.limit - }, + variables: graphqlVariablesForShape(variables), operationName: operationNameForShape(variables.shape) }, { @@ -195,11 +202,7 @@ export const search = (fetcher: DataFetcher) => ({ const document = documentForShape(variables.shape); const result = useQuery(document, { ...config, - variables: { - keyword: variables.keyword, - keyword_number: variables.keyword_number, - limit: variables.limit - } + variables: graphqlVariablesForShape(variables) } as QueryHookOptions); return {