Internal GraphQL Server
PHP kodu kullanarak GraphQL queries'lerini doğrudan uygulamanız içinde çalıştırın.

Bu uzantı, PHP kodu kullanarak uygulamanız içinden çağrılabilen dahili bir GraphQL Server kurar.
Dahili GraphQL server'a GatoGraphQL\InternalGraphQLServer\GraphQLServer sınıfı aracılığıyla, şu üç yöntemle erişilir:
executeQuery: Bir GraphQL query çalıştırırexecuteQueryInFile: Bir (.gql) dosyasında bulunan GraphQL query'yi çalıştırırexecutePersistedQuery: Kalıcı bir GraphQL query çalıştırır (ID'sini tam sayı olarak veya slug'ını dize olarak sağlayarak) (Persisted Queries uzantısı gereklidir)
Yöntem imzaları şunlardır:
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 {
// ...
}
}Bir GraphQL query çalıştırmak ve yanıt içeriğini elde etmek için:
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"] ?? [];