플러그인 설정블록용 커스텀 내부 엔드포인트 생성
블록용 커스텀 내부 엔드포인트 생성
blockEditor 내부 엔드포인트와 마찬가지로, 개발자는 특정 설정을 적용하기 위해 자체적인 사전 정의된 내부 엔드포인트(애플리케이션 또는 블록에 데이터를 제공하기 위한)를 생성할 수 있습니다.
- 중첩 뮤테이션 사용 여부
- 네임스페이싱 사용 여부
- 쿼리 가능한 CPT 사전 정의
- 스키마 설정에서 사용 가능한 기타 설정
다음 PHP 코드는 accessMyPortfolioData라는 이름의 커스텀 내부 엔드포인트를 정의합니다. 이 엔드포인트는 필드 Root.customPosts(「Custom Posts」 모듈)가 MyPortfolio CPT에만 액세스하도록 설정합니다.
<?php
declare(strict_types=1);
use GatoGraphQL\GatoGraphQL\PluginSkeleton\ExtensionHooks\AbstractAddCustomAdminEndpointHook;
use PoP\Root\Module\ModuleInterface;
use PoPCMSSchema\CustomPosts\Environment as CustomPostsEnvironment;
use PoPCMSSchema\CustomPosts\Module as CustomPostsModule;
class MyPortfolioCustomAdminEndpointHook extends AbstractAddCustomAdminEndpointHook
{
protected function getAdminEndpointGroup(): string
{
return 'accessMyPortfolioData';
}
/**
* Allow querying a specific CPT
*
* @param array<class-string<ModuleInterface>,array<string,mixed>> $moduleClassConfiguration [key]: Module class, [value]: Configuration
* @return array<class-string<ModuleInterface>,array<string,mixed>> [key]: Module class, [value]: Configuration
*/
protected function doGetPredefinedAdminEndpointModuleClassConfiguration(
array $moduleClassConfiguration,
): array {
$moduleClassConfiguration[CustomPostsModule::class][CustomPostsEnvironment::QUERYABLE_CUSTOMPOST_TYPES] = ['MyPortfolio'];
return $moduleClassConfiguration;
}
/**
* Do not disable any schema modules
*
* @param array<class-string<ModuleInterface>> $schemaModuleClassesToSkip List of `Module` class which must not initialize their Schema services
* @return array<class-string<ModuleInterface>> List of `Module` class which must not initialize their Schema services
*/
protected function doGetSchemaModuleClassesToSkip(
array $schemaModuleClassesToSkip,
): array {
return [];
}
}plugins_loaded 훅에서 초기화해야 합니다.
add_action('plugins_loaded', function () {
// Validate Gato GraphQL is installed, or exit
if (!class_exists(\GatoGraphQL\GatoGraphQL\Plugin::class)) {
return;
}
new MyPortfolioCustomAdminEndpointHook();
});마지막으로, 파라미터 endpoint_group을 선택한 이름으로 교체하여 엔드포인트에 액세스합니다.
https://yoursite.com/wp-admin/edit.php?page=gatographql&action=run_query&endpoint_group=accessMyPortfolioData