silverstripe/graphql-devtools
Composer 安装命令:
composer require silverstripe/graphql-devtools
包简介
Tools to help developers building new applications on SilverStripe's GraphQL API
README 文档
README
Tools to help developers building new applications on SilverStripe’s GraphQL API
Installation
composer require --dev silverstripe/graphql-devtools
What it does
This module adds an implementation of graphiql, an in-browser IDE for GraphQL servers. It provides browseable documentation of your schema, as well as autocomplete and syntax-checking of your queries.
Accessing the IDE
It can be accessed at /dev/graphql/ide.
This is because GraphQL 4+ has its own DevelopmentAdmin controller.
The GraphQL v4 version of the module allows you to clear your schema by running sake graphql:clear.
Security
By default, the tool has the same restrictions as other development tools like /dev/build:
- In "dev" mode, it's available without authentication
- In "test" and "live" mode, it requires ADMIN permissions
- It's installed with
composer require --devby default. In most deployment contexts that'll mean it's not available on environments in "test" or "live" modes
Configuration
In most installations of SilverStripe, there are at least two GraphQL servers running - one
for the admin (admin/graphql) and one for the user space (/graphql). By default, only
the default schema will show, but this is configurable.
Showing multiple schemas
Important: Due to a limitation in the GraphQL Playground library, showing multiple schemas will disable the persistence of IDE state across page refreshes.
Also important: When changing the available schemas, be sure to clear the local storage in your browser, otherwise, you'll get inconsistent state.
You can configure the visible schemas in the controller.
Show a select list of schemas
SilverStripe\GraphQLDevTools\Controller: # show two schemas schemas: - default - admin # default schema that is selected default_schema: admin
Show all schemas
SilverStripe\GraphQLDevTools\Controller: # show two schemas schemas: '*' default_schema: default
Further, you can override the config in the request, by using ?schema=<schemaName>,
e.g. http://example.com/dev/graphql/ide?schema=mySchema.
If you're using a custom controller for your GraphQL endpoint
The IDE finds schemas by checking Director for routes that map to a SilverStripe\GraphQL\Controller instance.
If for some reason you're using a custom controller, you might get an error: "Could not find your default schema 'default'. You will need to add one to the SilverStripe\Control\Director.rules config setting."
To avoid this, you can explicitly map your graphql route to a schema in your Director config:
SilverStripe\Control\Director: rules: graphql: Controller: '%$MyCustomController' Schema: default
GraphQL schema initialise task
This module provides a GraphQLSchemaInitTask task to initialise a basic GraphQL schema to get you started. It will create configuration files for your schema and a basic resolver. Specifically it will create:
app/_config/graphql.ymlapp/_graphqlcontaining several yml filessrc/GraphQL/Resolvers.php
You must be in CLI mode to use this task
To view help for the task to see what options are available:
vendor/bin/sake tasks:GraphQLSchemaInitTask --help
To run the task with with minimal options:
vendor/bin/sake tasks:GraphQLSchemaInitTask --namespace=App
Upgrading and maintaining the IDE
The library running the IDE is GraphQL Playground. It is served from your local environment as an exposed resource. The setup is based on their "HTML Page" example seen here, which uses remote bundle files served from a CDN. This repository uses a manually created bundle file copied directly from the CDN. This may seem like a convoluted approach, but the main benefits are:
- It allows offline use
- It does not require setting up a build chain or installing NPM dependencies
- There is no need for SRI protection
To upgrade GraphQL Playground, refer to the example linked above and use their
CDN to download the latest distribution and drop it into this repository. Be sure
to update the comment at the top of the bundle.js file to track the URL it was
downloaded from.
silverstripe/graphql-devtools 适用场景与选型建议
silverstripe/graphql-devtools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 415.59k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2017 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 silverstripe/graphql-devtools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silverstripe/graphql-devtools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 415.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 16
- 依赖项目数: 6
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-01-12
