DEV Community

Shannon W
Shannon W

Posted on • Edited on

Setting Up a GraphQL API With Strapi

Original post from series "Building an App with Gatsby and Strapi"

Who is this post for? Each post in the series is loosely dependent on each other. So you can follow any post in any order you like. Posts were made this way so you don’t have to read all the previous ones to follow along.

The goal of this post is to explore Strapi’s GraphQL API in regards to:

  • setting up the API,
  • setting up API permissions,
  • documenting and testing API endpoints.

Setting Up

To begin, you will need to install the GraphQL plugin from the Marketplace.

Alt Text

Once installation is finished, restart Strapi.

Setting Up API Permissions

Similar to setting up the REST API, we will need to define who has permission and to what actions. For example, let’s look at the Page content type and give the Public role permission to call count, find, and findone actions (actions are simply the functions used by the controller to perform business logic).

Step 1 – Ensure the content type is defined as needed

Alt Text

Step 2 – Go to Roles & Permissions and select the Public role

Alt Text

Step 3 – Give permission to use the actions

Alt Text

Documenting and Testing the API

Strapi automatically provides a GraphQL playground at /graphql. So if you are running Strapi locally, it can be found at http://localhost:1337/graphql, otherwise, it’ll be located at http://<website-domain>/graphql. From here you can explore the available schemas, type details, arguments, and test queries using the editor.

Alt Text

Top comments (2)

Collapse
 
avxkim profile image
Alexander Kim

You just described a documentation..

Collapse
 
yoloadr profile image
Yohann Loïc Ravino

Wasting time