karolinasena / service-course

https://lab.github.com/vtex-trainings/vtex-io-service-course
1 stars 0 forks source link

GraphQL: Using GraphiQL #8

Closed github-learning-lab[bot] closed 3 years ago

github-learning-lab[bot] commented 3 years ago

GraphQL: Using GraphiQL

Introduction

Now, with the query and resolver implemented, we need to use it to retrieve the top n most viewed products. By using the GraphQL IDE, we can test the query we implemented before.

GraphiQL

GraphiQL is a graphical interactive in-browser GraphQL IDE. Before using the query in the app, it is interesting to test its functionality. To do so, we will reproduce your query usage in the GraphQL IDE.

Exploring the IDE interface, there are three main areas: the coding area, the query variables area and the debug area. Check where each shows up in the interface in the image below.

image

Activity

  1. Open the GraphiQL route and type the code below in the coding area:

    query ($topN: Int) {
     productList(topN: $topN){
       slug
       count
     }
    }
  2. The query that we just declared uses a variable (topN). Now we need to declare it in the Query Variables area:

    {
     "topN": 2
    }

    :exclamation: The Query Variables area is below the coding area, to amplify it's area just drag by the title.

  3. At last, just click on the play button and check the outcome on the debug area. The query results should look like this:

    image

github-learning-lab[bot] commented 3 years ago

Congratulations!

You have successfully completed this course!