tina4stack/tina4php-graphql 问题修复 & 功能扩展

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

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

tina4stack/tina4php-graphql

最新稳定版本:v2.0.1

Composer 安装命令:

composer require tina4stack/tina4php-graphql

包简介

Lightweight GraphQL engine for Tina4 PHP — recursive descent parser, executor, auto-schema from ORM

README 文档

README

Lightweight GraphQL engine for the Tina4 PHP framework. Built from scratch with no external dependencies — recursive descent parser, depth-first executor, and auto-schema generation from ORM objects.

Tests

Installing

composer require tina4stack/tina4php-graphql

Requirements

  • PHP >= 8.1

Usage

Simple Queries

$schema = new \Tina4\GraphQLSchema();

$schema->addQuery('hello', [
    'type' => 'String',
    'resolve' => fn() => 'Hello World!',
]);

$schema->addQuery('user', [
    'type' => 'User',
    'args' => ['id' => ['type' => 'ID']],
    'resolve' => fn($root, $args) => ['id' => $args['id'], 'name' => 'Andre'],
]);

$graphql = new \Tina4\GraphQL($schema);
$result = $graphql->execute('{ hello user(id: 1) { name } }');
// $result = ['data' => ['hello' => 'Hello World!', 'user' => ['name' => 'Andre']]]

Auto-Schema from ORM

The killer feature — register ORM classes and get full CRUD automatically:

$schema = new \Tina4\GraphQLSchema();
$schema->fromORM(Customer::class);
$schema->fromORM(Order::class);

// Generates automatically:
// Queries:  customer(id), customers(limit, offset)
// Mutations: createCustomer(input), updateCustomer(id, input), deleteCustomer(id)

Tina4 Route Integration

$schema = new \Tina4\GraphQLSchema();
$schema->fromORM(Customer::class);
\Tina4\GraphQLRoute::register($schema);

// POST /graphql with JSON body:
// { "query": "{ customers(limit: 10) { id name email } }" }

Mutations

$schema->addMutation('createUser', [
    'type' => 'User',
    'args' => ['name' => ['type' => 'String!'], 'email' => ['type' => 'String!']],
    'resolve' => function ($root, $args) {
        $user = new User();
        $user->name = $args['name'];
        $user->email = $args['email'];
        $user->save();
        return ['id' => $user->id, 'name' => $user->name, 'email' => $user->email];
    },
]);

Variables

query GetUser($id: ID!) {
    user(id: $id) {
        name
        email
    }
}
$result = $graphql->execute($query, ['id' => 42]);

Fragments

fragment UserFields on User {
    id
    name
    email
}

{
    users {
        ...UserFields
    }
}

HTTP Handler

$graphql = new \Tina4\GraphQL($schema);
$jsonResponse = $graphql->handleRequest(file_get_contents('php://input'));

Architecture

Class Purpose
GraphQL Main entry — parse, execute, return result
GraphQLParser Recursive descent parser — query string to AST
GraphQLExecutor Walks AST, calls resolvers, builds response
GraphQLSchema Type definitions, query/mutation registry
GraphQLType Type system — scalars, objects, lists, non-null
GraphQLRoute Register /graphql POST endpoint in Tina4

Supported Features

  • Queries and mutations
  • Nested field resolution
  • Arguments (string, int, float, boolean, enum)
  • Variable definitions and resolution
  • Fragment definitions and spreads
  • Aliases
  • Comments
  • List types
  • Error collection (non-halting)
  • Auto-schema from Tina4 ORM

Running Tests

composer test

Our Sponsors

Sponsored with 🩵 by Code Infinity

Code Infinity

Supporting open source communities Innovate Code Empower

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固