---
title: Learn more on GraphQL
layour: layout.html
---

# GraphQL

In order to interact with the API, you need to write a small program that uses GraphQL.

**GraphQL** provides a way to describe the data you want to access. In order to use it, consider the following:

- in GraphQL, the information is organized as a graph of objects (an object can be Product, or Review, or QualitativeAnalys, etc.)
- each object is composed by a set of fields (e.g. Product is composed by productName, averageRating, etc.)
- GraphQL allows two type of operations on the data:

  - query: to fetch data (e.g. "give me all the reviews from 'webshop X' of 'product Y' )
  - mutations: to change data and fetch directly the changed data (e.g. "mark my user account as logged in and give me information about my user account")

- fething data with GraphQL means describing which part of the graph of objects you want to access

## Resources

- a practical example on how to use GraphQL can be found in the [tutorial](/tutorial/get-api=-keys.html)
- for schema information, check out the [reference docs](/graphql-schema-docs/index.html)


## Example of GraphQL query

Consider the following graph:

<img src="/images/example-graphql-diagram.png" style="width:80%; padding:25px;" />

In GraphQL, the query will look like:

```
query query($token: String!) {
  query(token: $token) {
    error
    user {
      products(where: { name: { _eq: "prodottoWOW" } }) {
        name
        quantitativeAnalysis{
          ratingDistribution {
            _1
            _2
            _3
            _4
            _5
          }
        }
        qualitativeAnalysis(where: { channels: { _eq: "channel.io" } }) {
          prosConsData {
            annotation
            positive
            negative
            negativePercentage
            positivePercentage
            neutralPercentage
          }
        }
        reviews(where: { channels: { _eq: "channel.io" } }) {
          author
          rating
          annotations {
            category
            sentiment
          }
        }
      }
    }
  }
}
```





