Giter Site home page Giter Site logo

raywire / lighthouse-tutorial Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.33 MB

A blog API built using Lighthouse for GraphQL and Laravel

Home Page: https://lighthouse-tutorial.herokuapp.com/

PHP 96.69% Vue 0.53% HTML 2.78%
php laravel graphql backend heroku lighthouse lighthouse-tutorial

lighthouse-tutorial's Introduction

Title

Lighthouse Tutorial

Description

A basic starter pack for a GraphQL API using Lighthouse and Laravel

Running the API

It's very simple to get the API up and running. First, create the database (and database user if necessary) and add them to the .env file.

DB_DATABASE=your_db_name
DB_USERNAME=your_db_user
DB_PASSWORD=your_password

Then install, migrate, seed, and run the server:

composer install
php artisan migrate
php artisan serve

Testing Environment

Visit http://127.0.0.1:8000/graphql-playground on your browser to test the API

Alternatively you can use Postman or Insomnia

Use this url: http://localhost:8000/graphql

Heroku Link

Heroku

Seeding the database

First run

php artisan tinker

Then on the shell that opens up run

factory('App\User',10)->create();
factory('App\Post',50)->create();
factory('App\Comment',50)->create();

or simply

composer seed

Queries and Mutations

Fetch a user

{
  user(id: 1) {
    id
    name
    email
  }
}

Fetch all users with pagination

{
  users(count:10) {
    paginatorInfo {
      total
      hasMorePages
      currentPage
      lastPage
      perPage
      firstItem
      lastItem
      count
    }
    data {
      id
      name
      email
    }
  }
}

Fetch a post

{
  post(id: 1) {
    id
    title
    content
    user {
      id
      name
    }
    comments {
      id
      reply
    }
  }
}

Fetch posts

{
  posts {
    id
    title
    user {
      id
      name
    }
    comments {
      id
      reply
    }
  }
}

Create a user

mutation {
  createUser(
    name: "Ryan Wire"
    email: "[email protected]"
    password: "1234567"
  ){
    id,
    name
  }
}

Login a user

mutation {
    login(data: {
        username: "[email protected]",
        password: "password"
    }) {
        access_token
    }
}

lighthouse-tutorial's People

Contributors

raywire avatar

Stargazers

January Thomas avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.