Comments (3)
So have a look at this and see if it makes sense: https://github.com/silverstripe/silverstripe-graphql/blob/cedacb79929745bd1d49bf9309e68c7679c7a90e/src/Schema/Resolver/ComposedResolver.php
Presumably this would only work for a function of a single argument. If multiple arguments are passed to such a call-back, it should probably ignore subsequent arguments.
Not necessarily. In my example, you see I'm just replacing the first argument each time, but that's very graphql specific. I reckon you just pass $prevResult
as the final argument.
I also append a $done
argument to the params so that any single function can cancel execution (like event propagation).
Should a return value of null be handled specially?
I think it null
is okay, because in my example, you're not destroying anything. Each callback still receives all the original values.
public function call(...$args): array
{
/** @var array<mixed> $results */
$results = [];
$prevValue = null;
foreach ($this->callbacks as $callback) {
$callbackArgs = array_merge($args, [$prevValue]);
$prevValue = \call_user_func_array($callback, $args);
$results[] = $prevValue;
}
return $results;
}
You might not want to have $prevValue
default to null
so that a user could hook into "this is the first callback", in which case, you would leave it undefined and do the array_merge
in an isset
condition, and a user would have to do a count($args)
check to see if it's one short.
from callbacklist.
Could you post an example of how the linked resolver in GraphQL is used?
from callbacklist.
So if you look here, this is the abstract PaginationPlugin (no assumptions about DataList):
It's using ->addResolverAfterware()
to apply a (to be defined in the concrete layer) pagination function.
Then if you look at the concrete layer, the DataList paginator:
It can assume there that $obj
is a DataList that has already had ->filter()
calls made against it, for instance.
A key place where this matters would be something like the canViewPermission
plugin, where you need to ensure that it comes absolutely last, so it can do a filterByCallback
and obscure any sensitive data from the result set.
... if only there was some hastily scrawled ACL module we could use 🤔
from callbacklist.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from callbacklist.