Reorganize branch offices
Suppose your bank is consolidating two regional offices into one. The workflow: create the new office, move every organization that was on the old offices to the new one, then retire the old offices.
All steps require a JWT — get one from the homepage first.
1. Take stock of existing offices
query existingBranchOffices {
branchOffices(first: 100) {
nodes {
id
name
}
}
}
Note the IDs of the offices you're consolidating ("old A", "old B") so you can find their organizations in step 3.
2. Create the new office
mutation addBranchOffice($input: AddBranchOfficeInput!) {
addBranchOffice(input: $input) {
branchOfficePayload {
branchOffice {
id
name
}
}
}
}
Save the returned id — that's the destination for step 4.
3. List organizations on the old offices
organizations doesn't expose branchOffice as a filter directly, so we project it instead and you filter client-side. Note that extendedInformation is a list — an organization can have more than one entry.
query organizationsByBranchOffice {
organizations(first: 100) {
nodes {
id
name
extendedInformation {
branchOffice {
id
name
}
}
}
}
}
Take the list of organization IDs whose extendedInformation[*].branchOffice.id matches one of the offices you're retiring.
4. Move each organization to the new office
Run this once per organization. The mutation creates extendedInformation if it didn't exist, and otherwise just updates the branchOffice association. The payload wraps the organization in an inner organizationPayload.
mutation moveOrganizationToBranchOffice($input: UpdateOrganizationBranchOfficeInput!) {
updateOrganizationBranchOffice(input: $input) {
organizationPayload {
organization {
id
}
}
}
}
For a large list, scripting this against your own backend is much faster than running it manually here — same mutation, same input.
5. Retire the old offices
Once every organization has moved off, delete each retired office.
mutation removeBranchOffice($input: RemoveBranchOfficeInput!) {
removeBranchOffice(input: $input) {
success
}
}
If a retired office still has organizations attached, the mutation succeeds but those organizations end up dangling on a deleted office — re-run step 3 before running this to make sure the office is empty.