radic / graphql_streams_api-module
轻松地将PyroCMS Streams绑定到GraphQL API服务。这是非免费专业API模块插件的一个很好的替代品。
0.3.0
2018-10-12 19:02 UTC
Requires
- deinternetjongens/lighthouse-utils: ~0.2
- nuwave/lighthouse: dev-master#a0ba2e80dd59adaafd55cdb4b8e60b874e232139 as ~2.2
This package is not auto-updated.
Last update: 2024-09-14 08:30:37 UTC
README
简介
本模块旨在提供一个简单且灵活的方法,将您的PyroCMS Streams绑定到GraphQL API。此模块将nuwave/lighthouse
与PyroCMS Streams集成。
请确保您对以下有基本了解:
预览
本模块的小型使用预览。
1. 配置绑定
config.php
return [ // other config options redacted, check out the documentation for a full overview 'default_field_resolutions' => [ 'anomaly.field_type.addon' => 'String', 'anomaly.field_type.blocks' => 'String', 'anomaly.field_type.boolean' => 'Boolean', 'anomaly.field_type.checkboxes' => 'Boolean', 'anomaly.field_type.colorpicker' => 'String', //etc... ], 'stream_bindings' => [ // namespace::slug 'users::users' => [ // generator results: type User {} 'type_name' => 'User', // PyroCMS Stream field assignment => GraphQL field type 'resolutions' => [ // custom type resolutions 'id' => 'ID', 'roles' => '[UserRole!] @hasMany', 'created_at' => 'Date', 'updated_at' => 'Date', 'deleted_at' => 'Date', // The fields below will be resolved using the `default_field_resolutions` // If you want, you can assign a custom type resolutions like above 'username', 'display_name', 'first_name', // protect fields by requiring authentication and permissions 'email' => 'String @role(roles: ["admin"], operator: "AND")', 'email' => 'String @role(roles: ["user", "guest"], operator: "NOT")', 'email' => 'String @role(roles: ["admin", "user"], operator: "OR")', 'last_name', 'activated', 'enabled', ], ], // other streams... ] ];
2. 生成schema.graphql
当您已经定义了所有流绑定和解决方案后,您需要运行生成器。这将生成一个GraphQL模式定义文件,该文件将被Lighthouse使用。
php artisan api:generate
3. 然后,大功告成!
文档
安装
添加到composer
composer require radic/graphql_streams_api-module
安装插件
php artisan addon:install radic.module.graphql_streams_api
发布插件
要自定义和定义您的GraphQL服务,请使用api:publish
命令。
这将发布配置和模式文件到resources/{application}/addons/radic/graphql_streams_api
。
php artisan api:publish
自定义
您可以在resources/{application}/addons/radic/graphql_streams_api
中自定义/定义GraphQL服务
config/config.php
schema/queryable.graphqls
schema/core.graphqls
config/schema
output
: 模式将生成的路径。imports
: 包含在生成的模式输出中的其他模式定义文件的路径。
config/stream_bindings
这定义了您希望生成的GraphQL类型的流。
'stream_bindings' => [ // '{namespace}::{slug}' 'users::users' => [ 'type_name' => 'User', // The resulting GraphQL schema type name. 'resolutions' => [ 'slug', 'title', 'roles' => '[UserRole!] @hasMany', ] ], 'users::roles' => [ 'type_name' => 'UserRole', 'resolutions' => [ 'slug' ] ] ]
resolutions
用于定义应包含在GraphQL类型中的流字段。您可以
- 仅定义流字段名称(如'slugs')。生成器将使用
default_field_bindings
自动解析GraphQL类型。 - 定义流字段名称和自定义GraphQL字段类型。这通常用于关系字段或您想向字段添加某些指令时。
生成
在修改config.php
或任何定义的schema.imports
文件后,您需要运行
php artisan api:generate
这将生成在配置的schema.output
文件路径中的模式。
许可
版权所有 2018 - Robin Radic - MIT许可证