marvinrabe/laravel-graphql-test
Composer 安装命令:
composer require --dev marvinrabe/laravel-graphql-test
包简介
Provides you with a simple GraphQL testing trait.
README 文档
README
Elegant GraphQL testing utilities for Laravel. Works with any GraphQL library. Especially with Lighthouse.
Installation
You can install the package via composer:
composer require --dev marvinrabe/laravel-graphql-test
And then add the trait to your TestCase class:
<?php namespace Tests; abstract class TestCase extends BaseTestCase { use MarvinRabe\LaravelGraphQLTest\TestGraphQL; // ... }
When your GraphQL endpoint is not /graphql you have to specify it manually:
public $graphQLEndpoint = 'graphql';
Usage
Queries
You can write queries like this:
$this->query('account', ['id' => 123], ['id']);
Note that this function returns an \Illuminate\Foundation\Testing\TestResponse. Therefore you might use any Laravel testing methods. For example:
$this->query('account', ['id' => 123], ['id']) ->assertSuccessful() ->assertJsonFragment([ 'id' => 123 ]);
With nested resources:
$this->query('account', ['id' => 123], ['transactions' => ['id']]);
Without a third argument it will be assumed that the second one is the selection set:
$this->query('accounts', ['id']);
When you only pass the object name, you get the GraphQLClient instead of the Laravel TestResponse:
$this->query('accounts')->getGql();
Mutations
Same as queries:
$this->mutation('accounts')->getGql(); $this->mutation('accounts', ['id']); $this->mutation('accounts', ['id' => 123]);
Argument Order
For simplicity you can find the correct argument order in the following table:
| Method | Arguments | Returns |
|---|---|---|
| query | (object) | GraphQLClient |
| query | (object, selectionSet) | TestResponse |
| query | (object, arguments, selectionSet) | TestResponse |
| mutation | (object) | GraphQLClient |
| mutation | (object, selectionSet) | TestResponse |
| mutation | (object, arguments, selectionSet) | TestResponse |
Enums
Because PHP has no built in Enum support. You have to use the provided enum helper:
$this->query('accounts', ['status' => $this->enum('closed')], ['id']);
Or create a EnumType manually:
$this->query('accounts', ['status' => new \MarvinRabe\LaravelGraphQLTest\Scalars\EnumType('closed')], ['id']);
Headers
You can add additional HTTP headers by using withHeader or withHeaders methods provided by Laravel. For example:
$this->withHeaders(["Authorization" => "Bearer TOKEN"])->query('accounts', ['id']);
If you always provide the same headers, you could define them on your TestCase.
class AccountsTest extends TestCase { protected $defaultHeaders = [ "Authorization" => "Bearer TOKEN", ]; // ... }
Limitations
The QueryBuilder provided by this library is not safe for use in production code. It is designed for ease of use and does not comply to the GraphQL specifications fully. Use it only for testing purposes! You have been warned.
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
marvinrabe/laravel-graphql-test 适用场景与选型建议
marvinrabe/laravel-graphql-test 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 377.19k 次下载、GitHub Stars 达 57, 最近一次更新时间为 2019 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「testing」 「laravel」 「graphql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marvinrabe/laravel-graphql-test 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marvinrabe/laravel-graphql-test 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marvinrabe/laravel-graphql-test 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
The PHP SDK for Checkmango
Alfabank REST API integration
The testing extension of TYPO3voilà.
Auto-generate dummy data with realistic relationships per Model-like config classes
Dusk extensions for testing
统计信息
- 总下载量: 377.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 57
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-24