<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
almservices / attributed-graphql-model-types example snippets
#[Model(name: "AnimalAlias")]
class Animal
{
#[ID]
#[Field]
public int $id;
#[Field]
public string $name;
}
/**
* @Model(name: "AnimalAlias")
*/
class Animal
{
/**
* @ID
* @Field
*/
public int $id;
/**
* @Field
*/
public string $name;
}
class AnimalType extends ModelType
{
public function __construct(bool $isProd)
{
parent::__construct(Animal::class, new TypeContainer($isProd), $isProd);
}
}
new ModelType(Animal::class, new TypeContainer($isProd), $isProd);
#[Model(name: "Foo")]
class Foo
{
#[Field]
public int $bar;
#[Field]
public function baz(): string
{
return 'baz';
}
}
#[Model(name: "AnimalAlias")]
class Foo
{
#[Alias("bar")]
#[Field]
public int $foo;
}
#[Model(name: "Family")]
enum Family
{
case SEAL;
case BEAR;
}
#[Model(name: "Foo")]
class InlineEnum
{
#[Field]
#[Enum("SingleEnum", "A", "B", "C", "D")]
public string $single;
#[Field]
#[ListOf("ListEnum")]
#[Enum("ListEnum", "A", "B", "C", "D")]
public array $list;
}
#[Model("SomeEnum")]
class SomeEnum: string
{
case FOO = 'foo'; // FOO
}
#[Model("SomeEnum")]
class SomeEnum: int
{
case FOO = 1; // FOO
}
#[Model("SomeEnum")]
class SomeEnum: string
{
#[Alias("foo")]
case FOO = "bar"; // foo
}
#[Model("SomeEnum")]
class SomeEnum: int
{
#[Alias("foo")]
case FOO = 1; // foo
}
#[Model("SomeEnum")]
class SomeEnum: int
{
case FOO;
case BAR;
#[Ignore]
case BAZ;
}
#[Model("Foo")]
class Foo
{
#[Field]
#[ListOf(type: "string")]
public \Traversable $test; // [String]!
#[Field]
#[ListOf(type: "string")]
public array $foo; // [String]!
#[Field]
#[ListOf(type: self::class)]
public iterable $bar; // [Foo]!
#[Field]
#[ListOf(type: OtherModel::class)]
public array $baz; // [OtherModel]!
#[Field]
#[ListOf(type: OtherModel::class)]
public \Doctrine\Common\Collections\Collection $qux; // [OtherModel]!
}
#[Model("Foo")]
class Foo {
#[Field]
#[NonNull]
#[ListOf("string")]
public array $list; // [String!]!
}
class FooBar implements Stringable
{
private string $type;
private function __construct(string $type)
{
$this->type = $type;
}
public static function foo(): self
{
return new self('foo');
}
public static function bar(): self
{
return new self('foo');
}
public function __toString(): string
{
return $this->type;
}
}
#[Model(name: "Foo")]
class Foo {
#[ID]
#[Field]
public readonly FooBar $id;
}
#[Model(name: "Foo")]
class Foo {
public function __construct(
private string $foo,
private string $bar,
) {}
#[ID]
#[Field]
public function id(): string
{
return $this->foo . $this->bar;
}
}
#[Model(name: "Foo")]
class Foo {
#[Field]
#[Deprecated("Do not use Foo.foo, use Foo.bar instead")]
public function foo(): string
{
return 'foo';
}
#[Field]
public function bar(): string
{
return 'bar';
}
}
#[Description("Foo is Bar")]
#[Model(name: "Foo")]
class Foo {
#[Field]
#[Description("Foo foo?")]
public function foo(): string
{
return 'foo';
}
}