kikoseijo / lumen-relay-boilerplate

[OUTDATED] A lumen boilerplate with Auth, GraphQL & Relay Modern, a ready to go API for your React, VueJS applications
http://kikoseijo.com/laravel-lumen-graphql-server-for-react-relay-moder/
MIT License
9 stars 0 forks source link

login mutation missing user info #2

Closed 4levels closed 6 years ago

4levels commented 6 years ago

Hi @kikoseijo,

Could you please verify if you manage to run the login mutation whilst returning the actual user in the response? I do get a token but the expected user element is always empty. I just tested this on a fresh install and I can't seem to get the user object filled in the mutation response..

I'm always getting user:null

grapqhl:

mutation loginUser {
  login (email: "some@example.org", password: "some.password") {
    token
    user {
      name
    }
  }
}

response:

{
  "data": {
    "login": {
      "token": "<token sting>",
      "user": null
    }
  }
}
4levels commented 6 years ago

Hi @kikoseijo,

I think I managed to get this working: in the Login Mutation I changed the resolve function as follows

          ...
          if ($user && app('hash')->check($args['password'], $user->password)) {
              $this->deleteExpiredTokens($user);
              $user['token'] = $user->createToken('Todo App')->accessToken;
+             app('auth')->setUser($user); // authenticate user with Auth
              return $user;
          }
          ...

and in the LoginPayload Type I added:

+    public function resolveUserField() {
+        return app('auth')->user();
+    }
kikoseijo commented 6 years ago

@4levels move to this package:

https://github.com/nuwave/lighthouse/issues/66

I have just finished integration and its amazing what you can do with a single schema.

4levels commented 6 years ago

Hi @kikoseijo,

very interesting read indeed. Glad Lighthouse is moving forward as it sounds very promising. Currently I've managed to get the whole GraphQL/Lumen/Relay part working except for Relay subscriptions so I'm currently developing the React Native counterpart.

To have a "kind of" subscription like feel, I went around the Relay subscriptions issue by implementing timers in React Native with createRefetchContainers I'll ask in the lighthouse tracker how the subscriptions are going to work since I'm very interested in this.

I'm already working with queueable jobs and message broadcasting by using Redis and a socket.io instance reading the Redis queue. Having this augmented with Relay subscriptions would be ideal!