Skip to content

Commit

Permalink
feat(graphql)!: TypeDefinition can be fully replaced via `Container…
Browse files Browse the repository at this point in the history
…` (`TypeDefinition::getTypeName()` became is non `static`).
  • Loading branch information
LastDragon-ru committed Aug 31, 2023
1 parent cacf098 commit 0ee21c7
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/graphql/src/Builder/Contracts/TypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface TypeDefinition {
/**
* Returns the type name for given Builder and Source.
*/
public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string;
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string;

/**
* Returns the type definition for given Source if possible. The name must be equal to `$name`.
Expand Down
16 changes: 8 additions & 8 deletions packages/graphql/src/Builder/Manipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ public function getBuilderInfo(): BuilderInfo {
// <editor-fold desc="TypeProvider">
// =========================================================================
public function getType(string $definition, TypeSource $source): string {
// Instance (phpstan is not so smart yet...)
$instance = Container::getInstance()->make($definition);

if (!($instance instanceof TypeDefinition)) {
throw new TypeDefinitionImpossibleToCreateType($definition, $source);
}

// Exists?
$name = $definition::getTypeName($this, $this->getBuilderInfo(), $source);
$name = $instance->getTypeName($this, $this->getBuilderInfo(), $source);

if ($this->isTypeDefinitionExists($name)) {
return $name;
Expand All @@ -86,13 +93,6 @@ public function getType(string $definition, TypeSource $source): string {
// Fake
$this->addFakeTypeDefinition($name);

// Instance (phpstan is not so smart yet...)
$instance = Container::getInstance()->make($definition);

if (!($instance instanceof TypeDefinition)) {
throw new TypeDefinitionImpossibleToCreateType($definition, $source);
}

// Create new
$node = $instance->getTypeDefinition($this, $name, $source);

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public function call(
throw new Exception('should not be called');
}

public static function getTypeName(
public function getTypeName(
Manipulator $manipulator,
BuilderInfo $builder,
TypeSource $source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
$typeName = $source->getTypeName();
$builderName = $builder->getName();
$operatorName = Str::studly(Relation::getName());
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Types/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
use const SORT_REGULAR;

class Condition extends InputObject {
public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
$typeName = $source->getTypeName();
$builderName = $builder->getName();
$directiveName = Directive::Name;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Types/Enumeration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
$directiveName = Directive::Name;
$builderName = $builder->getName();
$typeName = $source->getTypeName();
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Types/Flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
return Directive::Name.'TypeFlag';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Types/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
$typeName = $source->getTypeName();
$directiveName = Directive::Name;

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Types/Scalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
$directiveName = Directive::Name;
$builderName = $builder->getName();
$typeName = $source->getTypeName();
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Types/Clause.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use const SORT_REGULAR;

class Clause extends InputObject {
public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
$directiveName = Directive::Name;
$builderName = $builder->getName();
$typeName = $source->getTypeName();
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Types/Direction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
return Directive::Name.'TypeDirection';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Types/Flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct() {
// empty
}

public static function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
public function getTypeName(Manipulator $manipulator, BuilderInfo $builder, TypeSource $source): string {
return Directive::Name.'TypeFlag';
}

Expand Down

0 comments on commit 0ee21c7

Please sign in to comment.