π¦ΈπΏββοΈ Gato GraphQLμ΄ μ΄μ PHP 8.0μμ 7.1λ‘ νΈλμ€νμΌλ©λλ€
μμ μ PHP μ½λλ₯Ό νΈλμ€νμΌνλ κΈ°λ²μ λν΄ κΈμ μ΄ μ μ΄ μμ΅λλ€.
- Transpiling PHP code from 8.0 to 7.x via Rector
- Coding in PHP 7.4 and deploying to 7.1 via Rector and GitHub Actions
PHP μ½λλ₯Ό νΈλμ€νμΌνλ©΄ κ°λ° μμλ μ΅μ PHP κΈ°λ₯μ μ¬μ©νλ©΄μλ, νλ‘λμ λ°°ν¬ μμλ μ½λλ₯Ό ꡬ λ²μ PHPλ‘ λ³ννμ¬ νλ¬κ·ΈμΈμ 릴리μ€ν μ μμ΄ λ λ§μ μ¬μ©μλ₯Ό λμμΌλ‘ ν μ μμ΅λλ€.
μ§λ λͺ μ£Ό λμ Gato GraphQL νλ¬κ·ΈμΈμ μν΄ μ΄ νλ‘μΈμ€λ₯Ό λμ± μ κ΅νκ² λ€λ¬μμ΅λλ€.
μ΄μ νλ¬κ·ΈμΈμ μꡬ PHP λ²μ μ΄ PHP 8.0μΌλ‘ μ κ·Έλ μ΄λλμμμ κΈ°μκ² μλ €λ립λλ€.

μ΄μ νλ¬κ·ΈμΈμ΄ PHP 8.0μ μ μ λ‘ μ¬μ©ν μ μκ² λλ©΄μ, μ½λλ² μ΄μ€ μ 체μ λͺ¨λ PHP ν΄λμ€μ μλ λͺ¨λ νλ‘νΌν°μ νμ μ μΆκ°νλ μμ μ μλ£ν μ μμμ΅λλ€. μ λμ¨ νμ λ ν¬ν¨λ©λλ€.
νλ₯ν©λλ€!
μλλ νλ¬κ·ΈμΈ κ°λ° μ μ¬μ©ν μ μλ λͺ¨λ μλ‘μ΄ PHP 8.0 κΈ°λ₯μ μμ½μ λλ€.
PHP 8.0 μ κΈ°λ₯
Gato GraphQLμ κ°λ°ν λ λ€μ PHP 8.0 κΈ°λ₯μ μ¬μ©ν μ μμ΅λλ€.
- μ λμ¨ νμ
mixedμ μ¬ νμstaticλ°ν νμ- κ°μ²΄μμμ
::classλ§€μ§ μμ matchννμ- νμ
λ§μΌλ‘
catchμμΈ μ²λ¦¬ - Null μμ μ°μ°μ
- ν΄λμ€ μμ±μ νλ‘νΌν° νλ‘λͺ¨μ
- λ§€κ°λ³μ λͺ©λ‘κ³Ό ν΄λ‘μ
useλͺ©λ‘μ νν μΌν
κ°κ°μ μμμ νλ¬κ·ΈμΈ κ°λ°μμ μ΄λ»κ² μ¬μ©λλμ§, κ·Έλ¦¬κ³ graphql-api.zipμ μμ±ν λ μ΄λ»κ² νΈλμ€νμΌλλμ§ μ΄ν΄λ³΄κ² μ΅λλ€.
μ λμ¨ νμ
interface CustomPostTypeAPIInterface
{
public function createCustomPost(array $data): string | int | null | Error;
}νΈλμ€νμΌ ν:
interface CustomPostTypeAPIInterface
{
public function createCustomPost(array $data)
}mixed μ μ¬ νμ
interface CMSServiceInterface
{
public function getOption(string $option, mixed $default = false): mixed;
}νΈλμ€νμΌ ν:
interface CMSServiceInterface
{
public function getOption(string $option, $default = false);
}κ°μ²΄μμμ ::class λ§€μ§ μμ
foreach ($directiveResolvers as $directiveResolver) {
$directiveResolverName = $directiveResolver->getDirectiveName();
$this->directiveNameClasses[$directiveResolverName][] = $directiveResolver::class;
}νΈλμ€νμΌ ν:
foreach ($directiveResolvers as $directiveResolver) {
$directiveResolverName = $directiveResolver->getDirectiveName();
$this->directiveNameClasses[$directiveResolverName][] = get_class($directiveResolver);
}match ννμ
public function getSchemaFieldType(TypeResolverInterface $typeResolver, string $fieldName): ?string
{
$ret = match($fieldName) {
'accessControlLists' => TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID),
'cacheControlLists' => TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID),
'fieldDeprecationLists' => TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID),
'schemaConfigurations' => TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID),
default => parent::getSchemaFieldType($typeResolver, $fieldName),
};
return $ret;
}νΈλμ€νμΌ ν:
public function getSchemaFieldType(TypeResolverInterface $typeResolver, string $fieldName): ?string
{
switch ($fieldName) {
case 'accessControlLists':
$ret = TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID);
break;
case 'cacheControlLists':
$ret = TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID);
break;
case 'fieldDeprecationLists':
$ret = TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID);
break;
case 'schemaConfigurations':
$ret = TypeCastingHelpers::makeArray(SchemaDefinition::TYPE_ID);
break;
default:
$ret = parent::getSchemaFieldType($typeResolver, $fieldName);
break;
}
return $ret;
}νμ
λ§μΌλ‘ catch μμΈ μ²λ¦¬
try {
// ...
} catch (InvalidArgumentException) {
return sprintf(
'<p>%s</p>',
\__('Oops, the documentation for this module is not available', 'graphql-api')
);
}νΈλμ€νμΌ ν:
try {
// ...
} catch (InvalidArgumentException $exception) {
return sprintf(
'<p>%s</p>',
\__('Oops, the documentation for this module is not available', 'graphql-api')
);
}Null μμ μ°μ°μ
public function getSchemaDirectiveDeprecationDescription(TypeResolverInterface $typeResolver): ?string
{
return $this->getSchemaDefinitionResolver($typeResolver)?->getSchemaDirectiveDeprecationDescription($typeResolver);
}νΈλμ€νμΌ ν:
public function getSchemaDirectiveDeprecationDescription(TypeResolverInterface $typeResolver): ?string
{
return $this->getSchemaDefinitionResolver($typeResolver) ? $this->getSchemaDefinitionResolver($typeResolver)->getSchemaDirectiveDeprecationDescription($typeResolver) : null;
}ν΄λμ€ μμ±μ νλ‘νΌν° νλ‘λͺ¨μ
abstract class AbstractEndpointResolver
{
function __construct(protected EndpointHelpers $endpointHelpers)
{
}
}νΈλμ€νμΌ ν:
abstract class AbstractEndpointResolver
{
/**
* @var \GraphQLAPI\GraphQLAPI\Services\Helpers\EndpointHelpers
*/
protected $endpointHelpers;
function __construct(EndpointHelpers $endpointHelpers)
{
$this->endpointHelpers = $endpointHelpers;
}
}λ§€κ°λ³μ λͺ©λ‘κ³Ό ν΄λ‘μ use λͺ©λ‘μ νν μΌν
public function resolveFieldTypeResolverClass(TypeResolverInterface $typeResolver, string $fieldName): ?string
{
switch ($fieldName) {
case 'accessControlLists':
return CustomPostTypeResolver::class;
}
return parent::resolveFieldTypeResolverClass(
$typeResolver,
$fieldName,
);
}νΈλμ€νμΌ ν:
public function resolveFieldTypeResolverClass(TypeResolverInterface $typeResolver, string $fieldName): ?string
{
switch ($fieldName) {
case 'accessControlLists':
return CustomPostTypeResolver::class;
}
return parent::resolveFieldTypeResolverClass($typeResolver, $fieldName);
}