1
- from typing import Optional , List , Literal
1
+ from typing import Optional , List , Literal , Dict
2
2
3
3
import strawberry
4
4
from strawberry import Info
5
5
6
- from src .api_adapters .strawberry_models .class_generators import make_linked_list_result_type , make_resolve_result_type , \
7
- make_details_result_type , make_list_result_type
8
- from src .api_adapters .strawberry_models .input_types import FilterOption , ListFilterSettings , LinkedListFilterSettings , \
9
- ListQueryContext
10
- from src .api_adapters .strawberry_models .shared_query_models import Provenance
6
+ from src .api_adapters .strawberry_models .class_generators import make_linked_list_result_type
7
+ from src .api_adapters .strawberry_models .input_types import FilterOption , ListFilterSettings , LinkedListFilterSettings
8
+ from src .api_adapters .strawberry_models .shared_query_models import Provenance , generate_resolvers
11
9
from src .interfaces .result_types import LinkedListQueryContext
12
10
from src .interfaces .simple_enum import NodeLabel , RelationshipLabel
13
11
from src .models .analyte import Synonym
@@ -297,20 +295,6 @@ def provenance(root) -> Provenance:
297
295
298
296
evidence : List [GoEvidence ]
299
297
300
-
301
- ProteinListResult = make_list_result_type ("ProteinListResult" , Protein )
302
- GeneListResult = make_list_result_type ("GeneListResult" , Gene )
303
- TranscriptListResult = make_list_result_type ("TranscriptListResult" , Transcript )
304
- LigandListResult = make_list_result_type ("LigandListResult" , Ligand )
305
- GoTermListResult = make_list_result_type ("GoTermListResult" , GoTerm )
306
-
307
- ResolveProteinResult = make_resolve_result_type ("ResolveProteinResult" , Protein )
308
- ResolveGeneResult = make_resolve_result_type ("ResolveGeneResult" , Gene )
309
- ResolveTranscriptResult = make_resolve_result_type ("ResolveTranscriptResult" , Transcript )
310
- ResolveLigandResult = make_resolve_result_type ("ResolveLigandResult" , Ligand )
311
-
312
- GoTermResult = make_details_result_type ("GoTermResult" , GoTerm )
313
-
314
298
ProteinGeneQueryResult = make_linked_list_result_type ("ProteinGeneQueryResult" , "ProteinGeneDetails" , GeneProteinRelationship , Gene )
315
299
ProteinTranscriptQueryResult = make_linked_list_result_type ("ProteinTranscriptQueryResult" , "ProteinTranscriptDetails" , TranscriptProteinRelationship , Transcript )
316
300
ProteinGoTermQueryResult = make_linked_list_result_type ("ProteinGoTermQueryResult" , "ProteinGoTermDetails" , ProteinGoTermRelationship , GoTerm )
@@ -328,86 +312,32 @@ def provenance(root) -> Provenance:
328
312
329
313
LigandProteinQueryResult = make_linked_list_result_type ("LigandProteinQueryResult" , "LigandProteinDetails" , ProteinLigandRelationship , Protein )
330
314
331
-
332
-
333
- @strawberry .type
334
- class Query :
335
- @strawberry .field ()
336
- def proteins (self , info : Info , filter : Optional [ListFilterSettings ] = None ) -> ProteinListResult :
337
- api = info .context ["api" ]
338
- context = ListQueryContext (
339
- source_data_model = "Protein" ,
340
- filter = filter
341
- )
342
- result = api .get_list_obj (context )
343
- return result
344
-
345
- @strawberry .field ()
346
- def genes (self , info : Info , filter : Optional [ListFilterSettings ] = None ) -> GeneListResult :
347
- api = info .context ["api" ]
348
- context = ListQueryContext (
349
- source_data_model = "Gene" ,
350
- filter = filter
351
- )
352
- result = api .get_list_obj (context )
353
- return result
354
-
355
- @strawberry .field ()
356
- def transcripts (self , info : Info , filter : Optional [ListFilterSettings ] = None ) -> TranscriptListResult :
357
- api = info .context ["api" ]
358
- context = ListQueryContext (
359
- source_data_model = "Transcript" ,
360
- filter = filter
361
- )
362
- result = api .get_list_obj (context )
363
- return result
364
-
365
- @strawberry .field ()
366
- def ligands (self , info : Info , filter : Optional [ListFilterSettings ] = None ) -> LigandListResult :
367
- api = info .context ["api" ]
368
- context = ListQueryContext (
369
- source_data_model = "Ligand" ,
370
- filter = filter
371
- )
372
- result = api .get_list_obj (context )
373
- return result
374
-
375
- @strawberry .field ()
376
- def go_terms (self , info : Info , filter : Optional [ListFilterSettings ] = None ) -> GoTermListResult :
377
- api = info .context ["api" ]
378
- context = ListQueryContext (
379
- source_data_model = "GoTerm" ,
380
- filter = filter
381
- )
382
- result = api .get_list_obj (context )
383
- return result
384
-
385
- @strawberry .field ()
386
- def resolve_protein (self , info : Info , id : str ) -> ResolveProteinResult :
387
- api = info .context ["api" ]
388
- result = api .resolve_id ("Protein" , id = id , sortby = {"uniprot_reviewed" : "desc" , "uniprot_canonical" : "desc" , "mapping_ratio" : "desc" })
389
- return result
390
-
391
- @strawberry .field ()
392
- def resolve_gene (self , info : Info , id : str ) -> ResolveGeneResult :
393
- api = info .context ["api" ]
394
- result = api .resolve_id ("Gene" , id = id , sortby = {"mapping_ratio" : "desc" })
395
- return result
396
-
397
- @strawberry .field ()
398
- def resolve_transcript (self , info : Info , id : str ) -> ResolveTranscriptResult :
399
- api = info .context ["api" ]
400
- result = api .resolve_id ("Transcript" , id = id , sortby = {"mapping_ratio" : "desc" })
401
- return result
402
-
403
- @strawberry .field ()
404
- def resolve_ligand (self , info : Info , id : str ) -> ResolveLigandResult :
405
- api = info .context ["api" ]
406
- result = api .resolve_id ("Ligand" , id = id )
407
- return result
408
-
409
- @strawberry .field ()
410
- def go_term (self , info : Info , id : str ) -> GoTermResult :
411
- api = info .context ["api" ]
412
- result = api .get_details ("GoTerm" , id = id )
413
- return result
315
+ ENDPOINTS : Dict [type , Dict [str , str ]] = {
316
+ Protein : {
317
+ "list" : "proteins" ,
318
+ "details" : "resolve_protein" ,
319
+ "sortby" : {"uniprot_reviewed" : "desc" , "uniprot_canonical" : "desc" , "mapping_ratio" : "desc" }
320
+ },
321
+ Gene : {
322
+ "list" : "genes" ,
323
+ "details" : "resolve_gene" ,
324
+ "sortby" : {"mapping_ratio" : "desc" }
325
+ },
326
+ Transcript : {
327
+ "list" : "transcripts" ,
328
+ "details" : "resolve_transcript" ,
329
+ "sortby" : {"mapping_ratio" : "desc" }
330
+ },
331
+ Ligand : {
332
+ "list" : "ligands" ,
333
+ "details" : "resolve_ligand"
334
+ },
335
+ GoTerm : {
336
+ "list" : "go_terms" ,
337
+ "details" : "resolve_go_term"
338
+ }
339
+ }
340
+
341
+ resolvers = generate_resolvers (ENDPOINTS )
342
+
343
+ Query = strawberry .type (type ("Query" , (), resolvers ))
0 commit comments