PHP code example of wwwision / graphql

1. Go to this page and download the library: Download wwwision/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/ */

    

wwwision / graphql example snippets


// YourApi.php

namespace Your\Package;

use Neos\Flow\Annotations as Flow;
use Wwwision\TypesGraphQL\Attributes\Query;

#[Flow\Scope('singleton')]
final class YourApi
{
    #[Query]
    public function ping(string $name): string {
        return strtoupper($name);
    }
}

// YourApi.php
// ...
#[Query]
public function ping(Name $name): Name {
    return strtoupper($name);
}

final class SomeCustomResolvers {

    public function __construct(private readonly SomeDependency $incjection) {}
    
    public function getFullName(User $user): string {
        return $user->givenName . ' ' . $user->familyName;
    }
    
    public function isAllowed(User $user, Privilege $privilege): bool {
        return $this->incjection->isUserPrivilegeAllowed($user->id, $privilege);
    }
}

 use Doctrine\ORM\Mapping as ORM;
 use Neos\Flow\Annotations as Flow;

 /**
  * @ORM\Entity
  * @Flow\Proxy(false)
  */
class TestEntity
{

    /**
     * @var string
     * @ORM\Id
     */
    public readonly string $id;

    /**
     * @var string
     * @ORM\Column(length=80)
     */
    public readonly string $title;

    public function __construct(string $id, string $title) {
        $this->id = $id;
        $this->title = $title;
    }
}