Skip to content

Expose FieldRegion.projects & FieldZone.projects#3530

Open
rdonigian wants to merge 4 commits intodevelopfrom
region-zone-projects
Open

Expose FieldRegion.projects & FieldZone.projects#3530
rdonigian wants to merge 4 commits intodevelopfrom
region-zone-projects

Conversation

@rdonigian
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented Jul 18, 2025

🗞 GraphQL Summary

View schema changes
@@ -1736,8 +1736,11 @@
   director: SecuredUser!
   fieldZone: SecuredFieldZone!
   id: ID!
   name: SecuredString!
+
+  """The list of projects in this field region"""
+  projects(input: ProjectListInput = {count: 25, order: ASC, page: 1, sort: "name"}): SecuredProjectList!
 }
 
 input FieldRegionFilters {
   director: UserFilters
@@ -1781,8 +1784,11 @@
   createdAt: DateTime!
   director: SecuredUser!
   id: ID!
   name: SecuredString!
+
+  """The list of projects in regions within this field zone"""
+  projects(input: ProjectListInput = {count: 25, order: ASC, page: 1, sort: "name"}): SecuredProjectList!
 }
 
 input FieldZoneFilters {
   director: UserFilters

@rdonigian rdonigian force-pushed the region-zone-projects branch 2 times, most recently from 91c9d80 to d2ea758 Compare July 21, 2025 12:40
@rdonigian rdonigian marked this pull request as ready for review July 21, 2025 14:01
@rdonigian rdonigian requested a review from CarsonF as a code owner July 21, 2025 14:01
@coderabbitai
Copy link

coderabbitai bot commented Jul 21, 2025

📝 Walkthrough

Walkthrough

This change introduces a projects property to both FieldRegion and FieldZone entities at the schema, DTO, service, and GraphQL resolver levels. Supporting migrations and module dependency adjustments are included to enable traversal and listing of related projects for these entities, along with updated service methods and module registrations.

Changes

Files/Paths Change Summary
dbschema/field-region.gel, dbschema/field-zone.gel Added computed multi-valued projects property to FieldRegion and FieldZone types.
dbschema/migrations/00020-m1cjlgl.edgeql Migration adding multi links projects to FieldRegion and FieldZone.
src/components/field-region/dto/field-region.dto.ts, src/components/field-zone/dto/field-zone.dto.ts Added static Relations property mapping projects relation for DTOs.
src/components/field-region/field-region-projects.resolver.ts, src/components/field-zone/field-zone-projects.resolver.ts Added new GraphQL resolvers for projects field on FieldRegion and FieldZone.
src/components/field-region/field-region.service.ts, src/components/field-zone/field-zone.service.ts Added listProjects method and injected ProjectService dependency.
src/components/field-region/field-region.module.ts, src/components/field-zone/field-zone.module.ts Updated modules to import ProjectModule (with forwardRef) and register new resolvers.
src/components/location/location.module.ts, src/components/organization/organization.module.ts Changed imports to use forwardRef for module dependencies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2ea758 and dd8615f.

📒 Files selected for processing (8)
  • src/components/field-region/dto/field-region.dto.ts (1 hunks)
  • src/components/field-region/field-region-projects.resolver.ts (1 hunks)
  • src/components/field-region/field-region.module.ts (2 hunks)
  • src/components/field-region/field-region.service.ts (3 hunks)
  • src/components/field-zone/dto/field-zone.dto.ts (1 hunks)
  • src/components/field-zone/field-zone-projects.resolver.ts (1 hunks)
  • src/components/field-zone/field-zone.module.ts (2 hunks)
  • src/components/field-zone/field-zone.service.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/components/field-region/field-region.module.ts
  • src/components/field-zone/field-zone.module.ts
  • src/components/field-zone/dto/field-zone.dto.ts
  • src/components/field-zone/field-zone.service.ts
  • src/components/field-region/dto/field-region.dto.ts
  • src/components/field-zone/field-zone-projects.resolver.ts
  • src/components/field-region/field-region.service.ts
  • src/components/field-region/field-region-projects.resolver.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch region-zone-projects

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@CarsonF CarsonF left a comment

Choose a reason for hiding this comment

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

Looks good, just need to spread in the sub filter objects

@rdonigian rdonigian force-pushed the region-zone-projects branch from d2ea758 to dd8615f Compare July 29, 2025 17:24
@rdonigian rdonigian requested a review from CarsonF August 8, 2025 14:50
@sethmcknight sethmcknight requested review from Copilot and removed request for CarsonF February 24, 2026 23:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Exposes projects connections on FieldRegion and FieldZone so API consumers can query projects scoped to a region/zone, backed by new GEL computed links and GraphQL resolvers.

Changes:

  • Added projects GraphQL resolve fields for FieldRegion and FieldZone, plus service methods to list scoped projects.
  • Declared projects as a resource relation on FieldRegion/FieldZone DTOs and added GEL schema + migration for computed projects links.
  • Updated several Nest modules to use forwardRef() to resolve new module dependency cycles.

Reviewed changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/components/organization/organization.module.ts Uses forwardRef() for LocationModule to avoid circular module resolution issues.
src/components/location/location.module.ts Wraps FieldRegionModule in forwardRef() to break a transitive circular dependency.
src/components/field-zone/field-zone.service.ts Adds listProjects() that scopes ProjectService.list() to a zone via filters.
src/components/field-zone/field-zone.module.ts Imports ProjectModule and registers FieldZoneProjectsResolver.
src/components/field-zone/field-zone-projects.resolver.ts New GraphQL field resolver for FieldZone.projects.
src/components/field-zone/dto/field-zone.dto.ts Declares projects in Relations for the FieldZone resource shape.
src/components/field-region/field-region.service.ts Adds listProjects() that scopes ProjectService.list() to a region via filters.
src/components/field-region/field-region.module.ts Imports ProjectModule and registers FieldRegionProjectsResolver.
src/components/field-region/field-region-projects.resolver.ts New GraphQL field resolver for FieldRegion.projects.
src/components/field-region/dto/field-region.dto.ts Declares projects in Relations for the FieldRegion resource shape.
dbschema/migrations/00020-m1cjlgl.edgeql Adds GEL migration creating computed projects links on FieldRegion/FieldZone.
dbschema/field-zone.gel Adds computed multi projects link for FieldZone.
dbschema/field-region.gel Adds computed multi projects link for FieldRegion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +140 to +144
return {
...projectListOutput,
canRead: true,
canCreate: false, // Field zone doesn't own project creation
};
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

FieldZoneService.listProjects() relies on ProjectService.list() with a filter.fieldRegion.fieldZone.id constraint. When config.databaseEngine === 'gel', ProjectService uses ProjectGelRepository, whose listFilters() currently does not apply filter.fieldRegion/filter.fieldRegion.fieldZone at all, so this resolver would return all readable projects instead of just those in the zone. Either implement fieldRegion (and nested fieldZone) filtering in ProjectGelRepository.listFilters(), or in gel mode query via the new Gel computed link FieldZone.projects/FieldRegion.projects so the constraint is enforced at the DB level.

Suggested change
return {
...projectListOutput,
canRead: true,
canCreate: false, // Field zone doesn't own project creation
};
// Defensive filter in case lower layers ignore fieldRegion/fieldZone filters (e.g. gel repo)
const filteredItems = projectListOutput.items.filter((project: any) => {
const zoneId =
project?.fieldRegion?.fieldZone?.id ??
project?.fieldRegion?.value?.fieldZone?.id ??
project?.fieldRegion?.value?.fieldZone?.value?.id;
return zoneId === fieldZone.id;
});
const securedList: SecuredProjectList = {
...(projectListOutput as SecuredProjectList),
items: filteredItems,
canRead: true,
canCreate: false, // Field zone doesn't own project creation
};
// Keep total consistent if present on the list output
if ('total' in securedList && typeof (securedList as any).total === 'number') {
(securedList as any).total = filteredItems.length;
}
return securedList;

Copilot uses AI. Check for mistakes.
Comment on lines +126 to +139
async listProjects(
fieldRegion: FieldRegion,
input: ProjectListInput,
): Promise<SecuredProjectList> {
const projectListOutput = await this.projectService.list({
...input,
filter: {
...input.filter,
fieldRegion: {
...(input.filter?.fieldRegion ?? {}),
id: fieldRegion.id,
},
},
});
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

FieldRegionService.listProjects() relies on ProjectService.list() with a filter.fieldRegion.id constraint. In gel DB mode, ProjectService uses ProjectGelRepository, and its listFilters() currently does not apply the filter.fieldRegion constraint, so this could return all readable projects rather than only projects in the requested region. Add fieldRegion filtering support to ProjectGelRepository.listFilters() (and any needed nested filters), or switch gel mode to resolve via the new Gel computed link FieldRegion.projects so the constraint is always enforced.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +24
@ResolveField(() => SecuredProjectList, {
description: 'The list of projects in regions within this field zone',
})
async projects(
@Parent() fieldZone: FieldZone,
@ListArg(ProjectListInput) input: ProjectListInput,
@Loader(ProjectLoader) projects: LoaderOf<ProjectLoader>,
): Promise<SecuredProjectList> {
const list = await this.fieldZoneService.listProjects(fieldZone, input);
projects.primeAll(list.items);
return list;
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This introduces a new GraphQL field (FieldZone.projects) but there are no accompanying e2e tests covering it. Add coverage in the existing zone/region e2e specs to assert that the field returns only projects within the zone and respects pagination/filtering (and that unauthorized projects are not included).

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +24
@ResolveField(() => SecuredProjectList, {
description: 'The list of projects in this field region',
})
async projects(
@Parent() fieldRegion: FieldRegion,
@ListArg(ProjectListInput) input: ProjectListInput,
@Loader(ProjectLoader) projects: LoaderOf<ProjectLoader>,
): Promise<SecuredProjectList> {
const list = await this.fieldRegionService.listProjects(fieldRegion, input);
projects.primeAll(list.items);
return list;
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This introduces a new GraphQL field (FieldRegion.projects) but there are no accompanying e2e tests covering it. Add coverage (likely in test/region.e2e-spec.ts) to validate that the field returns only projects for the region and that authorization/pagination behavior matches other *.projects connection fields (e.g. Language.projects, Partner.projects).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants