⚡🌐⚡ Schema printing visitor for GraPHPinator typesystem.
This library allows printing of the GraphQL schema into human-readable format. It supports multiple output formats and ordering options.
Install package using composer
composer require infinityloop-dev/graphpinator-printer
Usage of this library is very simple.
$schema; // instance of \Graphpinator\Typesystem\Schema
$printer = new \Graphpinator\Printer\Printer();
echo $printer->printSchema($schema);Advanced configiration options (see description below)
$schema; // instance of \Graphpinator\Typesystem\Schema
$printer = new \Graphpinator\Printer\Printer(
new \Graphpinator\Printer\HtmlVisitor( // different format
new \Graphpinator\Printer\ImplicitInheritanceFieldCollector(), // enable implicit inheritance
),
new \Graphpinator\Printer\TypeKindSorter(), // different sorter
);
echo $printer->printSchema($schema);It is possible to implement additional printing mechanisms for various output formats.
This is done by implementing \Graphpinator\Printer\PrintComponentVisitor and passing an instance to Printer as first constructor argument.
TextVisitor(default) - standard mechanism which creates text outputHtmlVisitor- mechanism which creates structured HTML code (there is also a SCSS bundled in thethemefolder and compiled CSS inbuildfolder)
Both formatters support Implicit inheritance RFC - option to exclude fields inherited from parent interface.
In order to enable implicit inheritance, it is needed to pass different FieldCollector strategy to TextVisitor or HtmlVisitor.
AllFieldCollector(default) - standard strategy to print all fieldsImplicitInheritanceFieldCollector- strategy to leverage Implicit inheritance RFC, inherited fields which remained the same are excluded
It is possible to change the order of types/directives in output.
This is done by implementing \Graphpinator\Printer\Sorter and passing an instance to Printer as second constructor argument.
AlphabeticalSorter(default) - sorts types and directives alphabeticallyTypeKindSorter- sorts types by their TypeKind (and then alphabetically) - interfaces first, then object types, then unions, ..., directives last