<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
v16studios / graphql-laravel-bootstrapper example snippets
namespace App\GraphQL\Types\Global;
use GraphQL\Bootstrapper\Interfaces\GraphQlType;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Support\Type;
class UserType extends Type implements GraphQlType
{
protected $attributes = [
'name' => 'User',
'description' => 'A user account.',
];
public function fields() : array
{
return [
'id' => [
'type' => GraphQL::type('Int'),
'description' => 'The id of the User.',
],
'uuid' => [
'type' => GraphQL::type('String'),
'description' => "The user's UUID.",
],
'email' => [
'type' => GraphQL::type('String'),
'description' => "The user's email address.",
],
'isVerified' => [
'type' => GraphQL::type('Boolean'),
'description' => 'Check if the user has verified their email address.',
'resolve' => function ($user) {
return isset($user->email_verified_at);
},
],
'updatedAt' => [
'type' => GraphQL::type('String'),
'resolve' => function ($user) {
return $user->updated_at->toIso8601String();
},
],
];
}
public static function getSchemaName(): string
{
return '';
}
}
namespace App\GraphQL\Schemas\Primary\Queries;
use GraphQL\Bootstrapper\Interfaces\GraphQlQuery;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Support\Query;
class GetUserQuery extends Query implements GraphQlQuery
{
protected $attributes = [
'name' => 'GetUser',
'description' => 'Get a user from their API token.',
];
public function type() : Type
{
return GraphQL::type('User');
}
public function args() : array
{
return [];
}
public function resolve($root, $args, $authUser, ResolveInfo $resolveInfo)
{
return $authUser;
}
public static function getSchemaName(): string
{
return 'primary';
}
}
// The name of the default schema
// Used when the route group is directly accessed
'default_schema' => 'primary',
'schemas' => [
'primary' => [
'query' => [
// ExampleQuery::class,
],
'mutation' => [
// ExampleMutation::class,
],
// The types only available in this schema
'types' => [
// ExampleType::class,
],
// Laravel HTTP middleware
'middleware' => [],
// Which HTTP methods to support; must be given in UPPERCASE!
'method' => ['GET', 'POST'],
// An array of middlewares, overrides the global ones
'execution_middleware' => null,
],
],
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.