GraphQL is a popular open-source method for manipulating API’s. Graphs provide a natural way to map relationships and hierarchies in data, and “QL” stands for Query Language.
Here is an example of a simple GraphQL Query:
In this particular script I am specifying that I want to get a list of all cars, and specifically each car’s make, model, year, and color.
Below is an example of a simple GraphQL Mutation. Mutations refer to modifications in the data that return values, such as inserts, updates, and deletes.
In this mutation query, I am adding a new car to my existing list of cars.
Query with HTTP GET
In some situations, it may be useful to list data from an API over HTTP GET. See an example of the original GraphQL Query above in HTTP:
Mutation with HTTP POST
HTTP POSTS are not available through a direct URL query, since URL’s don’t allow the POST method. However, tools such as Postman or shell scripts allow for testing a cURL POST. In the code below is a demonstration of a basic cURL script executing the GraphQL mutation above:
Hopefully this has been helpful! I had a situation where I needed to access graphQL via HTTP, and I was able to piece together some information I had on GraphQL, shell scripts, and HTTP. This puts the knowledge all in one place.