λΈ”λ‘œκ·Έ

πŸ¦ΈπŸΏβ€β™‚οΈ Gato GraphQL이 이제 PHP 8.0μ—μ„œ 7.1둜 νŠΈλžœμŠ€νŒŒμΌλ©λ‹ˆλ‹€

Leonardo Losoviz
μž‘μ„±μž: Leonardo Losoviz Β·

μ˜ˆμ „μ— PHP μ½”λ“œλ₯Ό νŠΈλžœμŠ€νŒŒμΌν•˜λŠ” 기법에 λŒ€ν•΄ 글을 μ“΄ 적이 μžˆμŠ΅λ‹ˆλ‹€.

PHP μ½”λ“œλ₯Ό νŠΈλžœμŠ€νŒŒμΌν•˜λ©΄ 개발 μ‹œμ—λŠ” μ΅œμ‹  PHP κΈ°λŠ₯을 μ‚¬μš©ν•˜λ©΄μ„œλ„, ν”„λ‘œλ•μ…˜ 배포 μ‹œμ—λŠ” μ½”λ“œλ₯Ό ꡬ 버전 PHP둜 λ³€ν™˜ν•˜μ—¬ ν”ŒλŸ¬κ·ΈμΈμ„ λ¦΄λ¦¬μŠ€ν•  수 μžˆμ–΄ 더 λ§Žμ€ μ‚¬μš©μžλ₯Ό λŒ€μƒμœΌλ‘œ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ§€λ‚œ λͺ‡ μ£Ό λ™μ•ˆ Gato GraphQL ν”ŒλŸ¬κ·ΈμΈμ„ μœ„ν•΄ 이 ν”„λ‘œμ„ΈμŠ€λ₯Ό λ”μš± μ •κ΅ν•˜κ²Œ λ‹€λ“¬μ—ˆμŠ΅λ‹ˆλ‹€.

이제 ν”ŒλŸ¬κ·ΈμΈμ˜ μš”κ΅¬ PHP 버전이 PHP 8.0으둜 μ—…κ·Έλ ˆμ΄λ“œλ˜μ—ˆμŒμ„ 기쁘게 μ•Œλ €λ“œλ¦½λ‹ˆλ‹€.

PHP μ΅œμ†Œ 버전 8.0으둜 μ—…κ·Έλ ˆμ΄λ“œ

이제 ν”ŒλŸ¬κ·ΈμΈμ΄ PHP 8.0을 μ „μ œλ‘œ μ‚¬μš©ν•  수 있게 λ˜λ©΄μ„œ, μ½”λ“œλ² μ΄μŠ€ μ „μ²΄μ˜ λͺ¨λ“  PHP ν΄λž˜μŠ€μ— μžˆλŠ” λͺ¨λ“  ν”„λ‘œνΌν‹°μ— νƒ€μž…μ„ μΆ”κ°€ν•˜λŠ” μž‘μ—…μ„ μ™„λ£Œν•  수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€. μœ λ‹ˆμ˜¨ νƒ€μž…λ„ ν¬ν•¨λ©λ‹ˆλ‹€.

ν›Œλ₯­ν•©λ‹ˆλ‹€!

μ•„λž˜λŠ” ν”ŒλŸ¬κ·ΈμΈ 개발 μ‹œ μ‚¬μš©ν•  수 μžˆλŠ” λͺ¨λ“  μƒˆλ‘œμš΄ PHP 8.0 κΈ°λŠ₯의 μš”μ•½μž…λ‹ˆλ‹€.

PHP 8.0 μ‹ κΈ°λŠ₯

Gato GraphQL을 κ°œλ°œν•  λ•Œ λ‹€μŒ PHP 8.0 κΈ°λŠ₯을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

각각의 μ˜ˆμ‹œμ™€ ν”ŒλŸ¬κ·ΈμΈ κ°œλ°œμ—μ„œ μ–΄λ–»κ²Œ μ‚¬μš©λ˜λŠ”μ§€, 그리고 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);
}

λ‰΄μŠ€λ ˆν„° κ΅¬λ…ν•˜κΈ°

Gato GraphQL의 λͺ¨λ“  μ—…λ°μ΄νŠΈλ₯Ό λ†“μΉ˜μ§€ λ§ˆμ„Έμš”.