Connections

Creating a Connection

To create a connection, you can use Lighthouse's make connection command

$ php artisan lighthouse:connection TaskConnection

Connection Class

namespace App\Http\GraphQL\Connections;

use GraphQL\Type\Definition\ResolveInfo;
use Nuwave\Lighthouse\Support\Interfaces\Connection;

class TaskConnection implements Connection
{

    /**
     * Get the name of the connection.
     * Note: Connection names must be unique
     *
     * @return string
     */
    public function name()
    {
        return 'TaskConnection';
    }

    /**
     * Get name of connection.
     *
     * @return string
     */
    public function type()
    {
        return 'task';
    }

    /**
     * Available connection arguments.
     *
     * @return array
     */
    public function args()
    {
        return [
            'completed' => [
                'type' => Type::nonNull(Type::boolean()),
                'rules' => ['required'],
            ]
        ];
    }

    /**
     * Resolve connection.
     *
     * @param  mixed  $parent
     * @param  array  $args
     * @param  mixed  $context
     * @param  ResolveInfo $info
     * @return mixed
     */
    public function resolve($parent, array $args, $context, ResolveInfo $info)
    {
        return $parent->tasks()
            ->where('completed', $args['completed'])
            ->toConnection($args);
    }
}

results matching ""

    No results matching ""