lastdragon-ru/lara-asp-graphql-printer
最新稳定版本:9.3.1
Composer 安装命令:
composer require lastdragon-ru/lara-asp-graphql-printer
包简介
The Awesome Set of Packages for Laravel - The GraphQL Printer.
README 文档
README
Warning
Package is abandoned, please use lastdragon-ru/graphql-printer instead.
Independent (from Laravel and Lighthouse) package that allow you to print GraphQL Schema and Queries in highly customized way eg you can choose indent size, print only used/wanted/all types, print only one type, print used/wanted/all directives (it is not possible with standard printer) and even check which types/directives are used in the Schema/Query.
Requirements
| Requirement | Constraint | Supported by |
|---|---|---|
| PHP | ^8.4 | HEAD ⋯ 8.0.0 |
^8.3 | HEAD ⋯ 5.0.0 | |
^8.2 | 7.2.0 ⋯ 3.0.0 | |
^8.1 | 6.4.2 ⋯ 3.0.0 | |
^8.0 | 4.6.0 ⋯ 3.0.0 | |
webonyx/graphql-php | ^15.4.0 | HEAD ⋯ 4.2.1 |
^15.2.4 | 4.2.0 ⋯ 4.0.0 | |
^14.11.9 | 3.0.0 |
Installation
composer require lastdragon-ru/graphql-printer
Usage
There are two primary methods: Printer::print() and Printer::export(). The print() will print the current type only, meanwhile export() will print the current type and all used types/directives:
<?php declare(strict_types = 1); use GraphQL\Utils\BuildSchema; use LastDragon_ru\GraphQLPrinter\Printer; use LastDragon_ru\GraphQLPrinter\Settings\DefaultSettings; use LastDragon_ru\LaraASP\Dev\App\Example; $schema = BuildSchema::build( <<<'GRAPHQL' type Query { a: A } type A @a { id: ID! b: [B!] } type B @b { id: ID! } directive @a on OBJECT directive @b on OBJECT GRAPHQL, ); $type = $schema->getType('A'); $settings = new DefaultSettings(); $printer = new Printer($settings, null, $schema); assert($type !== null); Example::raw($printer->print($type), 'graphql'); Example::raw($printer->export($type), 'graphql');
The $printer->print($type) is:
type A @a { b: [B!] id: ID! }
The $printer->export($type) is:
type A @a { b: [B!] id: ID! } directive @a on | OBJECT directive @b on | OBJECT type B @b { id: ID! }
Customization
Please see:
Settingsdirectory to see built-in settings;Settingsinterface to see all supported settings;DirectiveResolverinterface to define your own way to find all available directives and their definitions;
Filtering
Note
By default, built-in/internal type/directives are not printed, if you want/need them, you should allow them by type/directive definitions filters.
The Printer allows filter out types and directives. This may be useful to exclude them from the schema completely. Filtering also works for queries. Please note that types filtering will work only if the schema is known (the schema is required to determine the type of argument nodes). For some AST node types, their type may also be required.
<?php declare(strict_types = 1); use GraphQL\Language\Parser; use GraphQL\Utils\BuildSchema; use LastDragon_ru\GraphQLPrinter\Contracts\DirectiveFilter; use LastDragon_ru\GraphQLPrinter\Contracts\TypeFilter; use LastDragon_ru\GraphQLPrinter\Printer; use LastDragon_ru\GraphQLPrinter\Settings\DefaultSettings; use LastDragon_ru\LaraASP\Dev\App\Example; $typeFilter = new class() implements TypeFilter { #[Override] public function isAllowedType(string $type, bool $isStandard): bool { return $type !== 'Forbidden'; } }; $directiveFilter = new class() implements DirectiveFilter { #[Override] public function isAllowedDirective(string $directive, bool $isStandard): bool { return $directive !== 'forbidden'; } }; $schema = BuildSchema::build( <<<'GRAPHQL' type Query { allowed: Boolean @forbidden @allowed forbidden: Forbidden } type Forbidden { id: ID! } directive @allowed on FIELD_DEFINITION directive @forbidden on FIELD_DEFINITION GRAPHQL, ); $query = Parser::parse( <<<'GRAPHQL' query { allowed forbidden { id } } GRAPHQL, ); $settings = (new DefaultSettings()) ->setDirectiveFilter($directiveFilter) ->setTypeFilter($typeFilter); $printer = new Printer($settings, null, $schema); Example::raw($printer->print($schema), 'graphql'); Example::raw($printer->print($query), 'graphql');
The $printer->print($schema) is:
directive @allowed on | FIELD_DEFINITION type Query { allowed: Boolean @allowed }
The $printer->print($query) is:
query { allowed }
Laravel/Lighthouse
It is highly recommended to use lastdragon-ru/lara-asp-graphql package to use the Printer within the Laravel/Lighthouse application.
Testing Assertions
There are also a few useful assertions for PHPUnit to check printed/exported type/queries, please see the lastdragon-ru/graphql-printer-testing package.
Upgrading
Please follow Upgrade Guide.
Migration from lastdragon-ru/lara-asp-graphql-printer
- Use
lastdragon-ru/graphql-printerinstead oflastdragon-ru/lara-asp-graphql-printerincomposer.json - Use
lastdragon-ru/graphql-printer-testingpackage if you use PHPUnit assertions. - Use
LastDragon_ru\GraphQLPrinter\*instead ofLastDragon_ru\LaraASP\GraphQLPrinter\*in code.
Contributing
This package is the part of Awesome Set of Packages for Laravel. Please use the main repository to report issues, send pull requests, or ask questions.
lastdragon-ru/lara-asp-graphql-printer 适用场景与选型建议
lastdragon-ru/lara-asp-graphql-printer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65.95k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「graphql」 「GraphQL Printer」 「GraphQL Schema Printer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lastdragon-ru/lara-asp-graphql-printer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lastdragon-ru/lara-asp-graphql-printer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lastdragon-ru/lara-asp-graphql-printer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHPUnit result printer, variant of the TestDoxCli Printer, that reduces the test failure message size for better readability
GraphQL authentication for your headless Craft CMS applications.
Authorize introspection documentarion for rebing/graphql-laravel
Sylius backend integration for Vue Storefront 2
GraphQL client and query builder.
Printing package for Nette framework
统计信息
- 总下载量: 65.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04