/schema-transformer

Transform SDL and enhance query execution of GraphQL schema

Primary LanguagePHPMIT LicenseMIT

Schema Transformer

unit tests codecov

Transform SDL and enhance execution query of GraphQL schema

describe

Getting Started

Install this package via Composer

composer require x-graphql/schema-transformer

Usages

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);

Credits

Created by Minh Vuong