Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin UI Can not editing collection while customized fields with relation type (with translations) #1338

Closed
tianyingchun opened this issue Jan 11, 2022 · 3 comments
Assignees
Labels
status: reproduction needed 🔁 Reproduction of described behaviour needed by core team type: bug 🐛 Something isn't working

Comments

@tianyingchun
Copy link
Contributor

tianyingchun commented Jan 11, 2022

Describe the bug
Can not editing collection while customized fields with relation type (with translations)

To Reproduce
Steps to reproduce the behavior:

  1. extends new fields named campaign (relation type) on collection as below
 {
    type: 'relation',
    name: 'campaign',
    nullable: true,
    entity: Campaign,
    eager: true,
    public: true,
    label: [
      {
        languageCode: LanguageCode.en,
        value: 'Campaign',
      },
    ],
    description: [
      {
        languageCode: LanguageCode.en,
        value: 'Campaign of this collection page',
      },
    ],
  },
    config.customFields.Collection.push(...x);
   
  1. setup collection entity field(campaignId) with valid ID of Campaign entity.
  2. Go to admin collection page catalog/collections click editing button to ready redirect tocollection` detail page.
  3. throw error Cannot return null for non-nullable field Campaign.name.

Expected behavior
the Campaign entity as below

@Entity('campaign')
export class Campaign extends VendureEntity {
  constructor(input?: DeepPartial<Campaign>) {
    super(input);
  }

  @Column('varchar')
  campaignType: CampaignType;

 
  @Column({ nullable: true })
  periodOfValidity: number;

  @Column({ unique: true })
  code: string;

 
  name: LocaleString;

  applyForBeforeData: LocaleString;

  applyForResultData: LocaleString;

 
  @Column({ default: true })
  enabled: boolean;

  @ManyToOne(() => Promotion, { onDelete: 'SET NULL' })
  promotion: Promotion | null;

  @Column('int', { nullable: true })
  promotionId: ID | null;

  @OneToMany(() => CampaignTranslation, (translation) => translation.base, { eager: true })
  translations: Array<Translation<CampaignTranslation>>;
}
@Entity('campaign_translation')
export class CampaignTranslation extends VendureEntity implements Translation<Campaign> {
  constructor(input?: DeepPartial<Translation<CampaignTranslation>>) {
    super(input);
  }
  @Column('varchar')
  languageCode: LanguageCode;

  @Column('varchar')
  name: string;

  @Column('simple-json')
  applyForBeforeData: any;

  @Column('simple-json')
  applyForResultData: any;

  @ManyToOne(() => Campaign, (base) => base.translations, { onDelete: 'CASCADE' })
  base: Campaign;
}

Environment (please complete the following information):

  • @vendure/core version: 1.4.4
  • Nodejs version 16+
  • Database (mysql/postgres etc):mysql

Additional context
for Admin UI /catalog/collections Editing button before redirect to collect detail page.

  type Campaign implements Node {
    id: ID!
    createdAt: DateTime!
    updatedAt: DateTime!
   // here if we expose name as `optional`, the  admin works fine, other wise throw me error.
    name: String!
    code: String!
    promotion: Promotion
    periodOfValidity: Int
    enabled: Boolean!
    campaignType: CampaignType!
    applyForBeforeData: CampaignApplyForBeforeData!
    applyForResultData: CampaignApplyForResultData!
  }

If we expose graphql Campaign property name as optional,( name: String!)==> (name: String) the admin works fine, other wise throw me error.

@tianyingchun tianyingchun added the type: bug 🐛 Something isn't working label Jan 11, 2022
@tianyingchun tianyingchun changed the title Can not editing collection while customized fields with relation type (with translations) Admin UI Can not editing collection while customized fields with relation type (with translations) Jan 11, 2022
@michaelbromley michaelbromley moved this to 📅 Planned in Vendure OS Roadmap Jul 1, 2022
@jnugh

This comment was marked as outdated.

@jnugh
Copy link
Contributor

jnugh commented Mar 30, 2023

While writing a test using default entities I noticed that this issue does not occur on stock entities. There are already field resolvers in place for this case. I just had to add them to our custom entities. 🤦🏽‍♂️

e.g. the product resolver has:

 @ResolveField()
    name(@Ctx() ctx: RequestContext, @Parent() product: Product): Promise<string> {
        return this.localeStringHydrator.hydrateLocaleStringField(ctx, product, 'name');
    }

@dlhck dlhck added the status: reproduction needed 🔁 Reproduction of described behaviour needed by core team label Sep 24, 2024
@dlhck dlhck moved this from 📅 Planned to 👀 Under consideration in Vendure OS Roadmap Sep 24, 2024
@martijnvdbrug
Copy link
Collaborator

Thanks for your report. I am going to close this one, because:

  1. The error Cannot return null for non-nullable field Campaign.name indicates that it has to do with your custom Campaign entity rather than Vendure core
  2. This issue is a bit old, a lot has changed since this issue was created.

Please feel free to open a new issue if this issue persist in the latest versions of Vendure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: reproduction needed 🔁 Reproduction of described behaviour needed by core team type: bug 🐛 Something isn't working
Projects
Status: 👀 Under consideration
Development

No branches or pull requests

5 participants