-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Support bi-directional relations in customFields (#2365)
Co-authored-by: Alexis Kobrinski <[email protected]>
- Loading branch information
1 parent
88430e5
commit 0313ce5
Showing
4 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/core/e2e/fixtures/test-plugins/with-custom-entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Collection, PluginCommonModule, VendureEntity, VendurePlugin } from '@vendure/core'; | ||
import gql from 'graphql-tag'; | ||
import { DeepPartial, Entity, ManyToMany, OneToMany } from 'typeorm'; | ||
|
||
@Entity() | ||
export class TestCustomEntity extends VendureEntity { | ||
constructor(input?: DeepPartial<TestCustomEntity>) { | ||
super(input); | ||
} | ||
|
||
@ManyToMany(() => Collection, x => (x as any).customFields?.customEntityList, { | ||
eager: true, | ||
}) | ||
customEntityListInverse: Collection[]; | ||
|
||
@OneToMany(() => Collection, (a: Collection) => (a.customFields as any).customEntity) | ||
customEntityInverse: Collection[]; | ||
} | ||
|
||
@VendurePlugin({ | ||
imports: [PluginCommonModule], | ||
entities: [TestCustomEntity], | ||
adminApiExtensions: { | ||
schema: gql` | ||
type TestCustomEntity { | ||
id: ID! | ||
} | ||
`, | ||
}, | ||
configuration: config => { | ||
config.customFields = { | ||
...(config.customFields ?? {}), | ||
Collection: [ | ||
...(config.customFields?.Collection ?? []), | ||
{ | ||
name: 'customEntity', | ||
type: 'relation', | ||
entity: TestCustomEntity, | ||
list: false, | ||
public: false, | ||
inverseSide: (t: TestCustomEntity) => t.customEntityInverse, | ||
graphQLType: 'TestCustomEntity', | ||
}, | ||
{ | ||
name: 'customEntityList', | ||
type: 'relation', | ||
entity: TestCustomEntity, | ||
list: true, | ||
public: false, | ||
inverseSide: (t: TestCustomEntity) => t.customEntityListInverse, | ||
graphQLType: 'TestCustomEntity', | ||
}, | ||
], | ||
}; | ||
return config; | ||
}, | ||
}) | ||
export class WithCustomEntity {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters