First time working with GraphQL, so sorry if my thinking is totally wrong.
What I'm trying to reach is:
I have a function inside a model to get some details:
public function getMyCustomAttribute()
{
// Used by GraphQL
$Details = MyDetailModel::Details($this->id);
if(!$Details) return null;
return $Details;
}
This works perfect like it should, I access it within a type, i query it with ( within a other type ):
'details' => [
'alias' => 'MyCustom',
'type' => Type::listOf(GraphQL::type('DetailType')),
'selectable' => false,
'description' => 'The details',
],
Now I want this function but with only a single detail, I tried it like this
'detail' => [
'args' => [
'type' => [
'type' => Type::string(),
],
],
'alias' => 'SingleDetail',
'selectable' => false,
'type' => Type::listOf(GraphQL::type('DetailType')),
// $args are the local arguments passed to the relation
// $query is the relation builder object
// $ctx is the GraphQL context (can be customized by overriding `\Rebing\GraphQL\GraphQLController::queryContext`
'query' => function(array $args, $query, $ctx) {
}
],
My question now, and my problem , how do i get the arg['type'] inside my mutator of my model? or am I thinking totally wrong?
I _think_ maybe because you're using selectable => false, query, which is a feature of SelectFields, is not evaluated at all.
Is your plan to have $args['type'] to pass to MyDetailModel::Details(…)? Then you could do it in a resolve method (instead of query). The arguments should be the same for a regular resolver.
I am indeed trying to pass the args to my details() model function, how should I implent the resolve method?
'resolve' => function ($root, array $args) {
return MyDetailModel::Details($args['type'])->first();
}
or something? I don't know enough details.
Alright, worked like a charm.
Thank you for your time!