Skip to content

Commit

Permalink
feat: federate WorkflowsAggregate endpoint (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: Nina Bernick <nbernick@CZIMACOS4338.local>
Co-authored-by: Nina Bernick <nbernick@chanzuckerberg.com>
  • Loading branch information
3 people authored Feb 21, 2024
1 parent 1e45857 commit 9001540
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .meshrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ sources:
method: POST
requestSchema: ./json-schemas/workflowRunsRequest.json
responseSchema: ./json-schemas/workflowRunsResponse.json
- type: Query
field: workflowRunsAggregate
path: /projects.json
method: GET
requestSchema: ./json-schemas/workflowRunsAggregateRequest.json
responseSchema: ./json-schemas/workflowRunsAggregateResponse.json
responseTypeName: workflowRunsAggregate
- type: Query
field: ZipLink
path: /workflow_runs/{args.workflowRunId}/zip_link.json
Expand Down
23 changes: 23 additions & 0 deletions example-queries/workflows-aggregate-query.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
query workflowRunsAggregateQuery {
workflowRunsAggregate(
input: {
where: {
id: {
_in: ["1", "2", "3"]
}
},
todoRemove: {
domain: "my_data",
offset: 0,
visibility: "public",
search: "abc",
time: ["20240214", "20240222"]
}
}
) {
collectionId
amrRunsCount
cgRunsCount
mngsRunsCount
}
}
105 changes: 105 additions & 0 deletions json-schemas/workflowRunsAggregateRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"type": "object",
"properties": {
"where": {
"type": "object",
"properties": {
"id": {
"type": "object",
"properties": {
"_in": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"todoRemove": {
"type": "object",
"properties": {
"projectId": {
"type": "string"
},
"domain": {
"type": "string"
},
"host": {
"type": "array",
"items": {
"type": "integer"
}
},
"locationV2": {
"type": "array",
"items": {
"type": "string"
}
},
"taxonThresholds": {
"type": "array",
"items": {
"type": "object",
"properties": {
"metric": {
"type": "string"
},
"count_type": {
"type": "string"
},
"operator": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
},
"annotations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
"tissue": {
"type": "array",
"items": {
"type": "string"
}
},
"visibility": {
"type": "string"
},
"time": {
"type": "array",
"items": {
"type": "string"
}
},
"taxaLevels": {
"type": "array",
"items": {
"type": "string"
}
},
"taxon": {
"type": "array",
"items": {
"type": "integer"
}
},
"search": {
"type": "string"
}
}
}
}
}
26 changes: 26 additions & 0 deletions json-schemas/workflowRunsAggregateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "array",
"items": {
"type": "object",
"properties": {
"collectionId": {
"type": "string"
},
"mngsRunsCount": {
"type": "integer"
},
"cgRunsCount": {
"type": "integer"
},
"amrRunsCount": {
"type": "integer"
}
},
"required": [
"collectionId",
"mngsRunsCount",
"cgRunsCount",
"amrRunsCount"
]
}
}
38 changes: 38 additions & 0 deletions resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
query_consensusGenomes_items,
query_samples_items,
query_sequencingReads_items,
query_workflowRunsAggregate_items,
query_workflowRuns_items,
} from "./.mesh";
import {
Expand Down Expand Up @@ -787,6 +788,43 @@ export const resolvers: Resolvers = {
})
);
},
workflowRunsAggregate: async (root, args, context, info) => {
const input = args.input;

const { projects } = await get("/projects.json" +
formatUrlParams({
projectId: input?.todoRemove?.projectId,
domain: input?.todoRemove?.domain,
limit: TEN_MILLION,
listAllIds: false,
offset: 0,
host: input?.todoRemove?.host,
locationV2: input?.todoRemove?.locationV2,
taxonThresholds: input?.todoRemove?.taxonThresholds,
annotations: input?.todoRemove?.annotations,
search: input?.todoRemove?.search,
tissue: input?.todoRemove?.tissue,
visibility: input?.todoRemove?.visibility,
time: input?.todoRemove?.time,
taxaLevels: input?.todoRemove?.taxaLevels,
taxon: input?.todoRemove?.taxon,
}), args, context);

if (!projects?.length) {
return [];
}
return projects.map((project): query_workflowRunsAggregate_items => {
return {
collectionId: project.id.toString(),
mngsRunsCount: project.sample_counts.mngs_runs_count,
cgRunsCount:
project.sample_counts.cg_runs_count,
amrRunsCount: project.sample_counts.amr_runs_count,
};
});

// TODO (nina): call nextgen in addition to rails to get CG count
},
ZipLink: async (root, args, context, info) => {
const res = await getFullResponse(
`/workflow_runs/${args.workflowRunId}/zip_link.json`,
Expand Down
50 changes: 50 additions & 0 deletions sample-requests/workflowRunsAggregate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"where": {
"id": {
"_in": {
"items": [
"1234"
]
}
}
},
"todoRemove": {
"projectId": "1056",
"domain": "my_data",
"host": [
1,
11
],
"locationV2": [
"California, USA"
],
"taxonThresholds": [
{
"metric": "rpm",
"count_type": "NT",
"operator": ">=",
"value": "1"
}
],
"annotations": [
{
"name": "Hit"
}
],
"tissue": [
"CSF"
],
"visibility": "public",
"time": [
"20240205",
"20240213"
],
"taxaLevels": [
"species"
],
"taxon": [
244366
],
"search": "abc"
}
}
8 changes: 8 additions & 0 deletions sample-responses/workflowRunsAggregate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"collectionId": "123",
"mngsRunsCount": 0,
"cgRunsCount": 5,
"amrRunsCount": 0
}
]
49 changes: 49 additions & 0 deletions tests/WorkflowRunsAggregateQuery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ExecuteMeshFn } from "@graphql-mesh/runtime";
import { getMeshInstance } from "./utils/MeshInstance";

