GraphQL is a query language for your API. It simplifies the process of requesting the server by providing convenient ways to query objects.

For instance, if you’re using a REST API and you need a list of books, you might hit the GET /books/list endpoint for all books. Then if you need a specific book by ID, you would hit GET /book?id={id}, which means you’ll be making multiple requests to the server.

But GraphQL does something called declarative data fetching, where you can ask for what you want and get a predictable result in a single request.

Awesome right? Let’s see how it all works.

What we will be learning?

In this article, you’ll learn the basics of GraphQL by using the Laravel GraphQL package to build a server that does the following:

  1. Register users
  2. Fetch all users
  3. Get a user by ID
  4. Fetch all posts
  5. Fetch all posts with user relationships
  6. Finally, as a bonus, you’ll also learn how to use the super awesome Postman tool to run your query and get a real-time response

Prerequisites

Here are a few things you’ll need for this tutorial:

  1. A local server (XAMPP or WAMP)
  2. A code editor (Sublime TextVS Code, or Atom)
  3. A version control system (Git)
  4. A dependency Manager (Composer)
  5. The Laravel GraphQL package

#graphql #laravel #postman

How to Build a GraphQL Server with Laravel GraphQL and Test It with Postman
1 Likes33.85 GEEK