定制 radic/graphql_streams_api-module 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

radic/graphql_streams_api-module

Composer 安装命令:

composer require radic/graphql_streams_api-module

包简介

Effortlessly bind your PyroCMS Streams to the GraphQL API service. A great alternative to the non-free pro api-module addon.

README 文档

README

Introduction

This module aims to provide an easy yet flexiable way to bind your PyroCMS Streams to a GraphQL API. This module integrates nuwave/lighthouse with PyroCMS Streams.

Please make sure you have a basic understanding of:

Preview

A small usage preview of this module.

1. Configure the bindings

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. Generate the schema.graphql

When you have defined all stream bindings and resolutions to your liking then you need to run the generator. This will generate a GraphQL schema definition file that will be used by Lighthouse:

php artisan api:generate

3. And voila!

GraphQL Query and Result

Documentation

Installation

Add to composer

composer require radic/graphql_streams_api-module

Install addon

php artisan addon:install radic.module.graphql_streams_api

Publish the addon

To customize and define your GraphQL service use the api:publish command.

This will publish the configuration and schema files to resources/{application}/addons/radic/graphql_streams_api.

php artisan api:publish

Customization

You can customize/define the GraphQL service in resources/{application}/addons/radic/graphql_streams_api:

  • config/config.php
  • schema/queryable.graphqls
  • schema/core.graphqls

config.schema

  • output : The path where the schema will be generated.
  • imports : Paths to other schema definition files that will be included in the generated schema output.

config.stream_bindings

This defines the streams that you want to be generated as GraphQL types.

'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'
        ]
    ]
]

The resolutions are used to define the streams fields that should be in the GraphQL type. You can either:

  • Define only stream field name (like 'slugs'). The generator will use the default_field_bindings to resolve the GraphQL type automatically.
  • Define the stream field name and a custom GraphQL field type. This is usually done with relationship fields or if you want to add some directive(s) to the field.

Generate

After modifying the config.php or any of the defined schema.imports files you need to generate the output schema by running

php artisan api:generate

This will generate the schema in the configured schema.output file path.

License

Copyright 2018 - Robin Radic - MIT License

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固