Skip to content

Commit

Permalink
added linkouts queries/resolvers for GeneFamily and PanGeneSet (#126)
Browse files Browse the repository at this point in the history
* added linkouts queries/resolvers for GeneFamily and PanGeneSet; depends on legumeinfo/microservices#613

* removed console.log debug
  • Loading branch information
adf-ncgr authored Jan 10, 2024
1 parent 0f586d6 commit e6a6338
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/data-sources/microservices/microservices.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,26 @@ export class MicroservicesAPI extends RESTDataSource {
return await this.post('genomic_region_linkouts', options);
}

async getLinkoutsForGeneFamily(identifier: string): Promise<GraphQLLinkout[]> {
const options = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({gene_families: [identifier]}),
};
return await this.post('gene_family_linkouts', options);
}

async getLinkoutsForPanGeneSet(identifier: string): Promise<GraphQLLinkout[]> {
const options = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({pan_gene_sets: [identifier]}),
};
return await this.post('pan_gene_set_linkouts', options);
}

}
13 changes: 10 additions & 3 deletions src/resolvers/intermine/gene-family.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { DataSources, IntermineAPI } from '../../data-sources/index.js';
import { DataSources, IntermineAPI, MicroservicesAPI } from '../../data-sources/index.js';
import { inputError, KeyOfType } from '../../utils/index.js';
import { ResolverMap } from '../resolver.js';
import { annotatableFactory } from './annotatable.js';


export const geneFamilyFactory = (sourceName: KeyOfType<DataSources, IntermineAPI>):
ResolverMap => ({
export const geneFamilyFactory =
(
sourceName: KeyOfType<DataSources, IntermineAPI>,
microservicesSource: KeyOfType<DataSources, MicroservicesAPI>,
): ResolverMap => ({
Query: {
geneFamily: async (_, { identifier }, { dataSources }) => {
const {data: family} = await dataSources[sourceName].getGeneFamily(identifier);
Expand Down Expand Up @@ -48,5 +51,9 @@ ResolverMap => ({
// @ts-ignore: implicit type any error
.then(({data: results}) => results);
},
linkouts: async (geneFamily, _, { dataSources }) => {
const {identifier} = geneFamily;
return dataSources[microservicesSource].getLinkoutsForGeneFamily(identifier);
},
},
});
13 changes: 10 additions & 3 deletions src/resolvers/intermine/pan-gene-set.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { DataSources, IntermineAPI } from '../../data-sources/index.js';
import { DataSources, IntermineAPI, MicroservicesAPI } from '../../data-sources/index.js';
import { inputError, KeyOfType } from '../../utils/index.js';
import { ResolverMap } from '../resolver.js';
import { annotatableFactory } from './annotatable.js';


export const panGeneSetFactory = (sourceName: KeyOfType<DataSources, IntermineAPI>):
ResolverMap => ({
export const panGeneSetFactory =
(
sourceName: KeyOfType<DataSources, IntermineAPI>,
microservicesSource: KeyOfType<DataSources, MicroservicesAPI>,
): ResolverMap => ({
Query: {
panGeneSet: async (_, { identifier }, { dataSources }) => {
const {data: panGeneSet} = await dataSources[sourceName].getPanGeneSet(identifier);
Expand Down Expand Up @@ -36,5 +39,9 @@ ResolverMap => ({
// @ts-ignore: implicit type any error
.then(({data: results}) => results);
},
linkouts: async (panGeneSet, _, { dataSources }) => {
const {identifier} = panGeneSet;
return dataSources[microservicesSource].getLinkoutsForPanGeneSet(identifier);
},
},
});
8 changes: 8 additions & 0 deletions src/resolvers/microservices/linkouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ ResolverMap => ({
return dataSources[sourceName].getLinkoutsForLocation(identifier, start, end)
.then((results) => ({results}));
},
geneFamilyLinkouts: async (_, { identifier }, { dataSources }) => {
return dataSources[sourceName].getLinkoutsForGeneFamily(identifier)
.then((results) => ({results}));
},
panGeneSetLinkouts: async (_, { identifier }, { dataSources }) => {
return dataSources[sourceName].getLinkoutsForPanGeneSet(identifier)
.then((results) => ({results}));
},
},
});
2 changes: 2 additions & 0 deletions src/types/GeneFamily.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ type GeneFamily implements Annotatable {
genes: [Gene!]!
proteinDomains: [ProteinDomain!]!
tallies: [GeneFamilyTally!]!
## microservices
linkouts: [Linkout!]!
}
2 changes: 2 additions & 0 deletions src/types/PanGeneSet.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ type PanGeneSet implements Annotatable {
dataSets: [DataSet!]!
genes: [Gene!]!
proteins: [Protein!]!
## microservices
linkouts: [Linkout!]!
}

10 changes: 10 additions & 0 deletions src/types/Query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ type LocationLinkoutsResults {
results: [Linkout!]!
}

type GeneFamilyLinkoutsResults {
results: [Linkout!]!
}

type PanGeneSetLinkoutsResults {
results: [Linkout!]!
}


# Top-level queries

Expand Down Expand Up @@ -328,5 +336,7 @@ type Query {
### microservices queries
geneLinkouts(identifier: ID!): GeneLinkoutsResults
locationLinkouts(identifier: ID!, start: Int!, end: Int!): LocationLinkoutsResults
geneFamilyLinkouts(identifier: ID!): GeneFamilyLinkoutsResults
panGeneSetLinkouts(identifier: ID!): PanGeneSetLinkoutsResults

}

0 comments on commit e6a6338

Please sign in to comment.