定制 mll-lab/laravel-graphiql 二次开发

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

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

mll-lab/laravel-graphiql

Composer 安装命令:

composer require mll-lab/laravel-graphiql

包简介

Easily integrate GraphiQL into your Laravel project

README 文档

README

A thin wrapper for serving the GraphiQL UI from Laravel

GitHub license Packagist Packagist

Screenshot of GraphiQL with Doc Explorer Open

Please note: This is a UI for testing and exploring your schema and does not include a GraphQL server implementation. To serve a GraphQL API from Laravel, we recommend nuwave/lighthouse.

Installation

Install the package via composer:

composer require mll-lab/laravel-graphiql

Due to Laravel package discovery, this package will automatically register and is then ready to use without configuration.

If you are using Lumen, register the service provider in bootstrap/app.php

$app->register(MLL\GraphiQL\GraphiQLServiceProvider::class);

Upgrade Guide

When upgrading between major versions, consider UPGRADE.md.

Configuration

By default, the GraphiQL UI is reachable at /graphiql and assumes a running GraphQL endpoint at /graphql. To change those defaults, publish the configuration with the following command:

php artisan vendor:publish --tag=graphiql-config

You will find the configuration file at config/graphiql.php.

Lumen

If you are using Lumen, copy src/graphiql.php to config/graphiql.php manually. Then load the configuration in your boostrap/app.php:

$app->configure('graphiql');

HTTPS behind proxy

If your application sits behind a proxy which resolves https, the generated URL for the endpoint might not use https://. This may cause the GraphiQL UI to not work by default. To solve this, configure your TrustProxies middleware to contain \Symfony\Component\HttpFoundation\Request::HEADER_X_FORWARDED_FOR in $headers.

Customization

To customize the GraphiQL UI even further, publish the view:

php artisan vendor:publish --tag=graphiql-view

You can use that for all kinds of customization.

Change settings of the GraphiQL UI instance

Add extra props in the call to React.createElement(GraphiQL, ...) in the published view.

React.createElement(GraphiQL, {
  ...,
  // See https://github.com/graphql/graphiql/tree/main/packages/graphiql#props for available settings
});

Configure session authentication

Session-based authentication can be used with Laravel Sanctum. If you use GraphQL through sessions and CSRF, add the following to the <head> in the published view:

+<meta name="csrf-token" content="{{ csrf_token() }}">

Modify the GraphiQL props as follows:

React.createElement(GraphiQL, {
    ...,
+   defaultHeaders: JSON.stringify({
+       'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
+   }),
})

Make sure your route includes the web middleware group in config/graphiql.php:

    'routes' => [
        '/graphiql' => [
            'name' => 'graphiql',
+           'middleware' => ['web']
        ],
    ],

Local assets

To serve the assets from your own server, download them with:

php artisan graphiql:download-assets

This puts the necessary CSS, JS and Favicon into your public directory. If you have the assets downloaded, they will be used instead of the online version from the CDN.

Security

If you do not want to enable the GraphiQL UI in production, you can disable it in the config file. The easiest way is to set the environment variable GRAPHIQL_ENABLED=false.

If you want to protect the route to the GraphiQL UI, you can add custom middleware in the config file.

mll-lab/laravel-graphiql 适用场景与选型建议

mll-lab/laravel-graphiql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.71M 次下载、GitHub Stars 达 63, 最近一次更新时间为 2022 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「graphql」 「graphiql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mll-lab/laravel-graphiql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mll-lab/laravel-graphiql 我们能提供哪些服务?
定制开发 / 二次开发

基于 mll-lab/laravel-graphiql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.71M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 63
  • 点击次数: 23
  • 依赖项目数: 10
  • 推荐数: 4

GitHub 信息

  • Stars: 63
  • Watchers: 2
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-26