• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

mll-lab/laravel-graphql-playground: Easily integrate GraphQL Playground into you ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

mll-lab/laravel-graphql-playground

开源软件地址(OpenSource Url):

https://github.com/mll-lab/laravel-graphql-playground

开源编程语言(OpenSource Language):

PHP 84.2%

开源软件介绍(OpenSource Introduction):

Laravel GraphQL Playground

Easily integrate GraphQL Playground into your Laravel projects.

GitHub license Packagist Packagist

Please note: This is not a GraphQL Server implementation, only a UI for testing and exploring your schema. For the server component we recommend nuwave/lighthouse.

Installation

composer require mll-lab/laravel-graphql-playground

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

$app->register(MLL\GraphQLPlayground\GraphQLPlaygroundServiceProvider::class);

Configuration

By default, the playground is reachable at /graphql-playground and assumes a running GraphQL endpoint at /graphql.

To change the defaults, publish the configuration with the following command:

php artisan vendor:publish --tag=graphql-playground-config

You will find the configuration file at config/graphql-playground.php.

Lumen

If you are using Lumen, copy it into that location manually and load the configuration in your boostrap/app.php:

$app->configure('graphql-playground');

HTTPS behind proxy

If your application sits behind a proxy which resolves https, the generated URL for the endpoint will not be using https://, thus causing the Playground to not work by default. In order to solve this, add the following to the boot() method of a service provider:

if (! $this->app->isLocal()) {
    \Illuminate\Support\Facades\URL::forceScheme('https');
}

Customization

To customize the Playground even further, publish the view:

php artisan vendor:publish --tag=graphql-playground-view

You can use that for all kinds of customization.

Change settings of the playground instance

Add extra settings in the call to GraphQLPlayground.init in the published view:

GraphQLPlayground.init(document.getElementById('root'), {
  endpoint: "{{ url(config('graphql-playground.endpoint')) }}",
  subscriptionEndpoint: "{{ config('graphql-playground.subscriptionEndpoint') }}",
  // See https://github.com/graphql/graphql-playground#properties 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 Playground config:

GraphQLPlayground.init(document.getElementById('root'), {
  endpoint: "{{ url(config('graphql-playground.endpoint')) }}",
  subscriptionEndpoint: "{{ config('graphql-playground.subscriptionEndpoint') }}",
+ settings: {
+   'request.credentials': 'same-origin',
+ },
+ headers: {
+   'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
+ }
})

Make sure your route includes the web middleware group in config/graphql-playground.php:

    'route' => [
        'uri' => '/graphql-playground',
        'name' => 'graphql-playground',
+       'middleware' => ['web']
    ]

Local assets

If you want to serve the assets from your own server, you can download them with the command

php artisan graphql-playground: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 GraphQL playground in production, you can disable it in the config file. The easiest way is to set the environment variable GRAPHQL_PLAYGROUND_ENABLED=false.

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
notiz-dev/nestjs-prisma-starter: Starter template for NestJS 发布时间:2022-06-22
下一篇:
joshblack/build-a-graphql-server发布时间:2022-06-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap