with-custom-entity.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Collection, PluginCommonModule, VendureEntity, VendurePlugin } from '@vendure/core';
  2. import gql from 'graphql-tag';
  3. import { DeepPartial, Entity, ManyToMany, OneToMany } from 'typeorm';
  4. @Entity()
  5. export class TestCustomEntity extends VendureEntity {
  6. constructor(input?: DeepPartial<TestCustomEntity>) {
  7. super(input);
  8. }
  9. @ManyToMany(() => Collection, x => (x as any).customFields?.customEntityList, {
  10. eager: true,
  11. })
  12. customEntityListInverse: Collection[];
  13. @OneToMany(() => Collection, (a: Collection) => (a.customFields as any).customEntity)
  14. customEntityInverse: Collection[];
  15. }
  16. @VendurePlugin({
  17. imports: [PluginCommonModule],
  18. entities: [TestCustomEntity],
  19. adminApiExtensions: {
  20. schema: gql`
  21. type TestCustomEntity {
  22. id: ID!
  23. }
  24. `,
  25. },
  26. configuration: config => {
  27. config.customFields = {
  28. ...(config.customFields ?? {}),
  29. Collection: [
  30. ...(config.customFields?.Collection ?? []),
  31. {
  32. name: 'customEntity',
  33. type: 'relation',
  34. entity: TestCustomEntity,
  35. list: false,
  36. public: false,
  37. inverseSide: (t: TestCustomEntity) => t.customEntityInverse,
  38. graphQLType: 'TestCustomEntity',
  39. },
  40. {
  41. name: 'customEntityList',
  42. type: 'relation',
  43. entity: TestCustomEntity,
  44. list: true,
  45. public: false,
  46. inverseSide: (t: TestCustomEntity) => t.customEntityListInverse,
  47. graphQLType: 'TestCustomEntity',
  48. },
  49. ],
  50. };
  51. return config;
  52. },
  53. })
  54. export class WithCustomEntity {}