PHP code example of tylerfiekens / graphqlite-laravel
1. Go to this page and download the library: Download tylerfiekens/graphqlite-laravel 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/ */
tylerfiekens / graphqlite-laravel example snippets
namespace App\GraphQL\Types;
use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Annotations\Field;
#[Type(name: 'Example')]
class ExampleType
{
public function __construct(
private readonly string $name
private readonly array $data
) {
}
#[Field]
public function name(): string
{
return $this->name;
}
#[Field]
public function data(): array
{
return $this->data;
}
}
namespace App\GraphQL\Queries;
use App\GraphQL\Types\ExampleType;
use TheCodingMachine\GraphQLite\Annotations\Query;
class ExampleQuery
{
#[Query('example')]
public function __invoke(): ExampleType
{
return new ExampleType('Example', ['data' => 'example']);
}
}
namespace App\GraphQL\Mutations;
use App\GraphQL\Types\ExampleType;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
class CreateExampleMutation
{
#[Mutation(name: 'createExample')]
public function __invoke(string $name, array $data): ExampleType
{
return new ExampleType($name, $data);
}
}