Transform SDL and enhance execution query of GraphQL schema
Install this package via Composer
composer require x-graphql/schema-transformer
use GraphQL\GraphQL;
use GraphQL\Utils\SchemaPrinter;
use XGraphQL\HttpSchema\HttpDelegator;
use XGraphQL\HttpSchema\HttpSchemaFactory;
use XGraphQL\SchemaTransformer\AST\PrefixRootFieldsNameTransformer;
use XGraphQL\SchemaTransformer\SchemaTransformer;
$delegator = new HttpDelegator('https://countries.trevorblades.com/');
$schema = HttpSchemaFactory::createFromIntrospectionQuery($delegator);
$transformedSchema = SchemaTransformer::transform(
$schema,
[
new PrefixRootFieldsNameTransformer('XGraphQL_'),
],
);
$query = <<<'GQL'
query getCountries {
XGraphQL_countries {
name
}
}
GQL;
var_dump(SchemaPrinter::doPrint($transformedSchema));
$result = GraphQL::executeQuery($transformedSchema, $query);
var_dump($result->data);
Created by Minh Vuong