Skip to content

Transform SDL and enhance query execution of GraphQL schema

License

Notifications You must be signed in to change notification settings

x-graphql/schema-transformer

Repository files navigation

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

About

Transform SDL and enhance query execution of GraphQL schema

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages