issue-1664.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {
  2. LanguageCode,
  3. LocaleString,
  4. PluginCommonModule,
  5. Product,
  6. Translation,
  7. VendureEntity,
  8. VendurePlugin,
  9. } from '@vendure/core';
  10. import gql from 'graphql-tag';
  11. import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
  12. @Entity()
  13. class Vendor extends VendureEntity {
  14. constructor(input: Partial<Vendor>) {
  15. super(input);
  16. }
  17. description: LocaleString;
  18. @Column()
  19. name: string;
  20. @OneToMany(() => Product, product => (product.customFields as any).vendor)
  21. products: Product[];
  22. @OneToMany(() => VendorTranslation, translation => translation.base, { eager: true })
  23. translations: Array<Translation<Vendor>>;
  24. }
  25. @Entity()
  26. export class VendorTranslation extends VendureEntity implements Translation<Vendor> {
  27. constructor(input?: Partial<Translation<Vendor>>) {
  28. super(input);
  29. }
  30. @Column('varchar')
  31. languageCode: LanguageCode;
  32. @Column('text')
  33. description: string;
  34. @ManyToOne(() => Vendor, vendor => vendor.translations, { onDelete: 'CASCADE' })
  35. base: Vendor;
  36. }
  37. const schema = gql`
  38. type Vendor implements Node {
  39. id: ID!
  40. createdAt: DateTime!
  41. updatedAt: DateTime!
  42. name: String!
  43. description: String!
  44. }
  45. `;
  46. /**
  47. * Test plugin for https://github.com/vendure-ecommerce/vendure/issues/1664
  48. */
  49. @VendurePlugin({
  50. imports: [PluginCommonModule],
  51. entities: [Vendor, VendorTranslation],
  52. shopApiExtensions: { schema, resolvers: [] },
  53. adminApiExtensions: { schema, resolvers: [] },
  54. configuration: config => {
  55. config.customFields.Product.push({
  56. name: 'vendor',
  57. label: [{ languageCode: LanguageCode.en_AU, value: 'Vendor' }],
  58. type: 'relation',
  59. entity: Vendor,
  60. eager: true,
  61. nullable: false,
  62. defaultValue: null,
  63. ui: {
  64. component: 'cp-product-vendor-selector',
  65. },
  66. });
  67. config.customFields.Product.push({
  68. name: 'shopifyId',
  69. type: 'float',
  70. public: false,
  71. });
  72. return config;
  73. },
  74. })
  75. export class Test1664Plugin {}