Skip to content

Commit 8f700c3

Browse files
committed
Add an interface for declaring resource relations
This allows types & values to be patched in so that resource file doesn't have to know about what they are.
1 parent 56655ed commit 8f700c3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/common/resource.dto.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { createMetadataDecorator } from '@seedcompany/nest';
1212
import { LazyGetter as Once } from 'lazy-get-decorator';
1313
import { DateTime } from 'luxon';
14+
import { type OmitIndexSignature } from 'type-fest';
1415
import type {
1516
ResourceDBMap,
1617
ResourceLike,
@@ -29,6 +30,12 @@ import { getParentTypes } from './parent-types';
2930
import { type MaybeSecured, type SecuredProps } from './secured-property';
3031
import { type AbstractClassType } from './types';
3132

33+
// Merge with this to declare Relations types for Resources.
34+
// Be sure to patch at runtime too.
35+
// Don't reference this type directly, other than to declaration merge.
36+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
37+
export interface DeclareResourceRelations {}
38+
3239
const GqlClassType = createMetadataDecorator({
3340
key: CLASS_TYPE_METADATA,
3441
setter: (type: ClassTypeVal) => type,
@@ -54,7 +61,12 @@ export const resolveByTypename =
5461
@DbLabel('BaseNode')
5562
export abstract class Resource extends DataObject {
5663
// eslint-disable-next-line @typescript-eslint/naming-convention
57-
static readonly Relations = () => ({} satisfies ResourceRelationsShape);
64+
static readonly Relations =
65+
(): OmitIndexSignature<DeclareResourceRelations> => {
66+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
67+
// @ts-ignore -- runtime needs to be patched in.
68+
return {};
69+
};
5870

5971
readonly __typename?: string;
6072

0 commit comments

Comments
 (0)