for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*******************************************************************************
* This file is part of the GraphQL Bundle package.
*
* (c) YnloUltratech <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
******************************************************************************/
namespace Ynlo\GraphQLBundle\Schema;
use GraphQL\GraphQL;
use GraphQL\Utils\SchemaPrinter;
class SchemaExporter
{
/**
* @var SchemaCompiler
*/
protected $compiler;
private const INTROSPECTION_QUERY = <<<GraphQL
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
fragment FullType on __Type {
kind
fields(includeDeprecated: true) {
type {
...TypeRef
isDeprecated
deprecationReason
inputFields {
interfaces {
enumValues(includeDeprecated: true) {
possibleTypes {
fragment InputValue on __InputValue {
type { ...TypeRef }
defaultValue
fragment TypeRef on __Type {
ofType {
GraphQL;
* @param SchemaCompiler $compiler
public function __construct(SchemaCompiler $compiler)
$this->compiler = $compiler;
* @param string $endpoint
* @param bool $json
* @return string
public function export(string $endpoint, bool $json = false): string
$schema = $this->compiler->compile($endpoint);
if ($json) {
$result = GraphQL::executeQuery($schema, self::INTROSPECTION_QUERY);
return json_encode($result->toArray(), JSON_PRETTY_PRINT);
return SchemaPrinter::doPrint($schema);