import * as httpUtils from "../utils/httpUtils";
import { getExampleQuery } from "./utils/ExampleQueryFiles";
jest.spyOn(httpUtils, "get");

beforeEach(() => {
(httpUtils.get as jest.Mock).mockClear();
});

describe("workflows aggregate query:", () => {
let execute: ExecuteMeshFn;

beforeEach(async () => {
const mesh$ = await getMeshInstance();
({ execute } = mesh$);
});

it("Returns aggregate counts for each workflow", async () => {
(httpUtils.get as jest.Mock).mockImplementation(() => ({
projects: [
{
id: 1,
sample_counts: {
cg_runs_count: 1,
amr_runs_count: 2,
mngs_runs_count: 3
}
}
],
}));

const query = getExampleQuery("workflows-aggregate-query");

const response = await execute(query, {});
expect(httpUtils.get).toHaveBeenCalledWith(
"/projects.json?&domain=my_data&limit=10000000&listAllIds=false&offset=0&search=abc&visibility=public&time[]=20240214&time[]=20240222",
expect.anything(),
expect.anything()
);

expect(response.data.workflowRunsAggregate).toHaveLength(1);
expect(response.data.workflowRunsAggregate[0].collectionId).toBe("1");
expect(response.data.workflowRunsAggregate[0].amrRunsCount).toBe(2);
expect(response.data.workflowRunsAggregate[0].cgRunsCount).toBe(1);
expect(response.data.workflowRunsAggregate[0].mngsRunsCount).toBe(3);
});
});
47 changes: 47 additions & 0 deletions tests/__snapshots__/UnifiedSchema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Query @globalOptions(sourceName: "CZIDREST", endpoint: "http://web:3001/")
UserBlastAnnotations(sampleId: String, workflowVersionId: String): [query_UserBlastAnnotations_items] @httpOperation(path: "/samples/{args.sampleId}/report_v2?&id={args.sampleId}&pipeline_version={args.workflowVersionId}&merge_nt_nr=false", httpMethod: GET)
ValidateUserCanDeleteObjects(input: queryInput_ValidateUserCanDeleteObjects_input_Input): ValidateUserCanDeleteObjects @httpOperation(path: "/samples/validate_user_can_delete_objects.json", httpMethod: POST)
workflowRuns(input: queryInput_workflowRuns_input_Input): [query_workflowRuns_items] @httpOperation(path: "/workflow_runs.json", httpMethod: POST)
workflowRunsAggregate(input: queryInput_workflowRunsAggregate_input_Input): [query_workflowRunsAggregate_items] @httpOperation(path: "/projects.json", httpMethod: GET)
ZipLink(workflowRunId: String): ZipLink @httpOperation(path: "/workflow_runs/{args.workflowRunId}/zip_link.json", httpMethod: GET)
GraphQLFederationVersion: GraphQLFederationVersion
}
Expand Down Expand Up @@ -3316,6 +3317,52 @@ input queryInput_workflowRuns_input_entityInputsInput_where_fieldName_Input {
_eq: String
}
type query_workflowRunsAggregate_items {
collectionId: String!
mngsRunsCount: Int!
cgRunsCount: Int!
amrRunsCount: Int!
}
input queryInput_workflowRunsAggregate_input_Input {
where: queryInput_workflowRunsAggregate_input_where_Input
todoRemove: queryInput_workflowRunsAggregate_input_todoRemove_Input
}
input queryInput_workflowRunsAggregate_input_where_Input {
id: queryInput_workflowRunsAggregate_input_where_id_Input
}
input queryInput_workflowRunsAggregate_input_where_id_Input {
_in: [String]
}
input queryInput_workflowRunsAggregate_input_todoRemove_Input {
projectId: String
domain: String
host: [Int]
locationV2: [String]
taxonThresholds: [queryInput_workflowRunsAggregate_input_todoRemove_taxonThresholds_items_Input]
annotations: [queryInput_workflowRunsAggregate_input_todoRemove_annotations_items_Input]
tissue: [String]
visibility: String
time: [String]
taxaLevels: [String]
taxon: [Int]
search: String
}
input queryInput_workflowRunsAggregate_input_todoRemove_taxonThresholds_items_Input {
metric: String
count_type: String
operator: String
value: String
}
input queryInput_workflowRunsAggregate_input_todoRemove_annotations_items_Input {
name: String
}
type ZipLink {
url: String
error: String
Expand Down

0 comments on commit 9001540

Please sign in to comment.