Dataloader `prime`
ravangen opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
Provide an option to prime the dataloader's result cache with the provided key and value to avoid data being fetched needlessly.
Examples:
Describe the solution you'd like
Mechanism to add a result into a GraphQL::Dataloader::Source
instance.
EDIT: Looking more closely, is that the purpose of merge
? Perhaps an alias could be of benefit?
def prime(key, value)
merge(key => value)
end
Additional context
Exploring feature parity between graphql-batch and dataloader, testing the wheels 😄
Yes, that's exactly what merge
is for 👍 I'm open to supporting def prime
if you'd like to implement it. It could probably be implemented without creating the Hash, too:
def prime(new_k, new_v)
key = result_key_for(new_k)
@results[key] = new_v
end
Thanks, makes sense. Should have looked more closely.
I'm going to close the issue for now, since I have something working. But I'll keep this in mind for the future.