Skip to content

manuelgeek/laravel-graphql

Repository files navigation

badge StyleCI

About Laravel GraphQL

This is a sample Laravel Project to illustrate API creation using GraphQL using grapgql-laravel package

Set up

Fork and Clone the project then;

composer install

cp .env.example .env

php artisan key:generate

php artisan migrate 

php artisan serve

Features

  • Register
  • Login
  • Update Avatar
  • CRUD
  • Pagination

Sample Urls

1. Create user

Request

http://localhost:8000/graphql/auth

mutation {
    signUp(
    name: "tester"
    email:"123@test.com"
    password:"123"
  ) {
    id,
    email,
    name,
    api_token
  }
}

Response

{
    "data": {
        "signUp": {
            "id": 1,
            "email": "123@test.com",
            "name": "tester",
            "api_token": "09SBifku0BCSNS7VBFNqQg0goDYqCX43tL4pNtl7lJPmVOJOjDdjD42mnmuOLBybwW7DHZmrnVTey0p8nH4EWGGa7oRKErnZMm9c"
        }
    }
}

2. Login

http://localhost:8000/graphql/auth

Request

mutation {
    logIn(
    email:"123@test.com"
    password:"123"
  ) {
    id,
    email,
    name,
    api_token
  }
}

Response

{
    "data": {
        "logIn": {
            "id": 1,
            "email": "123@test.com",
            "name": "tester",
            "api_token": "09SBifku0BCSNS7VBFNqQg0goDYqCX43tL4pNtl7lJPmVOJOjDdjD42mnmuOLBybwW7DHZmrnVTey0p8nH4EWGGa7oRKErnZMm9c"
        }
    }
}

3. Get Bits

http://localhost:8000/graphql

Request

 mutation {
      newBit (snippet: "<?php ehco phpinfo(); ?>") {
        id
        user {
          id
          name
        }
        snippet
        created_at
        updated_at
      }
    }

Response

{
    "data": {
        "newBit": {
            "id": 2,
            "user": {
                "id": 1,
                "name": "tester"
            },
            "snippet": "<?php ehco phpinfo(); ?>",
            "created_at": "2020-04-16 18:27:07",
            "updated_at": "2020-04-16 18:27:07"
        }
    }
}

4. Update Avatar

http://localhost:8000/graphql

Request

mutation($file: Upload!) 
{ UpdateUserProfilePhoto(profilePicture: $file)
    {
     id,
     name,
     avatar,
     email,
     api_token
    } 
}

Resources

The sample project is created from serries of lessons from;

  1. Auth0 Blog

  2. Pusher Blog

About Me

Magak

License

The Laravel framework is open-sourced software licensed under the MIT license.

license

Open Source Love

Happy coding, Star then Fork 😊💪💯

About

A laravel graphQL API application sample

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published