PHP code example of lastdragon-ru / lara-asp-graphql
1. Go to this page and download the library: Download lastdragon-ru/lara-asp-graphql library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
declare(strict_types = 1);
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Comment extends Model {
protected $table = 'comments';
/**
* Will NOT work
*/
public function user() {
return $this->belongsTo(User::class);
}
/**
* Must be
*/
public function user(): BelongsTo {
return $this->belongsTo(User::class);
}
}
declare(strict_types = 1);
namespace App\GraphQL\Directives;
use Illuminate\Database\Eloquent\Builder;
use LastDragon_ru\LaraASP\GraphQL\Builder\BuilderInfo;
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderInfoProvider;
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource;
use Nuwave\Lighthouse\Support\Contracts\Directive;
use Override;
class CustomDirective implements Directive, BuilderInfoProvider {
#[Override]
public static function definition(): string {
return 'directive @custom';
}
#[Override]
public function getBuilderInfo(TypeSource $source): ?BuilderInfo {
return BuilderInfo::create(Builder::class);
}
public function __invoke(): mixed {
return null;
}
}
declare(strict_types = 1);
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\LaraASP\GraphQLPrinter\Contracts\DirectiveFilter;
use LastDragon_ru\LaraASP\GraphQLPrinter\Contracts\Printer;
use LastDragon_ru\LaraASP\GraphQLPrinter\Settings\DefaultSettings;
use Nuwave\Lighthouse\Schema\SchemaBuilder;
$schema = app()->make(SchemaBuilder::class)->schema();
$printer = app()->make(Printer::class);
$settings = new DefaultSettings();
$printer->setSettings(
$settings->setDirectiveDefinitionFilter(
new class() implements DirectiveFilter {
#[Override]
public function isAllowedDirective(string $directive, bool $isStandard): bool {
return !in_array($directive, ['eq', 'all', 'find'], true);
}
},
),
);
Example::raw($printer->print($schema), 'graphql');