8000 Typeorm automatically load relations when requested · Issue #33 · capaj/decapi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Typeorm automatically load relations when requested #33
Open
@paales

Description

@paales

Hi @capaj! Thanks for forking and extending this! I'm trying to implement GraphQL with TypeORM, so far so good, the GraphQL part is working pretty nicely, but I am not sure how I should pass the right request to Typeorm, expecially while loading relationships and relations of relations:

So I have the following Graph:
Schermafbeelding 2019-09-06 om 13 20 46

I have the following resolver:

#Schema
@SchemaRoot()
class Schema {
  @Query({ type: Voorraad })
  async inventory(artikelnummer: string, @Context { dbConn }: IContext): Promise<Voorraad> {
    const result = await dbConn.manager
      .getRepository(Voorraad)
      .findOne({ where: { artikelnummer }, relations: ['onderdeelsoort'] })
    return result
  }
}
#Relation definition
@ManyToOne(() => Ondsoort, (ondsoort: Ondsoort) => ondsoort.voorraads, {
  onDelete: 'RESTRICT',
  onUpdate: 'RESTRICT',
})
@JoinColumn({ name: 'onderdeelsoort_id' })
@Field({ type: () => Ondsoort })
onderdeelsoort: Ondsoort | null

Now I manually have to provide the relation field here, but that is far from ideal.. Can the GrapHQL request be 'automatically converted' to a TypeORM request that automatically selects the right relations and relations of relations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0