Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 1.43 KB

README.md

File metadata and controls

60 lines (43 loc) · 1.43 KB

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