morphql/morphql-symfony
Composer 安装命令:
composer require morphql/morphql-symfony
包简介
Symfony integration for MorphQL — YAML config, autowiring, and .morphql file convention
README 文档
README
Symfony integration for MorphQL — transform data with declarative queries.
YAML configuration · Autowiring · Twig-style file convention · PHP 8.1+
Installation
composer require morphql/morphql-symfony
With Symfony Flex (Currently waiting for submission to symfony/recipes-contrib), this will automatically:
- Registers
MorphQLBundleinbundles.php - Creates
config/packages/morphql.yamlwith sensible defaults - Scaffolds the
morphql-queries/directory at your project root
Without Flex, you could have to register the bundle manually in
config/bundles.php(depends on your Symfony version):MorphQL\SymfonyBundle\MorphQLBundle::class => ['all' => true],
The bundle is fully zero-config. All settings have sensible defaults — no YAML file is needed to get started. Just install, drop a .morphql file in morphql-queries/, and you're ready to go.
Configuration (optional)
To customize behavior, create or edit config/packages/morphql.yaml:
morphql: # Execution provider: "cli" (bundled Node.js engine) or "server" (remote REST API) # provider: cli # Directory containing .morphql query files # query_dir: '%kernel.project_dir%/morphql-queries' # Server provider settings (uncomment if using provider: server) # server_url: '%env(MORPHQL_SERVER_URL)%' # api_key: '%env(MORPHQL_API_KEY)%'
All options have sensible defaults — zero-config works out of the box.
Full Configuration Reference
| Option | Default | Description |
|---|---|---|
provider |
cli |
cli (bundled Node.js) or server (remote REST API) |
cli_path |
(auto) | Override CLI binary path |
node_path |
node |
Path to Node.js binary |
cache_dir |
%kernel.cache_dir%/morphql |
Compiled query cache |
query_dir |
%kernel.project_dir%/morphql-queries |
.morphql file directory |
server_url |
http://localhost:3000 |
MorphQL server URL |
api_key |
— | API key for server auth |
timeout |
30 |
Execution timeout (seconds) |
Usage
1. The morphql-queries/ directory
Like Twig templates in templates/, you can store your MorphQL queries in morphql-queries/. Use the .morphql extension for syntax highlighting in supported IDEs.
morphql-queries/
├── invoices/
│ └── to_xml.morphql # Identifier: 'invoices/to_xml'
└── api_response.morphql # Identifier: 'api_response'
2. Using the Transformation Registry
Inject the TransformationRegistry to run queries stored in files:
use MorphQL\SymfonyBundle\TransformationRegistry; class InvoiceService { public function __construct( private readonly TransformationRegistry $registry ) {} public function process(array $data): string { // Resolves to morphql-queries/invoices/to_xml.morphql return $this->registry->transform('invoices/to_xml', $data); } }
3. Direct MorphQL usage
For ad-hoc queries, you can inject the base MorphQL service:
use MorphQL\MorphQL; class MyController { public function __construct( private readonly MorphQL $morphql ) {} public function index(string $json): string { return $this->morphql->run('from json to json transform set x = 1', $json); } }
Features
- Symfony Flex Recipe: Automatic bundle registration, config scaffolding, and query directory creation.
- Filesystem Discovery: Use standard paths like
'sub/folder/query'— no dot-notation required. - Pre-configured: The
MorphQLservice is automatically configured from your YAML settings. - Isomorphic: Switch between
cliandserverproviders via config without changing your code.
Symfony Flex Recipe
The recipe files are staged in the recipe/ directory and need to be submitted to symfony/recipes-contrib for Flex to pick them up automatically.
To submit the recipe:
- Fork symfony/recipes-contrib
- Create
morphql/morphql-symfony/0.1/in the fork - Copy the contents of
recipe/into that directory - Open a Pull Request following the recipe contribution guide
Until the recipe is accepted, users can manually:
- Create
config/packages/morphql.yaml(copy fromrecipe/config/packages/morphql.yaml) - Create the
morphql-queries/directory at their project root
Troubleshooting
"node" not found
If you use a version manager like NVM, asdf, or Volta, the node binary might not be in the default PATH used by your web server or PHP process.
Solution 1: Set the path in .env
MORPHQL_NODE_PATH=/usr/local/bin/node # Use 'which node' to find yours
Solution 2: Create a system symlink
sudo ln -s $(which node) /usr/local/bin/node
Prerequisites
- PHP 8.1+
- Node.js 18+ (for the
cliprovider) - Symfony 5.4+, 6.x, 7.x, or 8.x
License
MIT
morphql/morphql-symfony 适用场景与选型建议
morphql/morphql-symfony 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「transform」 「data-transformation」 「morphql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 morphql/morphql-symfony 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 morphql/morphql-symfony 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 morphql/morphql-symfony 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Behat package to transform human readable labels into selectors or page paths.
Transform data structures
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
Transform Craft Element and field data structures
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 44
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-12