Skip to content

Commit

Permalink
First pass at integrating Garrett's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dariober committed Aug 2, 2023
1 parent 2d7e2fb commit 0c6798a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/apollo-schemas/src/feature.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ FeatureSchema.add({ children: { type: Map, of: FeatureSchema } })

FeatureSchema.index({ refSeq: 1, start: 1 })
FeatureSchema.index({ refSeq: 1, end: 1 })
FeatureSchema.index({ '$**': 'text' })
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@ export class ApolloTextSearchAdapter
}

get trackId() {
return readConfObject(this.config, 'trackId').uri
return readConfObject(this.config, 'trackId')
}

get internetAccountPreAuthorization():
| { authInfo: { token: string }; internetAccountType: string }
| undefined {
return readConfObject(this.config, 'baseURL')
.internetAccountPreAuthorization
get assemblyNames() {
return readConfObject(this.config, 'assemblyNames')
}

async searchFeatures(term: string) {
const url = new URL(`features/searchFeatures?term=${term}`, this.baseURL)
const assemblies = this.assemblyNames.join(',')
const url = new URL('features/searchFeatures', this.baseURL)
const searchParams = new URLSearchParams({ assemblies, term })
url.search = searchParams.toString()
const uri = url.toString()

const location: UriLocation = { locationType: 'UriLocation', uri }
if (this.internetAccountPreAuthorization) {
location.internetAccountPreAuthorization =
this.internetAccountPreAuthorization
}
const fetch = getFetcher(location, this.pluginManager)
return fetch(uri)
.then((res) => res.json())
.catch((err) => err)
const response = await fetch(uri)
return response.json()
}

mapBaseResult(
Expand All @@ -53,18 +49,16 @@ export class ApolloTextSearchAdapter
(feature) =>
new BaseResult({
label: query,
displayString: query,
trackId: this.trackId,
locString: `${feature.refSeq?.name}:${feature.start}..${feature.end}`,
}),
)
}

searchIndex(args: BaseTextSearchArgs): Promise<BaseResult[]> {
async searchIndex(args: BaseTextSearchArgs): Promise<BaseResult[]> {
const query = args.queryString
return this.searchFeatures(query)
.then((features) => this.mapBaseResult(features, query))
.catch((err) => err)
const features = await this.searchFeatures(query)
return this.mapBaseResult(features, query)
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down

0 comments on commit 0c6798a

Please sign in to comment.