From e6a6338f06047b6a850d8608468310a3bc3494ae Mon Sep 17 00:00:00 2001 From: adf-ncgr Date: Wed, 10 Jan 2024 11:55:48 -0700 Subject: [PATCH] added linkouts queries/resolvers for GeneFamily and PanGeneSet (#126) * added linkouts queries/resolvers for GeneFamily and PanGeneSet; depends on https://github.com/legumeinfo/microservices/pull/613 * removed console.log debug --- .../microservices/microservices.api.ts | 22 +++++++++++++++++++ src/resolvers/intermine/gene-family.ts | 13 ++++++++--- src/resolvers/intermine/pan-gene-set.ts | 13 ++++++++--- src/resolvers/microservices/linkouts.ts | 8 +++++++ src/types/GeneFamily.graphql | 2 ++ src/types/PanGeneSet.graphql | 2 ++ src/types/Query.graphql | 10 +++++++++ 7 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/data-sources/microservices/microservices.api.ts b/src/data-sources/microservices/microservices.api.ts index ec9936f1..a13e2147 100644 --- a/src/data-sources/microservices/microservices.api.ts +++ b/src/data-sources/microservices/microservices.api.ts @@ -46,4 +46,26 @@ export class MicroservicesAPI extends RESTDataSource { return await this.post('genomic_region_linkouts', options); } + async getLinkoutsForGeneFamily(identifier: string): Promise { + 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 { + 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); + } + } diff --git a/src/resolvers/intermine/gene-family.ts b/src/resolvers/intermine/gene-family.ts index 82f7031d..10e51499 100644 --- a/src/resolvers/intermine/gene-family.ts +++ b/src/resolvers/intermine/gene-family.ts @@ -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): -ResolverMap => ({ +export const geneFamilyFactory = + ( + sourceName: KeyOfType, + microservicesSource: KeyOfType, + ): ResolverMap => ({ Query: { geneFamily: async (_, { identifier }, { dataSources }) => { const {data: family} = await dataSources[sourceName].getGeneFamily(identifier); @@ -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); + }, }, }); diff --git a/src/resolvers/intermine/pan-gene-set.ts b/src/resolvers/intermine/pan-gene-set.ts index 3322c090..34c3a175 100644 --- a/src/resolvers/intermine/pan-gene-set.ts +++ b/src/resolvers/intermine/pan-gene-set.ts @@ -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): -ResolverMap => ({ +export const panGeneSetFactory = + ( + sourceName: KeyOfType, + microservicesSource: KeyOfType, + ): ResolverMap => ({ Query: { panGeneSet: async (_, { identifier }, { dataSources }) => { const {data: panGeneSet} = await dataSources[sourceName].getPanGeneSet(identifier); @@ -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); + }, }, }); diff --git a/src/resolvers/microservices/linkouts.ts b/src/resolvers/microservices/linkouts.ts index 4e6a581a..f4fd6393 100644 --- a/src/resolvers/microservices/linkouts.ts +++ b/src/resolvers/microservices/linkouts.ts @@ -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})); + }, }, }); diff --git a/src/types/GeneFamily.graphql b/src/types/GeneFamily.graphql index cff5de97..9a940e6a 100644 --- a/src/types/GeneFamily.graphql +++ b/src/types/GeneFamily.graphql @@ -23,4 +23,6 @@ type GeneFamily implements Annotatable { genes: [Gene!]! proteinDomains: [ProteinDomain!]! tallies: [GeneFamilyTally!]! + ## microservices + linkouts: [Linkout!]! } diff --git a/src/types/PanGeneSet.graphql b/src/types/PanGeneSet.graphql index f6170f0a..1cea7694 100644 --- a/src/types/PanGeneSet.graphql +++ b/src/types/PanGeneSet.graphql @@ -13,5 +13,7 @@ type PanGeneSet implements Annotatable { dataSets: [DataSet!]! genes: [Gene!]! proteins: [Protein!]! + ## microservices + linkouts: [Linkout!]! } diff --git a/src/types/Query.graphql b/src/types/Query.graphql index 90d5db2f..4803af49 100644 --- a/src/types/Query.graphql +++ b/src/types/Query.graphql @@ -256,6 +256,14 @@ type LocationLinkoutsResults { results: [Linkout!]! } +type GeneFamilyLinkoutsResults { + results: [Linkout!]! +} + +type PanGeneSetLinkoutsResults { + results: [Linkout!]! +} + # Top-level queries @@ -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 }