Update graph-gophers/dataloader to v7
Overview
The currently used version v5
of the graph-gophers/dataloader dependency is outdated and should be replaced with the most recent version v7
which introduces several improvements. To perform the update, the dependency name needs to be changed from github.com/graph-gophers/dataloader
to github.com/graph-gophers/dataloader/v7
.
Refactorings due to breaking changes
As this update introduces various changes, the dataloader-related code needs to be refactored accordingly. The following key aspects need to be considered:
- The library was refactored to use generic types. Whenever a
Loader
is created now, it is necessary to specify a type for its keys (K
) and the results (V
). Therefore, we need to introduce appropriate key and result types for all loaders.- For example, the loader that retrieves the lists of volumes for department numbers should be typed as
*dataloader.Loader[string, []*model.Volume]
since it usesstring
keys and returns slices ofVolume
pointers as the result.
- For example, the loader that retrieves the lists of volumes for department numbers should be typed as
- The
dataloader.Result
type is now also generic and requires specifying theV
generic type that is used for the loader in order to create a batch loader function that can be used for a loader. - The
Keys
interface, which previously represented any type of key, was removed because the key types are now specified via the generic typeK
of the loader. The batch loader functions should now use a slice of theK
generic type instead ofdataloader.Keys
as the type of their second argument.
Additional updates
As part of this issue, all other dependencies should be updated to the most recent versions if they do not require significant code changes. In addition, the Go version of the project should be updated to 1.22
as the latest available version.
Edited by Janek Berg