Skip to content

BaffourAdu/laravel-graphql-blog-api-server

Repository files navigation

Laravel GraphQL API Server

This is the repository for the tutorial on How to build a GraphQL Server using Laravel.

Follow the series here => https://baffouraduboampong.me/how-to-build-a-graphql-server-using-laravel-part-1/

Installation

Note: Make sure you have composer installed or you may downlaod composer at => https://getcomposer.org/download/

  1. git clone
  2. Open the console and cd into your project root directory
  3. Create your database
  4. Rename .env.example file to .env inside your project root
  5. Update .env with your database information.
  6. Run composer install or php composer.phar install
  7. Run php artisan key:generate
  8. Run php artisan migrate
  9. Run php artisan db:seed to run seeders (Incase of an error run => composer dump-autoload)
  10. Run php artisan serve

Project Url: http://localhost:8000

GraphQL Endpoint: http://localhost:8000/graphql

GraphQL Playground: http://localhost:8000/graphql-playground

Example Queries

query {
  users(first:10, page:6) {
    paginatorInfo {
      total
      currentPage
      hasMorePages
      lastPage
      perPage
    }
    data {
      id
      name
      email
    }
  }
  user(id:10){
    id
    email
    name
    articles {
      id
      title
      content
    }
  }
  article(id: 6) {
    id
    title
    content
    user {
      id
      name
      email
    }
  }
  articles(first:10, page:1) {
    paginatorInfo {
      total
      currentPage
      hasMorePages
      lastPage
      perPage
    }
    data {
      id
    	title
    	content
    } 
  }
}

Note: In the query below you need to add request headers such as

{
  "Authorization": "Bearer CKDL3XFeulMBEdXDtqNG1uEs69tBvCoPSkQZhfJSVKAE0AhHt5bkxKmLGtA8"
}
query {
  me {
    email
    name
    articles {
      id
      title
    }
  }
}

Example Mutations

mutation {
    createUser(
        name:"Alexis Osei"
        email:"alexis.osei@example.com"
        password: "secret"
    ) {
        id
        name
        email
    }

    login(
        email:"me@mygraphqlapp.com" 
        password:"secret"
    )
}

About

A micro blog GraphQL API Server built using Laravel. You may follow the tutorial series here => https://baffouraduboampong.me/how-to-build-a-graphql-server-using-laravel-part-1/

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published