API - slaymance/client-service GitHub Wiki

Table of Contents

  1. GraphQL API

GraphQL API

How GraphQL returns data

This service handles HTTP requests via GraphQL endpoints. GraphQL allows the querying of the user database and will return only requested information for all users. For example, take a look at the following cURL command:

curl -X POST -H 'Content-Type:application/graphql' -d '{users {favoriteGenres,age,location {name}}}' 'localhost:3000/graphql'

The command will return a JSON object, with "users" being an array with the favorite genres, age, and location for each user in the database. For example, the command would return the following if the users table looked like the example above:

{
  "data": {
    "users": [
      {
        "favoriteGenres": [
          1,
          67,
          21,
          2
        ],
        "age": 25,
        "location": {
          "name": "New York City"
        }
      },
    ]
  }
}

With the server running, you may also point your browser to localhost:3000/graphql. This brings up the Graphiql interface, which allows you to make exact queries to the graphql endpoint without using cURL commands or Postman.