rahuljayaraman/doctrine-graphql 问题修复 & 功能扩展

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

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

rahuljayaraman/doctrine-graphql

Composer 安装命令:

composer require rahuljayaraman/doctrine-graphql

包简介

Use Doctrine entities as GraphQL types

README 文档

README

WARNING: This repo is just an experiment & is not maintained. Please use at your own risk. Suggest using https://github.com/Ecodev/graphql-doctrine instead

Doctrine GraphQL Mapper

Builds GraphQL types out of doctrine entities

Installation

$> curl -sS https://getcomposer.org/installer | php
$> php composer.phar require rahuljayaraman/doctrine-graphql

Requirements

PHP >=5.4

Overview

The mapper builds GraphQL types out of doctrine entities. It's built on top of webonyx/graphql-php and maps doctrine entities to an ObjectType graph at runtime.

Here's an example. Consider the following schema

Employee
│
└───Company (getCompanies)
|
└───User (getUser)

We can extract the type for Employee by using

Mapper::extractType(Employee::class)

Associations are recursively extracted as well. So $employee->getCompanies() would return ListOf Type Company & $employee->getUser() would return Type User

NOTE: This library is not responsible for any of your GraphQL setup like setting up routes, root nodes etc.

TODO

Usage

Setup

Setup accepts 3 args. Doctrine's EntityManager, a setter method & a getter method to a type store (a data structure which stores types).

//Setup code, I use this in a laravel service provider
use RahulJayaraman\DoctrineGraphQL\Mapper;
use Doctrine\ORM\EntityManager;

Mapper::setup(
    app(EntityManager::class),
    function ($typeName, $type) {
        Cache::add($type, $typeName);
    },
    function ($typeName) {
        return Cache::get($typeName);
    }
);

Cache above could be replaced by any store. Eg. using Folkloreatelier/laravel-graphql's store

use Folklore\GraphQL\Support\Facades\GraphQL;

Mapper::setup(
    app(EntityManager::class),
    function ($typeName, $type) {
        GraphQL::addType($type, $typeName);
    },
    function ($typeName) {
        return GraphQL::type($typeName);
    }
);

Extract type

To extract the type

Mapper::extractType(Entity::class);

We could place it here if using with Folkloreatelier/laravel-graphql.

public function type()
{
   return Mapper::extractType(Entity::class);
}

Default resolver

For now, given a field name, say fieldName, the mapper will look for a getFieldName getter method on the entity. There are plans to allow customization here.

Register additional fields

For registering additional fields, one can use the RegisterField annotation.

RegisterField accepts name, type and args.

name accepts a string.

type accepts either an internal type or any of the extracted entities.

args accepts an array of tuples in the form of {{string, type}}

Here's an example

use RahulJayaraman\DoctrineGraphQL\Annotations\RegisterField;


/**
 * getEmployee
 *
 * @RegisterField(name="CustomName" type="Employee", args={{"slug", "string"}})
 */
public function getEmployee($slug)
{
    return ...
}

Blacklist fields

Fields can be blacklisted using the BlacklistField annotation. Here's an example.

use RahulJayaraman\DoctrineGraphQL\Annotations\BlacklistField;

/**
 * @var string
 * @ORM\Column(type="string")
 * @BlacklistField()
 */
private $password;

Complementary Tools

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-04-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固