/graphQL-Laravel

The graphQL with Laravel

Primary LanguagePHPMIT LicenseMIT

Introduction

Welcome to this straightforward project designed to demonstrate the practical use of GraphQL with Laravel. This project serves as a basic blog system featuring posts and categories.

Understanding GraphQL

GraphQL is a query language for APIs and an execution engine for fulfilling these queries using your existing data. It offers a comprehensive and intuitive way to describe the data available in your API, granting clients the ability to request exactly what they need, without any excess information. GraphQL simplifies the process of evolving APIs over time and provides powerful tools for developers.

Here's a concise comparison between GraphQL and REST:

REST:

  • REST is an architectural style.
  • REST is a protocol.
  • REST is a collection of guidelines, rules, constraints, principles, and rules.

GraphQL:

  • GraphQL is a query language, not an architectural style or protocol.

Objectives

The primary goals of this project are:

  • To understand how to leverage GraphQL with Laravel.
  • To become proficient in using the graphql-laravel package for GraphQL in Laravel.

Technologies used

This project utilizes the following technologies:

  • Laravel v10.28
  • PHP v8.2
  • MySQL v8.0
  • Docker v24.0.6

Packages used

To achieve its functionality, this project incorporates several packages, including:

How to run

To execute this project, follow these steps:

  1. Clone the repository to your local machine.
  2. Generate a .env file by executing the following command:
cp .env.example .env
  1. Install the project dependencies using Docker and Composer:
docker run --rm \
  -u "$(id -u):$(id -g)" \
  -v "$(pwd):/var/www/html" \
  -w /var/www/html \
  laravelsail/php82-composer:latest \
  composer install --ignore-platform-reqs
  1. Initiate the containers with the following command:
./vendor/bin/sail up -d
  1. Generate an application key with:
./vendor/bin/sail artisan key:generate
  1. Execute the database migrations:
./vendor/bin/sail artisan migrate
  1. Populate the database with initial data:
./vendor/bin/sail artisan db:seed
  1. Create a symbolic link for storage:
./vendor/bin/sail artisan storage:link

How to use

Once the project is operational, follow these steps to make the most of it:

  • Launch Postman or your preferred API testing tool.
  • Create a new GraphQL request.
  • Set the URL to http://your-domain/graphql (replace your-domain with your actual domain or local URL).

Suggestions and Feedback

I value your input and welcome any suggestions or feedback you may have regarding this project. If you encounter any issues, have ideas for improvements, or wish to share your experience, please don't hesitate to reach out. Your feedback will help me enhance and refine this project further. For a comprehensive tutorial on building a GraphQL API using Laravel, you can refer to the article on FreeCodeCamp. Thank you for your collaboration!