infinityloop-dev/graphpinator-printer

GraPHPinator 类型系统的模式打印访问者。

v1.2.3 2023-11-10 13:05 UTC

This package is auto-updated.

Last update: 2024-09-10 15:03:42 UTC


README

⚡🌐⚡ GraPHPinator 类型系统的模式打印访问者。

简介

此库允许将 GraphQL 模式打印成人类可读的格式。它支持多种输出格式和排序选项。

安装

使用 composer 安装包

composer require infinityloop-dev/graphpinator-printer

如何使用

此库的使用非常简单。

$schema; // instance of \Graphpinator\Typesystem\Schema
$printer = new \Graphpinator\Printer\Printer();

echo $printer->printSchema($schema);

高级配置选项(见下文描述)

$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);

格式

可以实现针对各种输出格式的附加打印机制。这是通过实现 \Graphpinator\Printer\PrintComponentVisitor 并将其实例作为第一个构造函数参数传递给 Printer 来完成的。

此库提供的实现

  • TextVisitor(默认)- 标准机制,创建文本输出
  • HtmlVisitor - 创建结构化 HTML 代码的机制(在 theme 文件夹中捆绑了 SCSS,并在 build 文件夹中编译了 CSS)

隐式继承

两种格式化器都支持隐式继承 RFC - 排除从父接口继承的字段。要启用隐式继承,需要将不同的 FieldCollector 策略传递给 TextVisitorHtmlVisitor

此库提供的策略

  • AllFieldCollector(默认)- 打印所有字段的标准策略
  • ImplicitInheritanceFieldCollector - 利用隐式继承 RFC 的策略,排除与父接口相同的继承字段

类型排序顺序

可以更改输出中类型/指令的顺序。这是通过实现 \Graphpinator\Printer\Sorter 并将其实例作为第二个构造函数参数传递给 Printer 来完成的。

此库提供的实现

  • AlphabeticalSorter(默认)- 按字母顺序排序类型和指令
  • TypeKindSorter - 根据其 TypeKind(然后按字母顺序)排序类型 - 首先是接口,然后是对象类型,然后是联合类型,最后是指令