mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
31 lines
824 B
PHP
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(' ');
|
|
}
|
|
}
|