Skip to content

Self-relation does not propagate (go deeper) with other relations #38

Description

@dmythro

First of all, this lib is awesome, saves tons of time for the projects which use GraphQL. I really hope it gets to v1 sometime :)

Now, I've found an issue: when doing self-relations, GraphQL schema adds a relation properly, but does not go deeper than that. Example:

export const asset = testSchema.table(
  'asset',
  {
    id: uuid().notNull().primaryKey().defaultRandom(),
    templateId: uuid(),
    assetTypeId: uuid()
      .notNull()
      .references(() => assetType.id, { onDelete: 'restrict', onUpdate: 'cascade' }),
    name: text().notNull(),
  },
  (table) => [
    foreignKey({
      name: 'template',
      columns: [table.templateId],
      foreignColumns: [table.id],
    })
      .onDelete('cascade')
      .onUpdate('cascade'),
  ],
)

export const assetRelations = relations(asset, ({ many, one }) => ({
  assetType: one(assetType, {
    fields: [asset.assetTypeId],
    references: [assetType.id],
  }),
  template: one(asset, { fields: [asset.templateId], references: [asset.id] }),
}))

I've tried (just in case) both Apollo and Yoga, and both behave the same way. I can query the asset, with assetType (and go deeper if there's a relation in other cases), but with a template, I can only query own asset fields, can't go deeper with assetType etc, only assetTypeId.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions