x-graphql/schema-transformer

Transforming types, fields of GraphQL schema

0.4.1 2024-04-04 04:34 UTC

This package is auto-updated.

Last update: 2024-11-04 05:47:46 UTC


README

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