I am preparing to develop a Laravel application that will use GraphQL to offer the API service. I am very new to GraphQL. I know GraphQL is a replacement to the REST API. I have been searching articles for how to use GraphQL properly with Laravel. One of the Article I found is using the GraphQL

This is the Register mutation.

class Register
    public function resolve($rootValue, array $args, $context)
        $params = [
            'email'    => $args['input']['email'],
            'name'     => $args['input']['name'],
            'password' => bcrypt($args['input']['password']),

        $user = User::where('email', $params['email'])->first();
        if($user) {
            throw new SafeGraphqlException("The email is already taken");

        $user = User::create($params);
        if (!$user) {
            throw new SafeGraphqlException("Not able to create a user");

        //other code

        if ($response->status() === 200) {
            $result = json_decode($response->getcontent(), true);
            $result['ok'] = true;

            return $result;

        } else {
            throw new SafeGraphqlException("Error when trying to log in");


In the above mutation, the thing I do not like is that it is not using laravel FormRequest to validate the input data. Also, I cannot use Laravel Policy classes for authorisation logic. So things are not done in the proper Laravel way. I feels like the code is messy. What I am asking for here is what would be the best proper way to use GraphQL with Laravel. I am also thinking is it a good idea to develop the traditional REST API in Laravel and then wrap the GraphQL on top of that. Is it possible to do that? If it is, is it a good idea? How should I use GraphQL with Laravel in a proper way? I looked for the tutorials on the Laracasts as well. I could not find one.

  • Wai Yan, did you find any solutions for this? – Kaz Jul 2 at 5:34

Your Answer


Browse other questions tagged or ask your own question.