Internal GraphQL Server
Выполняйте GraphQL queries непосредственно внутри вашего приложения, используя PHP-код.

Это расширение устанавливает внутренний GraphQL Server, который можно вызывать внутри вашего приложения с помощью PHP-кода.
Доступ к внутреннему GraphQL Server осуществляется через класс GatoGraphQL\InternalGraphQLServer\GraphQLServer посредством трёх методов:
executeQuery: Выполнить GraphQL queryexecuteQueryInFile: Выполнить GraphQL query, содержащийся в файле (.gql)executePersistedQuery: Выполнить persisted 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"] ?? [];