Skip to content
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

Add a @InjectUser annotation #131

Closed
moufmouf opened this issue Sep 20, 2019 · 6 comments
Closed

Add a @InjectUser annotation #131

moufmouf opened this issue Sep 20, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@moufmouf
Copy link
Member

moufmouf commented Sep 20, 2019

Idea: add a @InjectUser annotation that allows injecting the current user in any query / mutation / field.

/**
 * @InjectUser(for="$user")
 * @Query
 */
public function foo(User $user): string {
   // Do something with the user
}
@moufmouf moufmouf added the enhancement New feature or request label Sep 20, 2019
@fezfez
Copy link
Contributor

fezfez commented Oct 14, 2019

I think its a bad idea, its adding complexity for nothing, instead use DI.

class MyQuery
{
    private $session;
    public function __construct(Session $session)
    {
        $this->session = $session;
    }

    /** @Query */
    public function getUser(): string
    {
       return $this->session->getUser()->getName();
    }
}

If you go this way, the graphqlite is going to turn into DIC, i think it's not design in this way.

@XPOL555
Copy link

XPOL555 commented Oct 17, 2019

Hi @moufmouf, is this the last issue needed for v4? I'm really interested in this project since i want to bundle into my laravel 6 application. Is there any estimate on when the v4 will be available?

Thank you for your amazing work!

@gulien
Copy link
Contributor

gulien commented Oct 17, 2019

@XPOL555 don’t hesitate to use the « dev-master » version: it is really stable ;)

@moufmouf
Copy link
Member Author

@XPOL555 I cannot really give you an estimate for v4 release but it is definitely soon (probably in November).
You can start using the 4.x-dev version. There will not be any breaking changes before 4.0 is released.

I only plan to fix #103, implement this feature and add a way to add a GraphQL field directly on a magic property (that could be useful to ease the integration with Eloquent)

@XPOL555
Copy link

XPOL555 commented Oct 18, 2019

@moufmouf @gulien great! Thank you guys!

@moufmouf
Copy link
Member Author

@fezfez I still gave this a try (see #202).

I understand that you can clearly inject the "session" in your constructor and fetch the current user this way, but this is framework specific. And GraphQLite is framework agnostic.

I envision the possibility to create third party packages that would contain queries / mutations that could be used in any framework. Adding this InjectUser annotation allows me to access the current user, whatever the framework I'm using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants