1. Go to this page and download the library: Download ez-php/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/ */
ez-php / graphql example snippets
// app/Providers/GraphQLSchemaProvider.php
use EzPhp\Contracts\ServiceProvider;
use EzPhp\GraphQL\SchemaBuilder;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
final class GraphQLSchemaProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(Schema::class, function (): Schema {
return SchemaBuilder::create()
->query([
'hello' => [
'type' => Type::string(),
'resolve' => fn(): string => 'Hello, World!',
],
'user' => [
'type' => Type::string(),
'args' => ['id' => ['type' => Type::nonNull(Type::id())]],
'resolve' => fn($root, array $args): string => 'User ' . $args['id'],
],
])
->build();
});
}
public function boot(): void {}
}