Closed DiederikvandenB closed 6 years ago
Hi ! Thanks for using our package. Currently, the only way to manage that is to define the following fetchable
entry :
/**
* Returns fetchable endpoint fields
*
* @return array
*/
public function getFetchable() {
return [
// ...
'alerts' => [
'type' => \GraphQL::listOf('alert'),
'args' => ['active' => Type::bool()],
'inputable' => false
],
// ...
];
}
/**
* Resolve `alerts` field
*
* @param Endpoint $root
* @param array $args
* @return \Illuminate\Database\Eloquent\Collection
*/
public function resolveAlertsField(Endpoint $root, array $args) {
return \App\Alert::whereActive($args['active'])->get();
}
query {
endpoints {
id,
name,
alerts (active: true) {
id
created_at
}
}
}
Some rewrites are scheduled to manage easily definition and transformer, to apply properly arguments, filters, etc. I'm working on that as soon as possible :)
Thanks, that looks like a fine solution in the mean time, looking forward to the upcoming changes.
Another question, how would you tackle the N+1 problem when adding relations to definitions?
By defining a closure instead returning the built returned state. We're calling call_user_func
only when needed.
Thanks for making this great package. It makes GraphQL even easier! However, I seem to have ran in to a problem. I was hoping I could make a filter function like this in my
AlertDefinition
:And in my
EndpointDefinition
I would call the relation like this:Now unfortunately, this does not work. The filter will be applied to the root alert query, but it will not allow me to filter like this:
Is there anyway to achieve this "automagically" instead of having to use a custom resolver? Because that would mean that if I would like to apply the same filter on the root alert query, I would either have to write the logic twice, or do some class extending / traits magic which seems rather cumbersome.
I suppose it would be ideal if something like this would be possible:
(How) can something like this be achieved?