Skip to content

Commit

Permalink
feat: Integrate more V2 API queries (#1174)
Browse files Browse the repository at this point in the history
#1101 

Also temporarily disables automatic querying of `__typename` due to a
bug in the new API.
  • Loading branch information
bchu1 authored Sep 26, 2024
1 parent d21ffd9 commit 92f80a7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion frontend/packages/data-portal/app/apollo.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const apolloClientV2 = new ApolloClient({
fetchPolicy: 'no-cache',
},
},
cache: new InMemoryCache(),
cache: new InMemoryCache({ addTypename: false }), // TODO(bchu): Re-enable __typename when fixed in BE.
link: createHttpLink({
uri: process.env.API_URL_V2 ?? ENVIRONMENT_CONTEXT_DEFAULT_VALUE.API_URL_V2,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function RunHeader() {
resolutions,
annotationFilesAggregates,
tomogramsCount,
alignmentsCount,
} = useRunById()
const { toggleDrawer } = useMetadataDrawer()
const { t } = useI18n()
Expand Down Expand Up @@ -142,8 +143,9 @@ export function RunHeader() {
: 'text-sds-color-primitive-gray-500',
},
{
key: t('alignmentFile'),
value: '', // TODO(bchu): Confirm how this should be counted.
key: t('alignment'),
value:
alignmentsCount > 0 ? t('available') : t('notSubmitted'),
},
{
key: t('tomograms'),
Expand Down
44 changes: 19 additions & 25 deletions frontend/packages/data-portal/app/graphql/getRunByIdDiffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@ import {
Tomogram_Reconstruction_Method_Enum,
} from 'app/__generated_v2__/graphql'

/* eslint-disable no-console */
/* eslint-disable no-console, no-param-reassign */
export function logIfHasDiff(
url: string,
v1: GetRunByIdQuery,
v2: GetRunByIdV2Query,
): void {
console.log('Checking for run query diffs')

// eslint-disable-next-line no-param-reassign
v2 = structuredClone(v2)
// There are no alignments in V1.
delete v2.alignmentsAggregate.aggregate
// Tomogram deposition relations in V1 are incomplete.
for (const tomogram of v2.tomograms) {
delete tomogram.deposition
}
// Frames are not populated in V2 yet.
for (const run of v2.runs) {
delete run.framesAggregate
}

const v1Transformed: GetRunByIdV2Query = {
runs: v1.runs.map((run) => ({
__typename: 'Run',
id: run.id,
name: run.name,
tiltseries: {
__typename: 'TiltseriesConnection',
edges: run.tiltseries.map((runTiltseries) => ({
__typename: 'TiltseriesEdge',
node: {
__typename: 'Tiltseries',
accelerationVoltage: runTiltseries.acceleration_voltage,
alignedTiltseriesBinning: runTiltseries.aligned_tiltseries_binning,
binningFromFrames: runTiltseries.binning_from_frames,
Expand Down Expand Up @@ -67,7 +68,6 @@ export function logIfHasDiff(
})),
},
dataset: {
__typename: 'Dataset',
cellComponentName: run.dataset.cell_component_name,
cellComponentId: run.dataset.cell_component_id,
cellName: run.dataset.cell_name,
Expand Down Expand Up @@ -95,22 +95,16 @@ export function logIfHasDiff(
tissueId: run.dataset.tissue_id,
title: run.dataset.title,
fundingSources: {
__typename: 'DatasetFundingConnection',
edges: run.dataset.funding_sources.map((source) => ({
__typename: 'DatasetFundingEdge',
node: {
__typename: 'DatasetFunding',
fundingAgencyName: source.funding_agency_name,
grantId: source.grant_id,
},
})),
},
authors: {
__typename: 'DatasetAuthorConnection',
edges: run.dataset.authors.map((author) => ({
__typename: 'DatasetAuthorEdge',
node: {
__typename: 'DatasetAuthor',
correspondingAuthorStatus: author.corresponding_author_status,
email: author.email,
name: author.name,
Expand All @@ -121,19 +115,13 @@ export function logIfHasDiff(
},
},
tomogramVoxelSpacings: {
__typename: 'TomogramVoxelSpacingConnection',
edges: run.tomogram_voxel_spacings.map((tomogramVoxelSpacing) => ({
__typename: 'TomogramVoxelSpacingEdge',
node: {
__typename: 'TomogramVoxelSpacing',
id: tomogramVoxelSpacing.id,
s3Prefix: tomogramVoxelSpacing.s3_prefix!,
tomograms: {
__typename: 'TomogramConnection',
edges: tomogramVoxelSpacing.tomograms.map((tomogram) => ({
__typename: 'TomogramEdge',
node: {
__typename: 'Tomogram',
ctfCorrected: tomogram.ctf_corrected,
fiducialAlignmentStatus:
tomogram.fiducial_alignment_status as Fiducial_Alignment_Status_Enum,
Expand All @@ -153,7 +141,6 @@ export function logIfHasDiff(
sizeZ: tomogram.size_z,
voxelSpacing: tomogram.voxel_spacing,
alignment: {
__typename: 'Alignment',
affineTransformationMatrix: JSON.stringify(
tomogram.affine_transformation_matrix,
).replaceAll(',', ', '),
Expand All @@ -164,9 +151,20 @@ export function logIfHasDiff(
},
})),
},
tiltseriesAggregate: {
aggregate: [
{
count: run.tiltseries_aggregate.aggregate?.count,
avg: {
tiltSeriesQuality:
run.tiltseries_aggregate.aggregate?.avg?.tilt_series_quality,
},
},
],
},
})),
alignmentsAggregate: {},
tomograms: v1.tomograms.map((tomogram) => ({
__typename: 'Tomogram',
ctfCorrected: tomogram.ctf_corrected,
fiducialAlignmentStatus:
tomogram.fiducial_alignment_status as Fiducial_Alignment_Status_Enum,
Expand All @@ -193,17 +191,13 @@ export function logIfHasDiff(
tomogramVoxelSpacing:
tomogram.tomogram_voxel_spacing != null
? {
__typename: 'TomogramVoxelSpacing',
id: tomogram.tomogram_voxel_spacing.id,
s3Prefix: tomogram.tomogram_voxel_spacing.s3_prefix!,
}
: undefined,
authors: {
__typename: 'TomogramAuthorConnection',
edges: tomogram.authors.map((author) => ({
__typename: 'TomogramAuthorEdge',
node: {
__typename: 'TomogramAuthor',
primaryAuthorStatus: author.primary_author_status,
correspondingAuthorStatus: author.corresponding_author_status,
name: author.name,
Expand Down
31 changes: 20 additions & 11 deletions frontend/packages/data-portal/app/graphql/getRunByIdV2.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,26 @@ const GET_RUN_BY_ID_QUERY_V2 = gql(`
}
# Header
# tiltseriesAggregate { # TODO(bchu): Uncomment when __typename bug is fixed.
# aggregate {
# count
# avg {
# tiltSeriesQuality
# }
# # sum {
# # tiltseriesFramesCount # TODO(bchu): Uncomment when populated.
# # }
# }
# }
framesAggregate {
aggregate {
count
}
}
tiltseriesAggregate {
aggregate {
count
avg {
tiltSeriesQuality
}
}
}
}
# Header
alignmentsAggregate(where: {run: {id: {_eq: $id}}}) {
aggregate {
count
}
}
# Annotations table
Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/data-portal/app/hooks/useRunById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export function useRunById() {

const tomogramsCount = v1.tomograms_aggregate.aggregate?.count ?? 0

const alignmentsCount = v2.alignmentsAggregate.aggregate?.[0]?.count ?? 0

const { deposition } = v1

return {
Expand All @@ -60,6 +62,7 @@ export function useRunById() {
resolutions,
annotationFilesAggregates,
tomogramsCount,
alignmentsCount,
deposition,
}
}
2 changes: 1 addition & 1 deletion frontend/packages/data-portal/e2e/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getApolloClient() {
export function getApolloClientV2() {
return new apollo.ApolloClient({
ssrMode: true,
cache: new apollo.InMemoryCache(),
cache: new apollo.InMemoryCache({ addTypename: false }), // TODO(bchu): Re-enable __typename when fixed in BE.
link: apollo.createHttpLink({
uri:
process.env.API_URL_V2 ?? ENVIRONMENT_CONTEXT_DEFAULT_VALUE.API_URL_V2,
Expand Down

0 comments on commit 92f80a7

Please sign in to comment.