Skip to content
Merged
Changes from all 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
23 changes: 13 additions & 10 deletions src/api/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ export const getSearchVariables = (oriKeyword: string) => {
};
};

/** Only include variables declared by the query for this shape. */
function graphqlVariablesForShape(
variables: ReturnType<typeof getSearchVariables>
) {
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(
Expand Down Expand Up @@ -170,11 +181,7 @@ export const search = (fetcher: DataFetcher) => ({
const result = await fetcher.graphql<Partial<SearchAllResponse>>(
{
query: getGqlString(document),
variables: {
keyword: variables.keyword,
keyword_number: variables.keyword_number,
limit: variables.limit
},
variables: graphqlVariablesForShape(variables),
operationName: operationNameForShape(variables.shape)
},
{
Expand All @@ -195,11 +202,7 @@ export const search = (fetcher: DataFetcher) => ({
const document = documentForShape(variables.shape);
const result = useQuery<SearchAllResponse>(document, {
...config,
variables: {
keyword: variables.keyword,
keyword_number: variables.keyword_number,
limit: variables.limit
}
variables: graphqlVariablesForShape(variables)
} as QueryHookOptions<SearchAllResponse>);

return {
Expand Down
Loading