扩展

Internal GraphQL Server

使用 PHP 代码在应用程序内部直接执行 GraphQL queries。

Logo
Target Image

此扩展会安装一个内部 GraphQL Server,可通过 PHP 代码在应用程序内部调用。

内部 GraphQL Server 通过类 GatoGraphQL\InternalGraphQLServer\GraphQLServer 访问,提供以下三个方法:

  • executeQuery:执行一个 GraphQL query
  • executeQueryInFile:执行包含在 (.gql) 文件中的 GraphQL query
  • executePersistedQuery:执行已保存的 GraphQL query(以整数形式提供 ID,或以字符串形式提供 slug)(需要 Persisted Queries 扩展)

方法签名如下:

namespace GatoGraphQL\InternalGraphQLServer;
 
use PoP\Root\HttpFoundation\Response;
 
class GraphQLServer {
  /**
   * Execute a GraphQL query
   */
  public static function executeQuery(
    string $query,
    array $variables = [],
    ?string $operationName = null,
    int|string|null $schemaConfigurationIDOrSlug = null,
  ): Response {
    // ...
  }
 
 
  /**
   * Execute a GraphQL query contained in a (`.gql`) file
   */
  public static function executeQueryInFile(
    string $file,
    array $variables = [],
    ?string $operationName = null,
    int|string|null $schemaConfigurationIDOrSlug = null,
  ): Response {
    // ...
  }
 
 
  /**
   * Execute a persisted GraphQL query (providing its object
   * of type WP_Post, ID as an int, or slug as a string)
   */
  public static function executePersistedQuery(
    WP_Post|string|int $persistedQuery,
    array $variables = [],
    ?string $operationName = null
  ): Response {
    // ...
  }
}

执行 GraphQL query 并获取响应内容:

use GatoGraphQL\InternalGraphQLServer\GraphQLServer;
 
// Provide the GraphQL query
$query = "{ ... }";
 
// Execute the query against the internal server
$response = GraphQLServer::executeQuery($query);
 
// Get the content and decode it
$responseContent = json_decode($response->getContent(), true);
 
// Access the data and errors from the response
$responseData = $responseContent["data"] ?? [];
$responseErrors = $responseContent["errors"] ?? [];

购买 All-Inclusive 套装

Personal
$79
/
“All-Inclusive” 套装
授权适用于 1 个域名
购买 ->
  • 1 个域名
  • 支持
  • 产品更新
Organization
$99
/
“All-Inclusive” 套装
授权适用于 3 个域名
购买 ->
  • 3 个域名
  • 支持
  • 产品更新
Professional
$199
/
“All-Inclusive” 套装
授权适用于 10 个域名
购买 ->
  • 10 个域名
  • 支持
  • 产品更新

授权有效期为 1 年(每年可续订)。价格以美元(USD)计。

需要更多域名?联系我们

30 天退款保证

购买任何扩展,均可申请退款保障

Features illustration
Money back guarantee

阅读我们的退款政策

Testimonial image

“这款插件真的是另一个层次!它能把你的网站提升到全新水平,变成一个强大的引擎。你越深入探索它的功能,就越会感到惊叹。如果你还在犹豫——赶紧入手吧,不然你以后会后悔的! 文档本身就说明了一切,扎实得不能再扎实。 Leo(开发者)是我遇到过的最敏锐、最全面的开发者之一。他的响应非常快,明显对自己的专业领域了如指掌。这款插件能做的事情之多,真的让我非常兴奋。可能性几乎无穷无尽,如果你重视 SEO,这款插件会让你的网站排名大幅提升。”

olmate - Web 开发者

订阅我们的新闻通讯

及时了解 Gato GraphQL 的所有更新。