graphql-batch icon indicating copy to clipboard operation
graphql-batch copied to clipboard

Use different column then id for DB-Loading

Open Fleick opened this issue 7 years ago • 2 comments

Hey everyone, i am searching for a possibility use the Loader for other columns then the key-column to work with the following case: I have some ContactModes and every ContactMode is either an Email or a Telephone number, the problem with the Loader is that the foreign-key is in the other table so I have to load email.contact_mode_id == self.id instead of email.id == contact_mode.email_id

In Types::ContactModeType:
  field :email do
    type types[Types::EmailType]
    resolve -> (contact_mode, args, ctx){
      Email.where(contact_mode_id: contact_mode.id)
    }
  end
  field :address do
    type types[Types::AddressType]
    resolve -> (contact_mode, args, ctx) {
      Address.where(contact_mode_id: contact_mode.id)
    }
  end

Is there any possibility to call the loader use Table.column instead of Table.id for Loading? Thanks for answer

Fleick avatar Jun 29 '18 14:06 Fleick

Why don't you make that an association and use the AssociationLoader example?

dylanahsmith avatar Jul 04 '18 19:07 dylanahsmith

@Fleick Take a look at these two links

  1. https://github.com/Shopify/graphql-batch/issues/77#issuecomment-388565859

  2. https://github.com/Shopify/graphql-batch/blob/master/examples/record_loader.rb

frankjdelgado avatar Oct 30 '18 17:10 frankjdelgado