This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Schema\Resolver; | ||
|
||
abstract class AbstractTypeResolver implements ResolverCollectionInterface | ||
{ | ||
use ResolverTrait; | ||
|
||
/** | ||
* @return callable|null | ||
*/ | ||
public function getResolveCallback(): ?callable | ||
{ | ||
return function (string $fieldName) { | ||
return $this->getResolver($fieldName); | ||
}; | ||
} | ||
|
||
/** | ||
* @param string $fieldName | ||
* @return callable|null | ||
*/ | ||
public function getResolver(string $fieldName): ?callable | ||
{ | ||
$resolveMethod = 'resolve' . \ucfirst($fieldName); | ||
|
||
if (\method_exists($this, $resolveMethod)) { | ||
return [$this, $resolveMethod]; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Schema\Resolver; | ||
|
||
interface ResolverCollectionInterface extends ResolverInterface | ||
{ | ||
/** | ||
* @param string $fieldName | ||
* @return callable|null | ||
*/ | ||
public function getResolver(string $fieldName): ?callable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Schema\Resolver; | ||
|
||
use Digia\GraphQL\Execution\ResolveInfo; | ||
|
||
trait ResolverTrait | ||
{ | ||
/** | ||
* @return callable|null | ||
*/ | ||
public function getTypeResolver(): ?callable | ||
{ | ||
return function ($rootValue, $context = null, ?ResolveInfo $info = null) { | ||
return $this->resolveType($rootValue, $context, $info); | ||
}; | ||
} | ||
|
||
/** | ||
* @param mixed $rootValue | ||
* @param mixed $context | ||
* @param ResolveInfo|null $info | ||
* @return callable|null | ||
*/ | ||
public function resolveType($rootValue, $context = null, ?ResolveInfo $info = null): ?callable | ||
{ | ||
// Override this method when your resolver returns an interface or an union type. | ||
return null; | ||
} | ||
|
||
/** | ||
* @return array|null | ||
*/ | ||
public function getMiddleware(): ?array | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters