Closed akomm closed 6 years ago
Is it possible, that you meant $shipID , instead of $shipsID in this:
public function resolveShip($shipsID)
{
$promise = $this->container->get('ships_loader')->load($shipsID);
return $promise;
}
If that is the case, this would explain everything... Load adds ID and the adapter is a higher order promise, when resolved internally resolved the "ship_loader::all" with all the collected $ids.
edit Oh, it looks like. So the loader config creates service instances of DataLoader and DataLoader::load takes a key for a single item ands it to the queue.
The shipsID confused me being plural, which actually is not true, because it would be shipIDs.
The shipsID confused me being plural, which actually is not true, because it would be shipIDs.
can we change this in the docs, i also stumbled on this.
Also an example how to chain a single id in the example would be good.
When i understand correct load ind $this->container->get('ships_loader')->load($shipsID)
is not in the example.
Yes @ivoba, do you want to submit a PR fixing this?
@mcg-web i can fix the typo, sure.
But i still dont understand how to chain an id in the load
method.
Can you explain this maybe?
PR is made. As i understand now the load method of the DataLoader takes care of the queueing, so actually no more to do.
Thanks @ivoba (sorry for late reply!)
@ivoba
Yes, whenever you call load($key)
it adds the $key
to a list for later resolve. It also preserves the order of $key
added to list, so it can later resolve values from the resolved collection you return back to the proper load($key)
-generate promise. And loadMany($keys)
is simply the same, just saves you some imperative manual iteration over multiple $keys
and returns a composed promise that resolves, when all forwarded load($key)
promises resolve.
The following does not require this bundle, except the adapter, which purpose is neither explained nor obvious from readme:
Why do I need to define the adapter in another bundle:
Again, what is the purpose of the adapter? I create service, to create a service which lets the adapter call a load_fn, but it seems from the following example, that I still have to somehow collect the IDs:
So I could simply spare a lot of config and simply use the deffered from webonyx and collect my ids anyway. I could create a single service (instead of two) with almost zero config (using autoconfig/autowire) which does exactly this. Also the resolver usage does magically get shipIds, while actually the resolver would not get IDs, but the value/data being resolved.
The resolver usage combined with previous explanation feels like an "1. do this 2. ??? 3. profit?" currently ;(.