Skip to content

Commit

Permalink
bug: update query names for better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensplayer committed Jan 19, 2023
1 parent 1a31dd5 commit 998857c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
46 changes: 26 additions & 20 deletions packages/data-context/src/sources/RelevantRunSpecsDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ import type { CloudRunStatus } from '@packages/graphql/src/gen/cloud-source-type
const debug = debugLib('cypress:data-context:sources:RelevantRunSpecsDataSource')

const RELEVANT_RUN_SPEC_OPERATION_DOC = gql`
query RelevantRunsDataSource_latestRunUpdateSpecData(
fragment RelevantRunSpecsDataSource_Runs on CloudRun {
id
runNumber
status
specs {
id
status
groupIds
}
}
query RelevantRunSpecsDataSource_Specs(
$projectSlug: String!
$currentRunNumber: Int!
$hasCurrent: Boolean!
Expand All @@ -24,21 +35,11 @@ const RELEVANT_RUN_SPEC_OPERATION_DOC = gql`
id
current: runByNumber(runNumber: $currentRunNumber) @include(if: $hasCurrent) {
id
runNumber
status
specs {
id
status
}
...RelevantRunSpecsDataSource_Runs
}
next: runByNumber(runNumber: $nextRunNumber) @include(if: $hasNext) {
id
runNumber
status
specs {
id
status
}
...RelevantRunSpecsDataSource_Runs
}
}
}
Expand All @@ -56,14 +57,17 @@ export const SPECS_EMPTY_RETURN: RunSpecReturn = {

const INCOMPLETE_STATUSES: CloudSpecStatus[] = ['RUNNING', 'UNCLAIMED']

type RunSpecReturn = {
export type RunSpecReturn = {
runSpecs: CurrentProjectRelevantRunSpecs
statuses: {
current?: CloudRunStatus
next?: CloudRunStatus
}
}

//Not ideal typing for this return since the query is not fetching all the fields, but better than nothing
export type RelevantRunSpecsCloudResult = { cloudProjectBySlug: { __typename?: string, current?: Partial<CloudRun>, next?: Partial<CloudRun> } } & Pick<Query, 'pollingIntervals'>

/**
* DataSource to encapsulate querying Cypress Cloud for runs that match a list of local Git commit shas
*/
Expand All @@ -83,9 +87,14 @@ export class RelevantRunSpecsDataSource {
}

#calculateSpecMetadata (specs: CloudSpecRun[]) {
//mimic logic in Cloud to sum up the count of groups per spec to give the total spec counts
const countGroupsForSpec = (specs: CloudSpecRun[]) => {
return specs.map((spec) => spec.groupIds?.length || 0).reduce((acc, curr) => acc += curr, 0)
}

return {
totalSpecs: specs.length,
completedSpecs: specs.map((spec) => spec.status || 'UNCLAIMED').filter((status) => !INCOMPLETE_STATUSES.includes(status)).length,
totalSpecs: countGroupsForSpec(specs),
completedSpecs: countGroupsForSpec(specs.filter((spec) => !INCOMPLETE_STATUSES.includes(spec.status || 'UNCLAIMED'))),
}
}

Expand All @@ -106,10 +115,7 @@ export class RelevantRunSpecsDataSource {

debug(`Fetching specs for ${projectSlug} and %o`, runs)

//Not ideal typing for this return since the query is not fetching all the fields, but better than nothing
type CloudResult = { cloudProjectBySlug: { __typename: string, current?: CloudRun, next?: CloudRun } } & Pick<Query, 'pollingIntervals'>

const result = await this.ctx.cloud.executeRemoteGraphQL<CloudResult>({
const result = await this.ctx.cloud.executeRemoteGraphQL<RelevantRunSpecsCloudResult>({
fieldName: 'cloudProjectBySlug',
operationDoc: RELEVANT_RUN_SPEC_OPERATION_DOC,
operation: RELEVANT_RUN_SPEC_UPDATE_OPERATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Poller } from '../polling'
const debug = debugLib('cypress:data-context:sources:RelevantRunsDataSource')

const RELEVANT_RUN_OPERATION_DOC = gql`
query RelevantRunsDataSource_latestRunUpdateSpecData(
query RelevantRunsDataSource_RunsByCommitShas(
$projectSlug: String!
$shas: [String!]!
) {
Expand Down

0 comments on commit 998857c

Please sign in to comment.