You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A clear example that demonstrates "You can also batch other stuff, not only load records from a DB" could be very helpful for new users. A great example would be something that does a HTTP request to some external API, combining two non-record-from-db-loading use cases.
The text was updated successfully, but these errors were encountered:
I've been using the Record loader a lot, but run into a couple of problems that I haven't been able to figure out; I would love some more documentation on things like:
Is it possible to maintain order after the promises are fulfilled?
Hey, @hidde-jan, @Amnesthesia . CountLoader is just something like other loaders. The most important thing you have to do is to implement perform method . In the user-defined perform method, you have to create some key-value s by input keys using fulfill like this example. Here is the general usage
define your loader class and,
implement initialize, usually with some arguments you need and,
implement perform. In this method you have to get all results by keys, and create your key-value s
This example is far from ActiveRecord or any ORM
classMyLoader < GraphQL::Batch::Loaderdefinitialize(arguments)@arguments=argumentsend# Usually you don't have to implement your method unless some type casts are differentdefload(key)super(key)end# As it is refered from "You can also batch other stuff, not only load records from a DB"# In this example result is an object with attr `key`. Possiblly it is a redis obejct, json or rpc result defined in get_resultsdefperform(keys)results=get_results(keys)results.each{ |result| fulfill(result.key,result)}keys.each{ |key| fulfill(key,nil)unlessfulfilled?(key)}endprivatedefget_results(keys)# your implementation, remember to return an arrayendend
In the README, a
CountLoader
example is named, but it's not particularly detailed:A clear example that demonstrates "You can also batch other stuff, not only load records from a DB" could be very helpful for new users. A great example would be something that does a HTTP request to some external API, combining two non-record-from-db-loading use cases.
The text was updated successfully, but these errors were encountered: