Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update query names for better logging #25514

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

$projectSlug: String!
$shas: [String!]!
) {
Expand Down