maxa-ondrej/nette-graphql

Nette Framework GraphQLite Integration Extension

1.2.2 2023-03-26 20:24 UTC

This package is auto-updated.

Last update: 2024-10-26 23:40:09 UTC


README

Downloads Build Status Coverage Status Latest Stable Version

Usage

composer require maxa-ondrej/nette-graphql

Nette Framework Usage

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;    
    }
    
}

Want to modify the Schema Factory instance?

Use the already predefined class attributes:

  • #[Authentication] -> class must implement TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface
  • #[Authorization] -> class must implement TheCodingMachine\GraphQLite\Security\AuthorizationServiceInterface
  • #[Middleware(Middleware::FIELD)] -> class must implement TheCodingMachine\GraphQLite\Middlewares\FieldMiddlewareInterface
  • #[Middleware(Middleware::PARAMETER)] -> class must implement TheCodingMachine\GraphQLite\Middlewares\ParameterMiddlewareInterface

Or use a custom implementation of Maxa\Ondrej\Nette\GraphQL\DI\SchemaFactoryDecoratorService and add class attribute #[FactoryDecorator].

GraphQLite documentation