プラグインの設定
プラグインの設定ブロック用カスタム内部エンドポイントの作成

ブロック用カスタム内部エンドポイントの作成

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