Skip to content

Commit

Permalink
Declare list FilterField type lazily (#3242)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Jun 17, 2024
1 parent bf0f1bb commit 6756446
Show file tree
Hide file tree
Showing 23 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/common/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AbstractClassType } from './types';
* A field that is a filter object probably for input on a list query.
*/
export const FilterField = <T extends object>(
type: HasRequiredKeys<T> extends true ? never : AbstractClassType<T>,
type: () => HasRequiredKeys<T> extends true ? never : AbstractClassType<T>,
options?: {
/**
* There are no external fields on the filter, so don't expose to GQL.
Expand All @@ -22,12 +22,12 @@ export const FilterField = <T extends object>(
...(options?.internal
? []
: [
Field(() => type as unknown as Constructor<T>, {
Field(type as unknown as () => Constructor<T>, {
nullable: true,
defaultValue: {} as unknown as T, // Only for GQL schema & not always applied in TS
}),
]),
Type(() => type),
Type(type),
ValidateNested(),
DefaultValue.Set({}), // Default when omitted
Transform(({ value }) => value || {}), // null -> {}
Expand Down
2 changes: 1 addition & 1 deletion src/components/budget/dto/list-budget.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export abstract class BudgetFilters {
export class BudgetListInput extends SortablePaginationInput<keyof Budget>({
defaultSort: 'status',
}) {
@FilterField(BudgetFilters, { internal: true })
@FilterField(() => BudgetFilters, { internal: true })
readonly filter: BudgetFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ceremony/dto/list-ceremony.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CeremonyListInput extends SortablePaginationInput<
>({
defaultSort: 'projectName',
}) {
@FilterField(CeremonyFilters)
@FilterField(() => CeremonyFilters)
readonly filter: CeremonyFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/engagement/dto/list-engagements.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class EngagementListInput extends SortablePaginationInput<
>({
defaultSort: 'createdAt',
}) {
@FilterField(EngagementFilters)
@FilterField(() => EngagementFilters)
readonly filter: EngagementFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ethno-art/dto/list-ethno-art.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class EthnoArtFilters {}
export class EthnoArtListInput extends SortablePaginationInput<keyof EthnoArt>({
defaultSort: 'name',
}) {
@FilterField(EthnoArtFilters, { internal: true })
@FilterField(() => EthnoArtFilters, { internal: true })
readonly filter: EthnoArtFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/field-region/dto/list-field-region.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class FieldRegionListInput extends SortablePaginationInput<
>({
defaultSort: 'name',
}) {
@FilterField(FieldRegionFilters, { internal: true })
@FilterField(() => FieldRegionFilters, { internal: true })
readonly filter: FieldRegionFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/field-zone/dto/list-field-zone.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class FieldZoneListInput extends SortablePaginationInput<
>({
defaultSort: 'name',
}) {
@FilterField(FieldZoneFilters, { internal: true })
@FilterField(() => FieldZoneFilters, { internal: true })
readonly filter: FieldZoneFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/file/dto/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class FileListInput extends SortablePaginationInput<
>({
defaultSort: 'name',
}) {
@FilterField(FileFilters)
@FilterField(() => FileFilters)
readonly filter?: FileFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/film/dto/list-film.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class FilmFilters {}
export class FilmListInput extends SortablePaginationInput<keyof Film>({
defaultSort: 'name',
}) {
@FilterField(FilmFilters, { internal: true })
@FilterField(() => FilmFilters, { internal: true })
readonly filter: FilmFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/language/dto/list-language.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export abstract class LanguageFilters {
export class LanguageListInput extends SortablePaginationInput<keyof Language>({
defaultSort: 'name',
}) {
@FilterField(LanguageFilters)
@FilterField(() => LanguageFilters)
readonly filter: LanguageFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/location/dto/list-locations.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class LocationFilters {
export class LocationListInput extends SortablePaginationInput<keyof Location>({
defaultSort: 'name',
}) {
@FilterField(LocationFilters, { internal: true })
@FilterField(() => LocationFilters, { internal: true })
readonly filter: LocationFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/organization/dto/list-organization.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class OrganizationListInput extends SortablePaginationInput<
>({
defaultSort: 'name',
}) {
@FilterField(OrganizationFilters, { internal: true })
@FilterField(() => OrganizationFilters, { internal: true })
readonly filter: OrganizationFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/partner/dto/list-partner.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export abstract class PartnerFilters {
export class PartnerListInput extends SortablePaginationInput<keyof Partner>({
defaultSort: 'createdAt',
}) {
@FilterField(PartnerFilters)
@FilterField(() => PartnerFilters)
readonly filter: PartnerFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/partnership/dto/list-partnership.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PartnershipListInput extends SortablePaginationInput<
>({
defaultSort: 'createdAt',
}) {
@FilterField(PartnershipFilters, { internal: true })
@FilterField(() => PartnershipFilters, { internal: true })
readonly filter: PartnershipFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/post/dto/list-posts.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PostListInput extends SortablePaginationInput<keyof Post>({
defaultSort: 'createdAt',
defaultOrder: Order.DESC,
}) {
@FilterField(PostFilters, { internal: true })
@FilterField(() => PostFilters, { internal: true })
readonly filter: PostFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/product/dto/list-product.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export abstract class ProductFilters {
export class ProductListInput extends SortablePaginationInput<keyof Product>({
defaultSort: 'createdAt',
}) {
@FilterField(ProductFilters)
@FilterField(() => ProductFilters)
readonly filter: ProductFilters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ProjectChangeRequestListInput extends SortablePaginationInput<
>({
defaultSort: 'createdAt',
}) {
@FilterField(ProjectChangeRequestFilters, { internal: true })
@FilterField(() => ProjectChangeRequestFilters, { internal: true })
readonly filter: ProjectChangeRequestFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/project/dto/list-projects.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export abstract class ProjectFilters {
export class ProjectListInput extends SortablePaginationInput<keyof IProject>({
defaultSort: 'name',
}) {
@FilterField(ProjectFilters)
@FilterField(() => ProjectFilters)
readonly filter: ProjectFilters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ProjectMemberListInput extends SortablePaginationInput<
>({
defaultSort: 'createdAt',
}) {
@FilterField(ProjectMemberFilters)
@FilterField(() => ProjectMemberFilters)
readonly filter: ProjectMemberFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/story/dto/list-story.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class StoryFilters {}
export class StoryListInput extends SortablePaginationInput<keyof Story>({
defaultSort: 'name',
}) {
@FilterField(StoryFilters, { internal: true })
@FilterField(() => StoryFilters, { internal: true })
readonly filter: StoryFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/user/dto/list-users.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class UserFilters {
export class UserListInput extends SortablePaginationInput<keyof User>({
defaultSort: 'id', // TODO How to sort on name?
}) {
@FilterField(UserFilters)
@FilterField(() => UserFilters)
readonly filter: UserFilters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/user/education/dto/list-education.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class EducationListInput extends SortablePaginationInput<
>({
defaultSort: 'institution',
}) {
@FilterField(EducationFilters, { internal: true })
@FilterField(() => EducationFilters, { internal: true })
readonly filter: EducationFilters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class UnavailabilityListInput extends SortablePaginationInput<
defaultSort: 'start',
defaultOrder: Order.DESC,
}) {
@FilterField(UnavailabilityFilters, { internal: true })
@FilterField(() => UnavailabilityFilters, { internal: true })
readonly filter: UnavailabilityFilters;
}

Expand Down

0 comments on commit 6756446

Please sign in to comment.