cordero-digital/gql-query-loader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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 .graphql and .gql files.
  • 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

  1. Download the latest release
  2. Extract the .zip or .tar.gz to your machine
  3. Copy /src/Loader.php file into your project
  4. Include the Loader.php file 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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-07