graph-gophers / dataloader

Implementation of Facebook's DataLoader in Golang
MIT License
1.21k stars 75 forks source link

Load function keys as interface{} #23

Closed tonyghita closed 7 years ago

tonyghita commented 7 years ago

I've found the need to pass composite keys to certain batch load functions.

So far, I've been concatenating key parts together into a string before passing the keys to the load function, and then separating the key parts in the load function.

As you can imagine, this is pretty fragile.

I wondering if it would be plausible to change to a keys interface{} argument, to allow for passing structured composite keys.

I'm on the fence whether this change would be worth the added complexity for 90% of use-cases.

nicksrandall commented 7 years ago

Sorry for the delay, I’ve been out of town. Technically, the data loader spec says keys should be strings. That said, I can see a need for the use case you are talking about. Maybe we could change the key to be anything that implements ‘fmt.Stringer’ interface? That would be a non-breaking change and we could pass all keys to ‘fmt.Sprintf(“%s”, key)’ before we cache? What do you think of that?

tonyghita commented 7 years ago

No worries! I thought about it some more and I'm okay just implementing Stringer on my composite key structs. I don't want to push this grossness onto this library 😛