maxa-ondrej/nette-graphql

Nette 框架 GraphQLite 集成扩展

1.2.2 2023-03-26 20:24 UTC

This package is auto-updated.

Last update: 2024-09-26 23:25:58 UTC


README

Downloads Build Status Coverage Status Latest Stable Version

用法

composer require maxa-ondrej/nette-graphql

Nette 框架用法

config.neon

extensions:
    graphql: Maxa\Ondrej\Nette\GraphQL\DI\GraphQLExtension

MyPresenter.php

<?php declare(strict_types=1);

namespace App\Presenters;

use TheCodingMachine\GraphQLite\Annotations\Query;

/**
 * Class MyPresenter
 *
 * @package App\Presenters
 */
final class MyPresenter {

    /**
     * GraphQL request example:
     * {
     *   echo(name: "World")
     * }
     * outputs -> "Hello World" 
     */
    #[Query]
    public function echo(string $name): string {
        return 'Hello '. $name;    
    }
    
}

想要修改 Schema Factory 实例吗?

使用已预定义的类属性

  • #[Authentication] -> 类必须实现 TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface
  • #[Authorization] -> 类必须实现 TheCodingMachine\GraphQLite\Security\AuthorizationServiceInterface
  • #[Middleware(Middleware::FIELD)] -> 类必须实现 TheCodingMachine\GraphQLite\Middlewares\FieldMiddlewareInterface
  • #[Middleware(Middleware::PARAMETER)] -> 类必须实现 TheCodingMachine\GraphQLite\Middlewares\ParameterMiddlewareInterface

或者使用 Maxa\Ondrej\Nette\GraphQL\DI\SchemaFactoryDecoratorService 的自定义实现,并添加类属性 #[FactoryDecorator]

GraphQLite 文档