Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add example of a custom non-record-loading loader #89
Comments
|
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:
|
|
Hey, @hidde-jan, @Amnesthesia .
This example is far from ActiveRecord or any ORM class MyLoader < GraphQL::Batch::Loader
def initialize(arguments)
@arguments = arguments
end
# Usually you don't have to implement your method unless some type casts are different
def load(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_results
def perform(keys)
results = get_results(keys)
results.each { |result| fulfill(result.key, result)}
keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
end
private
def get_results(keys)
# your implementation, remember to return an array
end
end |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

In the README, a
CountLoaderexample 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.