Files
animethemes-server/app/Concerns/GraphQL/ResolvesDirectives.php
T
2025-07-30 02:20:46 -03:00

31 lines
824 B
PHP

<?php
declare(strict_types=1);
namespace App\Concerns\GraphQL;
trait ResolvesDirectives
{
/**
* Convert the array of directives into a string format for GraphQL.
*
* @param array<string, array<string, mixed>> $directives
*/
protected static function resolveDirectives(array $directives): string
{
return collect($directives)
->map(function ($args, $directive) {
if (blank($args)) {
return sprintf('@%s', $directive);
}
$argsString = collect($args)
->map(fn ($value, $key) => sprintf('%s: %s', $key, json_encode($value)))
->implode(', ');
return sprintf('@%s(%s)', $directive, $argsString);
})
->implode(' ');
}
}