cordero-digital/gql-query-loader
最新稳定版本:v1.3.0
Composer 安装命令:
composer require cordero-digital/gql-query-loader
包简介
A PHP library that adds native .gql and .graphql file type support.
README 文档
README
A simple library that adds support for .gql and .graphql files in your PHP application.
Features
- Load GraphQL queries from
.graphqland.gqlfiles. - Supports variable replacement within queries.
- Includes fragment files via
#include "fragment.graphql"syntax. - Prevents duplicate fragment loading.
Requirements
- PHP >=8.1
Installation
Install with composer
$ composer require cordero-digital/gql-query-loader
Install without composer
- Download the latest release
- Extract the
.zipor.tar.gzto your machine - Copy
/src/Loader.phpfile into your project - Include the
Loader.phpfile into the PHP file you need the library into
require_once __DIR__ . '/src/Loader.php'; use CorderoDigital\GQLQueryLoader\Loader; $loader = new Loader;
Usage
This package supports fragments. The package assumes the fragments are located in a sub directory called /fragments located next to the query.
Variable replacement
This package supports passing PHP values into Graphql files by doing string replacement. This allows you to hardcode your PHP variables into the compiled Graphql query. A couple things to note:
You pass the variables in to the loadQuery() method where the key is the variable name in the Graphql file. Ex:
// Your PHP file $query = (new Loader)->loadQuery($this->root . 'queries/variableNotInArrayExceptionTest.gql', ['id' => 123])->query();
# Your graphql file query { user{{ id }} { id name } }
# result query { user(id: 123) { id name } }
If you want multiple hard coded variables on a single object you would do:
// your PHP file $query = (new Loader)->loadQuery($this->root . 'queries/variableNotInArrayExceptionTest.gql', ['id' => 123, 'status' => 'active'])->query();
# Your graphql file query { user{{ id, status }} { id name } }
# result query { user(id: 123, status: "active") { id name } }
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-07