rozbehsharahi / netgen-headless-bundle
Symfony Bundle 用于使 Netgen Layouts 头部无界面
dev-main
2021-03-06 23:28 UTC
Requires
- php: >=7.4.0
- ext-json: *
- netgen/layouts-standard: ^1.2
- overblog/graphql-bundle: ^0.13.4
Requires (Dev)
- doctrine/orm: ^2.8
- overblog/graphiql-bundle: ^0.2.1
- phpunit/phpunit: ^9.5
- symfony/browser-kit: ^5.2
- symfony/console: ^5.2
- symfony/dotenv: ^5.2
- symfony/twig-bundle: ^5.2
- twig/extra-bundle: ^3.3
This package is auto-updated.
Last update: 2024-09-07 07:12:10 UTC
README
安装
Symfony flex 应该会自动进行配置。因此,步骤 2 和 3 通常不需要。
1 安装
$ composer require rozbehsharahi/netgen-headless-bundle
// This package has no release yet, so you will need to install like following in fact:
$ composer require rozbehsharahi/netgen-headless-bundle:dev-main
如果 symfony flex 缺少某些内容,请检查以下步骤
2 激活组件
// add to bundles.php
Overblog\GraphQLBundle\OverblogGraphQLBundle::class => ['all' => true],
Rs\NetgenHeadlessBundle\NetgenHeadlessBundle::class => ['all' => true],
3 添加 GraphQL 路由
overblog_graphql_endpoint:
resource: "@OverblogGraphQLBundle/Resources/config/routing/graphql.yml"
prefix: '' // add here a prefix for graphql in case you don't want graphql to register on `/`
尝试使用
// Please replace https:// with your host in case it is not localhost
curl -X POST -H "Content-Type: application/json" -d '{ "query": "{ sayHello }" }' https:///graphql/netgen
注意:该组件服务一个独立的模式。因此,请务必将模式 netgen
添加到您的 graphql 端点。
https:///graphql/netgen
GraphIQL 的安装用于调试和文档
GraphIQL 是发现此组件提供功能的不错方式。Symfony Flex 应该会自动配置您的应用程序。因此,步骤 2 和 3 通常不需要。
1 安装包
composer require --dev overblog/graphiql-bundle
2 激活组件
// config/bundles.php
Overblog\GraphiQLBundle\OverblogGraphiQLBundle::class => ['dev' => true],
3 添加路由
// config/routes/dev/graphiql.yaml
overblog_graphiql:
resource: "@OverblogGraphiQLBundle/Resources/config/routing.xml"
4 尝试使用
现在您可以浏览到 https:///graphiql/netgen
。
注意:请务必将模式 /netgen
添加到您的 graphiql 路由。
使用方法
此软件包提供了一个 graphql 端点,根据配置,可以通过 http://your-domain.com/graphql/netgen
等方式访问。
示例查询
{
layout(search: { request: { uri: "/hello-world" } }) {
id # receive id
json # receive json of whole layout
zones {
identifier # receive identifier
json # receive json of zone
}
}
}
运行测试和应用程序
这是一个包含在 Tests/Application
中的测试应用程序的自包含组件。
我是在我的个人 docker-compose 基础存储库 https://github.com/RozbehSharahi/doka
上开发的。您也可以使用这个,或者使用您自己的设置。
// In root dir call:
git clone https://github.com/RozbehSharahi/doka.git
// Create an empty .doka.env as described on https://github.com/RozbehSharahi/doka and add:
DOKA_APP_APACHE_DOCUMENT_ROOT=/var/www/html/Tests/Application/public/
// Start docker env
doka/compose up -d
// Enter docker-container and run tests
doka/enter-app
vendor/bin/phpunit
// If you don't want to have db created all over again, you can create a file (git ignored) on root directory called `fast-tests`
touch fast-tests
访问测试应用程序
# enter cli
doka/enter-app
# run once, whenever you call this you will have a clean and empty db again.
Tests/Application/setup-test-application
# Now go to
App: https://:8080
Netgen Layouts: https://:8080/nglayouts/admin (User: root, Password: root)
Graphql: https://:8080/graphql/netgen
Graphiql: https://:8080/graphiql/netgen