Skip to content

Commit

Permalink
DEVPROD-5460: Update GraphQL queries to use specific arguments (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt authored Apr 2, 2024
1 parent 23b0bea commit 7534d90
Show file tree
Hide file tree
Showing 45 changed files with 239 additions and 155 deletions.
4 changes: 3 additions & 1 deletion apps/spruce/src/components/ScheduleTasksModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export const ScheduleTasksModal: React.FC<ScheduleTasksModalProps> = ({
loadingTaskData || loadingScheduleTasksMutation || !selectedTasks.size
}
onConfirm={() => {
scheduleTasks({ variables: { taskIds: Array.from(selectedTasks) } });
scheduleTasks({
variables: { taskIds: Array.from(selectedTasks), versionId },
});
}}
>
<ContentWrapper>
Expand Down
1 change: 1 addition & 0 deletions apps/spruce/src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5155,6 +5155,7 @@ export type SchedulePatchMutation = {

export type ScheduleTasksMutationVariables = Exact<{
taskIds: Array<Scalars["String"]["input"]>;
versionId: Scalars["String"]["input"];
}>;

export type ScheduleTasksMutation = {
Expand Down
4 changes: 2 additions & 2 deletions apps/spruce/src/gql/mutations/schedule-tasks.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/baseTask.graphql"

mutation ScheduleTasks($taskIds: [String!]!) {
scheduleTasks(taskIds: $taskIds) {
mutation ScheduleTasks($taskIds: [String!]!, $versionId: String!) {
scheduleTasks(taskIds: $taskIds, versionId: $versionId) {
...BaseTask
}
}
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/build-variant-stats.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query BuildVariantStats($id: String!) {
version(id: $id) {
version(versionId: $id) {
buildVariantStats(options: {}) {
displayName
statusCounts {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query BuildVariantsWithChildren($id: String!) {
version(id: $id) {
version(versionId: $id) {
buildVariants(options: {}) {
displayName
tasks {
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/code-changes.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/moduleCodeChanges.graphql"

query CodeChanges($id: String!) {
patch(id: $id) {
patch(patchId: $id) {
id
moduleCodeChanges {
...ModuleCodeChange
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/has-version.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
query HasVersion($id: String!) {
hasVersion(id: $id)
hasVersion(patchId: $id)
}
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/is-patch-configured.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query IsPatchConfigured($id: String!) {
patch(id: $id) {
patch(patchId: $id) {
activated
alias
id
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/patch-configure.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/basePatch.graphql"

query ConfigurePatch($id: String!) {
patch(id: $id) {
patch(patchId: $id) {
...BasePatch
childPatchAliases {
alias
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/patch-task-statuses.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query PatchTaskStatuses($id: String!) {
patch(id: $id) {
patch(patchId: $id) {
baseTaskStatuses
id
taskStatuses
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/patch.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/basePatch.graphql"

query Patch($id: String!) {
patch(id: $id) {
patch(patchId: $id) {
...BasePatch
githash
patchNumber
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/repo-event-logs.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/projectSettings/projectEventSettings.graphql"

query RepoEventLogs($id: String!, $limit: Int, $before: Time) {
repoEvents(id: $id, limit: $limit, before: $before) {
repoEvents(id: $id, repoId: $id, limit: $limit, before: $before) {
count
eventLogEntries {
after {
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/repo-settings.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/projectSettings/index.graphql"

query RepoSettings($repoId: String!) {
repoSettings(id: $repoId) {
repoSettings(id: $repoId, repoId: $repoId) {
...RepoSettingsFields
}
}
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/task-statuses.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query TaskStatuses($id: String!) {
version(id: $id) {
version(versionId: $id) {
baseTaskStatuses
id
taskStatuses
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/undispatched-tasks.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query UndispatchedTasks($versionId: String!) {
version(id: $versionId) {
version(versionId: $versionId) {
id
tasks(
options: { statuses: ["unscheduled"], includeEmptyActivation: true }
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/version-task-durations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ query VersionTaskDurations(
$versionId: String!
$taskFilterOptions: TaskFilterOptions!
) {
version(id: $versionId) {
version(versionId: $versionId) {
id
tasks(options: $taskFilterOptions) {
count
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/version-tasks.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ query VersionTasks(
$versionId: String!
$taskFilterOptions: TaskFilterOptions!
) {
version(id: $versionId) {
version(versionId: $versionId) {
id
isPatch
tasks(options: $taskFilterOptions) {
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/gql/queries/version.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "../fragments/upstreamProject.graphql"

query Version($id: String!) {
version(id: $id) {
version(versionId: $id) {
activated
author
authorEmail
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/pages/projectSettings/HeaderButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const HeaderButtons: React.FC<Props> = ({ id, projectType, tab }) => {

const onClick = () => {
const formToGql: FormToGqlFunction<typeof tab> = formToGqlMap[tab];
const newData = formToGql(formData, id);
const newData = formToGql(formData, isRepo, id);
const save = (update, section) =>
isRepo
? saveRepoSection({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("repo data", () => {
});

it("correctly converts from a form to GQL", () => {
expect(formToGql(repoForm, "repo")).toStrictEqual(repoResult);
expect(formToGql(repoForm, true, "repo")).toStrictEqual(repoResult);
});
});

Expand All @@ -21,7 +21,9 @@ describe("project data", () => {
});

it("correctly converts from a form to GQL", () => {
expect(formToGql(projectForm, "project")).toStrictEqual(projectResult);
expect(formToGql(projectForm, false, "project")).toStrictEqual(
projectResult,
);
});
});

Expand All @@ -34,7 +36,8 @@ const projectForm: AccessFormState = {
},
};

const projectResult: Pick<ProjectSettingsInput, "projectRef"> = {
const projectResult: Pick<ProjectSettingsInput, "projectId" | "projectRef"> = {
projectId: "project",
projectRef: {
id: "project",
restricted: true,
Expand All @@ -51,7 +54,8 @@ const repoForm: AccessFormState = {
},
};

const repoResult: Pick<RepoSettingsInput, "projectRef"> = {
const repoResult: Pick<RepoSettingsInput, "repoId" | "projectRef"> = {
repoId: "repo",
projectRef: {
id: "repo",
restricted: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export const gqlToForm = ((data) => {
};
}) satisfies GqlToFormFunction<Tab>;

export const formToGql = (({ accessSettings, admin }, id) => {
export const formToGql = (({ accessSettings, admin }, isRepo, id) => {
const projectRef: ProjectInput = {
id,
restricted: accessSettings.restricted,
admins: admin.admins,
};

return { projectRef };
return { ...(isRepo ? { repoId: id } : { projectId: id }), projectRef };
}) satisfies FormToGqlFunction<Tab>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("containers", () => {
expect(gqlToForm(projectBase)).toStrictEqual(projectFormBase);
});
it("correctly converts from a form to GQL", () => {
expect(formToGql(projectFormBase, "spruce")).toStrictEqual(
expect(formToGql(projectFormBase, false, "spruce")).toStrictEqual(
projectResultBase,
);
});
Expand All @@ -29,6 +29,7 @@ const projectFormBase: ContainersFormState = {
};

const projectResultBase: ProjectSettingsInput = {
projectId: "spruce",
projectRef: {
id: "spruce",
containerSizeDefinitions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export const gqlToForm = ((data) => {
};
}) satisfies GqlToFormFunction<Tab>;

export const formToGql = ((formState, id) => {
export const formToGql = ((formState, isRepo, id) => {
const { containerSizeDefinitions } = formState;
return {
...(isRepo ? { repoId: id } : { projectId: id }),
projectRef: {
id,
containerSizeDefinitions: containerSizeDefinitions.variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("repo data", () => {
});

it("correctly converts from a form to GQL", () => {
expect(formToGql(repoForm, "repo")).toStrictEqual(repoResult);
expect(formToGql(repoForm, true, "repo")).toStrictEqual(repoResult);
});
});

Expand All @@ -24,7 +24,9 @@ describe("project data", () => {
});

it("correctly converts from a form to GQL", () => {
expect(formToGql(projectForm, "project")).toStrictEqual(projectResult);
expect(formToGql(projectForm, false, "project")).toStrictEqual(
projectResult,
);
});
});

Expand Down Expand Up @@ -67,7 +69,8 @@ const repoForm: GeneralFormState = {
},
};

const repoResult: Pick<RepoSettingsInput, "projectRef"> = {
const repoResult: Pick<RepoSettingsInput, "repoId" | "projectRef"> = {
repoId: "repo",
projectRef: {
id: "repo",
owner: "evergreen-ci",
Expand Down Expand Up @@ -133,7 +136,8 @@ const projectForm: GeneralFormState = {
},
};

const projectResult: Pick<ProjectSettingsInput, "projectRef"> = {
const projectResult: Pick<ProjectSettingsInput, "projectId" | "projectRef"> = {
projectId: "project",
projectRef: {
id: "project",
enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const formToGql = ((
historicalTaskDataCaching: { disabledStatsCache },
projectFlags,
},
isRepo,
id,
) => {
const projectRef: ProjectInput = {
Expand Down Expand Up @@ -101,5 +102,5 @@ export const formToGql = ((
disabledStatsCache,
};

return { projectRef };
return { ...(isRepo ? { repoId: id } : { projectId: id }), projectRef };
}) satisfies FormToGqlFunction<Tab>;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("repo data", () => {
});

it("correctly converts from a form to GQL", () => {
expect(formToGql(repoForm, "repo")).toStrictEqual(repoResult);
expect(formToGql(repoForm, true, "repo")).toStrictEqual(repoResult);
});
});

Expand All @@ -31,7 +31,9 @@ describe("project data", () => {
});

it("correctly converts from a form to GQL and omits empty strings", () => {
expect(formToGql(projectForm, "project")).toStrictEqual(projectResult);
expect(formToGql(projectForm, false, "project")).toStrictEqual(
projectResult,
);
});

it("correctly merges project and repo form states", () => {
Expand Down Expand Up @@ -139,7 +141,11 @@ const projectForm: GCQFormState = {
},
};

const projectResult: Pick<ProjectSettingsInput, "projectRef" | "aliases"> = {
const projectResult: Pick<
ProjectSettingsInput,
"projectId" | "projectRef" | "aliases"
> = {
projectId: "project",
projectRef: {
id: "project",
prTestingEnabled: null,
Expand Down Expand Up @@ -275,37 +281,39 @@ const repoForm: GCQFormState = {
},
};

const repoResult: Pick<RepoSettingsInput, "projectRef" | "aliases"> = {
projectRef: {
id: "repo",
prTestingEnabled: false,
manualPrTestingEnabled: false,
githubChecksEnabled: true,
gitTagVersionsEnabled: false,
gitTagAuthorizedUsers: ["admin"],
gitTagAuthorizedTeams: [],
commitQueue: {
enabled: true,
message: "Commit Queue Message",
mergeMethod: "squash",
mergeQueue: MergeQueue.Github,
},
},
aliases: [
{
id: "2",
alias: "__github_checks",
description: "",
gitTag: "",
remotePath: "",
task: "",
taskTags: ["tTag"],
variant: "",
variantTags: ["vTag"],
parameters: [],
const repoResult: Pick<RepoSettingsInput, "repoId" | "projectRef" | "aliases"> =
{
repoId: "repo",
projectRef: {
id: "repo",
prTestingEnabled: false,
manualPrTestingEnabled: false,
githubChecksEnabled: true,
gitTagVersionsEnabled: false,
gitTagAuthorizedUsers: ["admin"],
gitTagAuthorizedTeams: [],
commitQueue: {
enabled: true,
message: "Commit Queue Message",
mergeMethod: "squash",
mergeQueue: MergeQueue.Github,
},
},
],
};
aliases: [
{
id: "2",
alias: "__github_checks",
description: "",
gitTag: "",
remotePath: "",
task: "",
taskTags: ["tTag"],
variant: "",
variantTags: ["vTag"],
parameters: [],
},
],
};

const mergedForm: GCQFormState = {
github: {
Expand Down
Loading

0 comments on commit 7534d90

Please sign in to comment.