Skip to content

Pipes - missing documentation + bug #33

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

Closed
lorado opened this issue Oct 7, 2018 · 3 comments
Closed

Pipes - missing documentation + bug #33

lorado opened this issue Oct 7, 2018 · 3 comments

Comments

@lorado
Copy link
Contributor

lorado commented Oct 7, 2018

It would be nice, if using of pipes in definition would be documented. I also asked you, if it is possible to use pipes for authentication or other type of permission check is possible. You replied with "no", but actually it is possible. By the way, HTTP Middlewares in laravel, like auth middleware, works just the same.

I thing I got the idea of pipes, it is really nice! I also noticed, that it is generally possible to define pipe in following format: Class\Name\Of\Pipe:argument,another argument. So pipline can parse this string format, and get the class of pipe for creating it from container, and passes to the handle() method some addition parameters, in the example above: argument and another argument as 4th and 5th argument. It works well with pipeline code, but you also use pipes for gql fields generation... and this part of code dont accept this string format. May we fix it? As I would like to add a pipe for checking user role.

I'll do a merge request, so you can see what I mean... When we merge fix-bug, I can also write a small doc for pipe usage

@cmizzi
Copy link
Contributor

cmizzi commented Oct 18, 2018

Hum, I don't really understand. pipeline is used in order to build queries and mutations of each definition (and also, check ACL, etc.). You can provide arguments into each pipe using the Class:arg1,arg2 format to manage different cases within the pipe. You can also inherit each pipe with Argumentable interface in order to return new arguments fields into the query/mutation.

If you want adding a pipe to check user role, you can simply create a generic pipe using the following syntax :

class CheckContextRole {
    public function handle($builder, \Closure $next, array $args, string $role) {
        if ($args['context']->role !== $role) {
             throw new \Exception('You\'re not allowed');
        }

        return $next($builder);
    }
}

and register it like

	/**
	 * {@inheritDoc}
	 *
	 * @return array
	 */
	public function getPipes(): array {
		return array_merge_recursive(parent::getPipes(), [
                        // 'store' => \App\GraphQL\Pipe\CheckContextRole::class . ':admin']
			'all' => [\App\GraphQL\Pipe\CheckContextRole::class . ':admin']
		]);
	}

@lorado
Copy link
Contributor Author

lorado commented Oct 18, 2018

Yes, I currently do it already like you described =)

I figured it out while I was looking at your code and I understood it, but it would be nice, if it would be documented, so other people can unterstand and use it easy.

Also there is a bug. Have you looked at my PR? in src/Support/Transformer/Transformer.php there is a code, that creates pipe class and calls getArguments() method. But if I define some arguments on pipe, this line crashes, because it tries to create something like Path/To/Pipe/Class:some,arguments and sure it is not a valid class name. That is why I added there an explode(), to fetch actually the class name of pipe.

@cmizzi
Copy link
Contributor

cmizzi commented Oct 18, 2018

Oh ! I'll document pipeline soon. I've didn't really understood why the PR but it makes sense. I'll merge it when the README will explain pipeline.

Thanks!

@cmizzi cmizzi closed this as completed Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants