Joystream / hydra

A Substrate indexing framework
49 stars 44 forks source link

Missing model relations when two different one-to-many entity relationships use the same field names #443

Open Lezek123 opened 3 years ago

Lezek123 commented 3 years ago

Version: 3.1.0-alpha.0

Minimal schema example:

type ForumThread @entity {
  id: ID!
  title: String!
  posts: [ForumPost!] @derivedFrom(field: "thread")
}

type ForumPost @entity {
  id: ID!
  thread: ForumThread!
}

type ProposalDiscussionThread @entity {
  id: ID!
  test: String!
  posts: [ProposalDiscussionPost!] @derivedFrom(field: "thread")
}

type ProposalDiscussionPost @entity {
  id: ID!
  thread: ProposalDiscussionThread!
  text: String!
}

Hydra codegen result:

Only the ForumThread -> ForumPost relationship is preserved in the generated models, while the ProposalDiscussionThread -> ProposalDiscussionPost relationship is missing:

proposal-discussion-post.model.ts

import { BaseModel, Model, StringField } from 'warthog';

@Model({ api: {} })
export class ProposalDiscussionPost extends BaseModel {
  @StringField({})
  text!: string;

  constructor(init?: Partial<ProposalDiscussionPost>) {
    super();
    Object.assign(this, init);
  }
}

proposal-discussion-thread.model.ts

import { BaseModel, Model, StringField } from 'warthog';

@Model({ api: {} })
export class ProposalDiscussionThread extends BaseModel {
  @StringField({})
  test!: string;

  constructor(init?: Partial<ProposalDiscussionThread>) {
    super();
    Object.assign(this, init);
  }
}

Additional observations

Changing any of the relationship field names (posts -> discussionPosts or thread -> discussionThread) in ProposalDiscussionThread -> ProposalDiscussionPost relationship resolves the issue.

dmtrjsg commented 2 years ago

Needs refreshing and allocation to the right pipeline @ondratra

dmtrjsg commented 2 years ago

Key: Changing any of the relationship field names (posts -> discussionPosts or thread -> discussionThread) in ProposalDiscussionThread -> ProposalDiscussionPost relationship resolves the issue.