|
1 | 1 | import { isEqual } from 'lodash' |
2 | 2 | import { Observable } from 'rxjs' |
3 | | -import { distinctUntilChanged, map, mergeMap } from 'rxjs/operators' |
| 3 | +import { catchError, distinctUntilChanged, map, mergeMap, switchMap } from 'rxjs/operators' |
4 | 4 | import { SearchOptions } from '.' |
5 | 5 | import { gql, queryGraphQL } from '../backend/graphql' |
6 | 6 | import * as GQL from '../backend/graphqlschema' |
7 | 7 | import { mutateConfigurationGraphQL } from '../configuration/backend' |
| 8 | +import { ExtensionsControllerProps } from '../extensions/ExtensionsClientCommonContext' |
8 | 9 | import { currentConfiguration } from '../settings/configuration' |
9 | | -import { createAggregateError } from '../util/errors' |
| 10 | +import { asError, createAggregateError, ErrorLike } from '../util/errors' |
10 | 11 |
|
11 | | -export function search(options: SearchOptions): Observable<GQL.ISearchResults> { |
12 | | - return queryGraphQL( |
13 | | - gql` |
14 | | - query Search($query: String!) { |
15 | | - search(query: $query) { |
16 | | - results { |
17 | | - __typename |
18 | | - limitHit |
19 | | - resultCount |
20 | | - approximateResultCount |
21 | | - missing { |
22 | | - name |
23 | | - } |
24 | | - cloning { |
25 | | - name |
26 | | - } |
27 | | - timedout { |
28 | | - name |
29 | | - } |
30 | | - indexUnavailable |
31 | | - dynamicFilters { |
32 | | - value |
33 | | - label |
34 | | - count |
35 | | - limitHit |
36 | | - kind |
37 | | - } |
38 | | - results { |
39 | | - ... on Repository { |
| 12 | +export function search( |
| 13 | + options: SearchOptions, |
| 14 | + { extensionsController }: ExtensionsControllerProps |
| 15 | +): Observable<GQL.ISearchResults | ErrorLike> { |
| 16 | + /** |
| 17 | + * Emits whenever a search is executed, and whenever an extension registers a query transformer. |
| 18 | + */ |
| 19 | + return extensionsController.registries.queryTransformer.transformQuery(options.query).pipe( |
| 20 | + switchMap(query => |
| 21 | + queryGraphQL( |
| 22 | + gql` |
| 23 | + query Search($query: String!) { |
| 24 | + search(query: $query) { |
| 25 | + results { |
40 | 26 | __typename |
41 | | - id |
42 | | - name |
43 | | - url |
44 | | - } |
45 | | - ... on FileMatch { |
46 | | - __typename |
47 | | - file { |
48 | | - path |
49 | | - url |
50 | | - commit { |
51 | | - oid |
52 | | - } |
53 | | - } |
54 | | - repository { |
55 | | - name |
56 | | - url |
57 | | - } |
58 | 27 | limitHit |
59 | | - symbols { |
| 28 | + resultCount |
| 29 | + approximateResultCount |
| 30 | + missing { |
60 | 31 | name |
61 | | - containerName |
62 | | - url |
63 | | - kind |
64 | | - } |
65 | | - lineMatches { |
66 | | - preview |
67 | | - lineNumber |
68 | | - offsetAndLengths |
69 | 32 | } |
70 | | - } |
71 | | - ... on CommitSearchResult { |
72 | | - __typename |
73 | | - refs { |
| 33 | + cloning { |
74 | 34 | name |
75 | | - displayName |
76 | | - prefix |
77 | | - repository { |
78 | | - name |
79 | | - } |
80 | 35 | } |
81 | | - sourceRefs { |
| 36 | + timedout { |
82 | 37 | name |
83 | | - displayName |
84 | | - prefix |
85 | | - repository { |
86 | | - name |
87 | | - } |
88 | | - } |
89 | | - messagePreview { |
90 | | - value |
91 | | - highlights { |
92 | | - line |
93 | | - character |
94 | | - length |
95 | | - } |
96 | 38 | } |
97 | | - diffPreview { |
| 39 | + indexUnavailable |
| 40 | + dynamicFilters { |
98 | 41 | value |
99 | | - highlights { |
100 | | - line |
101 | | - character |
102 | | - length |
103 | | - } |
| 42 | + label |
| 43 | + count |
| 44 | + limitHit |
| 45 | + kind |
104 | 46 | } |
105 | | - commit { |
106 | | - id |
107 | | - repository { |
| 47 | + results { |
| 48 | + ... on Repository { |
| 49 | + __typename |
| 50 | + id |
108 | 51 | name |
109 | 52 | url |
110 | 53 | } |
111 | | - oid |
112 | | - abbreviatedOID |
113 | | - author { |
114 | | - person { |
| 54 | + ... on FileMatch { |
| 55 | + __typename |
| 56 | + file { |
| 57 | + path |
| 58 | + url |
| 59 | + commit { |
| 60 | + oid |
| 61 | + } |
| 62 | + } |
| 63 | + repository { |
| 64 | + name |
| 65 | + url |
| 66 | + } |
| 67 | + limitHit |
| 68 | + symbols { |
| 69 | + name |
| 70 | + containerName |
| 71 | + url |
| 72 | + kind |
| 73 | + } |
| 74 | + lineMatches { |
| 75 | + preview |
| 76 | + lineNumber |
| 77 | + offsetAndLengths |
| 78 | + } |
| 79 | + } |
| 80 | + ... on CommitSearchResult { |
| 81 | + __typename |
| 82 | + refs { |
| 83 | + name |
115 | 84 | displayName |
116 | | - avatarURL |
| 85 | + prefix |
| 86 | + repository { |
| 87 | + name |
| 88 | + } |
| 89 | + } |
| 90 | + sourceRefs { |
| 91 | + name |
| 92 | + displayName |
| 93 | + prefix |
| 94 | + repository { |
| 95 | + name |
| 96 | + } |
| 97 | + } |
| 98 | + messagePreview { |
| 99 | + value |
| 100 | + highlights { |
| 101 | + line |
| 102 | + character |
| 103 | + length |
| 104 | + } |
| 105 | + } |
| 106 | + diffPreview { |
| 107 | + value |
| 108 | + highlights { |
| 109 | + line |
| 110 | + character |
| 111 | + length |
| 112 | + } |
| 113 | + } |
| 114 | + commit { |
| 115 | + id |
| 116 | + repository { |
| 117 | + name |
| 118 | + url |
| 119 | + } |
| 120 | + oid |
| 121 | + abbreviatedOID |
| 122 | + author { |
| 123 | + person { |
| 124 | + displayName |
| 125 | + avatarURL |
| 126 | + } |
| 127 | + date |
| 128 | + } |
| 129 | + message |
| 130 | + url |
| 131 | + tree(path: "") { |
| 132 | + canonicalURL |
| 133 | + } |
117 | 134 | } |
118 | | - date |
119 | 135 | } |
120 | | - message |
121 | | - url |
122 | | - tree(path: "") { |
123 | | - canonicalURL |
| 136 | + } |
| 137 | + alert { |
| 138 | + title |
| 139 | + description |
| 140 | + proposedQueries { |
| 141 | + description |
| 142 | + query |
124 | 143 | } |
125 | 144 | } |
| 145 | + elapsedMilliseconds |
126 | 146 | } |
127 | 147 | } |
128 | | - alert { |
129 | | - title |
130 | | - description |
131 | | - proposedQueries { |
132 | | - description |
133 | | - query |
134 | | - } |
135 | | - } |
136 | | - elapsedMilliseconds |
137 | 148 | } |
138 | | - } |
139 | | - } |
140 | | - `, |
141 | | - { query: options.query } |
142 | | - ).pipe( |
143 | | - map(({ data, errors }) => { |
144 | | - if (!data || !data.search || !data.search.results) { |
145 | | - throw createAggregateError(errors) |
146 | | - } |
147 | | - return data.search.results |
148 | | - }) |
| 149 | + `, |
| 150 | + { query } |
| 151 | + ).pipe( |
| 152 | + map(({ data, errors }) => { |
| 153 | + if (!data || !data.search || !data.search.results) { |
| 154 | + throw createAggregateError(errors) |
| 155 | + } |
| 156 | + return data.search.results |
| 157 | + }), |
| 158 | + catchError(error => [asError(error)]) |
| 159 | + ) |
| 160 | + ) |
149 | 161 | ) |
150 | 162 | } |
151 | 163 |
|
|
0 commit comments