PHP code example of infinityloop-dev / graphpinator-constraint-directives

1. Go to this page and download the library: Download infinityloop-dev/graphpinator-constraint-directives library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

infinityloop-dev / graphpinator-constraint-directives example snippets


$intConstraint; // instance of \Graphpinator\ConstraintDirectives\IntConstraintDirective

\Graphpinator\Typesystem\Argument\Argument::create(
    'year'
    \Graphpinator\Typesystem\Container::Int(),
)->addDirective(
    $intConstraint,
    ['min' => 1900, 'max' => 2021],
);

$intConstraint; // instance of \Graphpinator\ConstraintDirectives\IntConstraintDirective

\Graphpinator\Typesystem\Field\Field::create(
    'year'
    \Graphpinator\Typesystem\Container::Int(),
)->addDirective(
    $intConstraint,
    ['min' => 1900, 'max' => 2021],
);

class DogOrCatInput extends \Graphpinator\Typesystem\InputType
{
    protected const NAME = 'DogOrCatInput';

    public funtion __construct(
        \Graphpinator\ConstraintDirectives\ObjectConstraintDirective $objectConstraint,
    )
    {
        parent::__construct();
        $this->addDirective($objectConstraint, ['exactlyOne' => ['dog', 'cat']]);
    }

    protected function getFieldDefinition() : \Graphpinator\Typesystem\Argument\ArgumentSet
    {
        return new \Graphpinator\Typesystem\Argument\ArgumentSet([
            \Graphpinator\Typesystem\Argument\Argument::create('dog', \Graphpinator\Typesystem\Container::String()),
            \Graphpinator\Typesystem\Argument\Argument::create('cat', \Graphpinator\Typesystem\Container::String()),
        ]);
    }
}