forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc-search-meta.sh
More file actions
executable file
·52 lines (44 loc) · 1.18 KB
/
src-search-meta.sh
File metadata and controls
executable file
·52 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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"