sourcegraph/dev/src-search-meta.sh
Camden Cheek 4239fe8a45
GraphQL: remove deprecated resultCount field (#31573)
The resultCount field was marked as deprecated back in 2019, but is
still seeing new uses. This removes remaining references to it and
removes it since all clients should now be using `matchCount`.
2022-02-21 12:03:36 -07:00

53 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Bash script to query sourcegraph search API via graphql. It only returns
# meta information (such as result count), not the actual results. This is
# especially useful for viewing traces with large result.
# shellcheck disable=SC2016
query='query($q: String!) {
site {
buildVersion
}
search(query: $q) {
results {
limitHit
matchCount
elapsedMilliseconds
...SearchResultsAlertFields
}
}
}
fragment SearchResultsAlertFields on SearchResults {
alert {
title
description
proposedQueries {
description
query
}
}
}'
q="$1"
body="$(jq -n --arg query "$query" --arg q "$q" '{"query": $query, "variables": {"q": $q}}')"
endpoint=${SRC_ENDPOINT:-https://sourcegraph.com}
# Create and capture request/response headers
headers="$(mktemp -d)" || exit 1
trap 'rm -rf "$headers"' EXIT
echo 'X-Sourcegraph-Should-Trace: 1' >>"$headers/request"
if [ -n "$SRC_ACCESS_TOKEN" ]; then
echo "Authorization: token $SRC_ACCESS_TOKEN" >>"$headers/request"
fi
curl --silent \
-H "@$headers/request" \
-d "$body" \
-D "$headers/response" \
"$endpoint/.api/graphql?SearchMeta" | jq .
grep x-trace "$headers/response"