Skip to content

Uses pipeline #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 10, 2018
Merged

Uses pipeline #24

merged 11 commits into from
Sep 10, 2018

Conversation

cmizzi
Copy link
Contributor

@cmizzi cmizzi commented Jul 3, 2018

The main goal here is to use pipeline instead of modifying transformers :

class UserDefinition extends Definition {
    /**
     * getTransformers
     *
     * @return void
     */
    public function getTransformers() {
        return [
            'list' => [
                StudioNet\GraphQL\Pipe\Eloquent\ListPipe::class,
                App\GraphQL\Pipe\User\RolePipe::class
            ],
            // ...
        ];
    }
}

// ...

use Illuminate\Database\Eloquent\Builder;
use Closure;

class RolePipe {
    /**
     * handle
     *
     * @param  Builder $builder
     * @param  Closure $next
     * @param  array $infos
     * @return mixed
     */
    public function handle(Builder $builder, Closure $next, array $infos) {
        // Call $builder method to update SQL query
        //
	// $infos = [
	// 	'root'
	// 	'args'
	// 	'fields'
	// 	'context'
	// 	'info'
	// 	'with'
	// 	'source'
	// 	'rules'
	// 	'filterables'
	// 	'definition'
	// ]

        return $next($builder);

        // All lines here can modify the collection returned by the next method
    }
}

This branch will not remove transformers at all, only the underlying code : it will only calls the pipeline and returns the result. To manage custom transformers, a configuration will be set to manage each new transformer (like #22).

@cmizzi cmizzi self-assigned this Jul 3, 2018
@cmizzi cmizzi requested a review from kadmelia July 3, 2018 13:18
@lorado
Copy link
Contributor

lorado commented Aug 6, 2018

Hi! Are there any updates? When do you think you can make next release?

@cmizzi
Copy link
Contributor Author

cmizzi commented Aug 6, 2018

The code seems to work, but I need to make some additional tests to be sure all cases are managed. I need more time :)

@lorado
Copy link
Contributor

lorado commented Aug 18, 2018

Is it possible to use something like AuthMiddleware with this pipeline idea? E.g. I want that some Transformer are only accessible, when user is logged in. Or is there any other option to achieve this?

In graphql-library from rebing there was an option to add middlewares to whole schemas, so it is possible to define an "open" and "protected" schemas.

@cmizzi
Copy link
Contributor Author

cmizzi commented Aug 20, 2018

You cannot use AuthMiddleware directly, but you can create your own and check if the user is logged (with context). But, it could be great to add global middleware per schema :)

@cmizzi cmizzi merged commit c87eb06 into master Sep 10, 2018
This was referenced Sep 10, 2018
@cmizzi cmizzi deleted the f-pipes branch September 10, 2018 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants