Skip to content

Don't generate empty argument objects #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ namespace GraphQL\SchemaObject;

class RootQueryObject extends QueryObject
{
const OBJECT_NAME = "query";
public const OBJECT_NAME = "query";

public function selectPokemons(RootPokemonsArgumentsObject $argsObject = null)
public function selectPokemons(?RootPokemonsArgumentsObject $argsObject = null): PokemonQueryObject
{
$object = new PokemonQueryObject("pokemons");
if ($argsObject !== null) {
Expand All @@ -263,7 +263,7 @@ class RootQueryObject extends QueryObject
return $object;
}

public function selectPokemon(RootPokemonArgumentsObject $argsObject = null)
public function selectPokemon(?RootPokemonArgumentsObject $argsObject = null): PokemonQueryObject
{
$object = new PokemonQueryObject("pokemon");
if ($argsObject !== null) {
Expand All @@ -287,7 +287,7 @@ class RootPokemonsArgumentsObject extends ArgumentsObject
{
protected $first;

public function setFirst($first)
public function setFirst($first): self
{
$this->first = $first;

Expand All @@ -308,14 +308,14 @@ class RootPokemonArgumentsObject extends ArgumentsObject
protected $id;
protected $name;

public function setId($id)
public function setId($id): self
{
$this->id = $id;

return $this;
}

public function setName($name)
public function setName($name): self
{
$this->name = $name;

Expand All @@ -336,30 +336,30 @@ namespace GraphQL\SchemaObject;

class PokemonQueryObject extends QueryObject
{
const OBJECT_NAME = "Pokemon";
public const OBJECT_NAME = "Pokemon";

public function selectId()
public function selectId(): self
{
$this->selectField("id");

return $this;
}

public function selectNumber()
public function selectNumber(): self
{
$this->selectField("number");

return $this;
}

public function selectName()
public function selectName(): self
{
$this->selectField("name");

return $this;
}

public function selectWeight(PokemonWeightArgumentsObject $argsObject = null)
public function selectWeight(?PokemonWeightArgumentsObject $argsObject = null): PokemonDimensionQueryObject
{
$object = new PokemonDimensionQueryObject("weight");
if ($argsObject !== null) {
Expand All @@ -370,7 +370,7 @@ class PokemonQueryObject extends QueryObject
return $object;
}

public function selectHeight(PokemonHeightArgumentsObject $argsObject = null)
public function selectHeight(?PokemonHeightArgumentsObject $argsObject = null): PokemonDimensionQueryObject
{
$object = new PokemonDimensionQueryObject("height");
if ($argsObject !== null) {
Expand All @@ -381,28 +381,28 @@ class PokemonQueryObject extends QueryObject
return $object;
}

public function selectClassification()
public function selectClassification(): self
{
$this->selectField("classification");

return $this;
}

public function selectTypes()
public function selectTypes(): self
{
$this->selectField("types");

return $this;
}

public function selectResistant()
public function selectResistant(): self
{
$this->selectField("resistant");

return $this;
}

public function selectAttacks(PokemonAttacksArgumentsObject $argsObject = null)
public function selectAttacks(?PokemonAttacksArgumentsObject $argsObject = null): PokemonAttackQueryObject
{
$object = new PokemonAttackQueryObject("attacks");
if ($argsObject !== null) {
Expand All @@ -413,28 +413,28 @@ class PokemonQueryObject extends QueryObject
return $object;
}

public function selectWeaknesses()
public function selectWeaknesses(): self
{
$this->selectField("weaknesses");

return $this;
}

public function selectFleeRate()
public function selectFleeRate(): self
{
$this->selectField("fleeRate");

return $this;
}

public function selectMaxCP()
public function selectMaxCP(): self
{
$this->selectField("maxCP");

return $this;
}

public function selectEvolutions(PokemonEvolutionsArgumentsObject $argsObject = null)
public function selectEvolutions(?PokemonEvolutionsArgumentsObject $argsObject = null): PokemonQueryObject
{
$object = new PokemonQueryObject("evolutions");
if ($argsObject !== null) {
Expand All @@ -445,7 +445,7 @@ class PokemonQueryObject extends QueryObject
return $object;
}

public function selectEvolutionRequirements(PokemonEvolutionRequirementsArgumentsObject $argsObject = null)
public function selectEvolutionRequirements(?PokemonEvolutionRequirementsArgumentsObject $argsObject = null): PokemonEvolutionRequirementQueryObject
{
$object = new PokemonEvolutionRequirementQueryObject("evolutionRequirements");
if ($argsObject !== null) {
Expand All @@ -456,18 +456,18 @@ class PokemonQueryObject extends QueryObject
return $object;
}

public function selectMaxHP()
public function selectMaxHP(): self
{
$this->selectField("maxHP");

return $this;
}

public function selectImage()
public function selectImage(): self
{
$this->selectField("image");

return $this;
}
}
```
```
15 changes: 8 additions & 7 deletions src/Enumeration/FieldTypeKindEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
*/
class FieldTypeKindEnum
{
const SCALAR = 'SCALAR';
const LIST = 'LIST';
const NON_NULL = 'NON_NULL';
const OBJECT = 'OBJECT';
const INPUT_OBJECT = 'INPUT_OBJECT';
const ENUM_OBJECT = 'ENUM';
const UNION_OBJECT = 'UNION';
const SCALAR = 'SCALAR';
const LIST = 'LIST';
const NON_NULL = 'NON_NULL';
const OBJECT = 'OBJECT';
const INPUT_OBJECT = 'INPUT_OBJECT';
const ENUM_OBJECT = 'ENUM';
const UNION_OBJECT = 'UNION';
const INTERFACE_OBJECT = 'INTERFACE';
}
2 changes: 1 addition & 1 deletion src/SchemaGenerator/CodeGenerator/CodeFile/ClassFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected function generateConstants(): string
if (!empty($this->constants)) {
foreach ($this->constants as $name => $value) {
$value = $this->serializeParameterValue($value);
$string .= " const $name = $value;" . PHP_EOL;
$string .= " public const $name = $value;" . PHP_EOL;
}
}

Expand Down
60 changes: 60 additions & 0 deletions src/SchemaGenerator/CodeGenerator/InterfaceObjectBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace GraphQL\SchemaGenerator\CodeGenerator;

use GraphQL\SchemaGenerator\CodeGenerator\CodeFile\ClassFile;
use GraphQL\Util\StringLiteralFormatter;

/**
* Class InterfaceObjectBuilder
*
* @package GraphQL\SchemaGenerator\CodeGenerator
*/
class InterfaceObjectBuilder extends QueryObjectClassBuilder
{
/**
* @var ClassFile
*/
protected $classFile;

/**
* EnumObjectBuilder constructor.
*
* @param string $writeDir
* @param string $objectName
* @param string $namespace
*/
public function __construct(string $writeDir, string $objectName, string $namespace = self::DEFAULT_NAMESPACE)
{
$className = $objectName . 'QueryObject';

$this->classFile = new ClassFile($writeDir, $className);
$this->classFile->setNamespace($namespace);
if ($namespace !== self::DEFAULT_NAMESPACE) {
$this->classFile->addImport('GraphQL\\SchemaObject\\InterfaceObject');
}
$this->classFile->extendsClass('InterfaceObject');
}

/**
* @param string $typeName
*/
public function addImplementation(string $typeName)
{
$upperCamelCaseTypeName = StringLiteralFormatter::formatUpperCamelCase($typeName);
$objectClassName = $typeName . 'QueryObject';
$method = "public function on$upperCamelCaseTypeName(): $objectClassName
{
return \$this->addImplementation($objectClassName::class);
}";
$this->classFile->addMethod($method);
}

/**
* @return void
*/
public function build(): void
{
$this->classFile->writeFile();
}
}
10 changes: 5 additions & 5 deletions src/SchemaGenerator/CodeGenerator/ObjectClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function addProperty($propertyName)
protected function addScalarSetter($propertyName, $upperCamelName)
{
$lowerCamelName = lcfirst($upperCamelName);
$method = "public function set$upperCamelName($$lowerCamelName)
$method = "public function set$upperCamelName($$lowerCamelName): self
{
\$this->$propertyName = $$lowerCamelName;

Expand All @@ -48,7 +48,7 @@ protected function addScalarSetter($propertyName, $upperCamelName)
protected function addListSetter(string $propertyName, string $upperCamelName, string $propertyType)
{
$lowerCamelName = lcfirst($upperCamelName);
$method = "public function set$upperCamelName(array $$lowerCamelName)
$method = "public function set$upperCamelName(array $$lowerCamelName): self
{
\$this->$propertyName = $$lowerCamelName;

Expand All @@ -65,7 +65,7 @@ protected function addListSetter(string $propertyName, string $upperCamelName, s
protected function addEnumSetter(string $propertyName, string $upperCamelName, string $objectClass)
{
$lowerCamelName = lcfirst(str_replace('_', '', $objectClass));
$method = "public function set$upperCamelName($$lowerCamelName)
$method = "public function set$upperCamelName($$lowerCamelName): self
{
\$this->$propertyName = new RawObject($$lowerCamelName);

Expand All @@ -83,12 +83,12 @@ protected function addEnumSetter(string $propertyName, string $upperCamelName, s
protected function addObjectSetter(string $propertyName, string $upperCamelName, string $objectClass)
{
$lowerCamelName = lcfirst(str_replace('_', '', $objectClass));
$method = "public function set$upperCamelName($objectClass $$lowerCamelName)
$method = "public function set$upperCamelName($objectClass $$lowerCamelName): self
{
\$this->$propertyName = $$lowerCamelName;

return \$this;
}";
$this->classFile->addMethod($method);
}
}
}
Loading
Loading