⚠️ This lesson is retired and might contain outdated information.

Querying the Strapi GraphQL API

Daniel Phiri
InstructorDaniel Phiri
Share this video with your friends

Social Share Links

Send Tweet

GraphQL has an amazing plugin for Strapi to allow us to query our data easily. In the Strapi marketplace, we can search and copy the install command to use in our terminal. In our localhost, after restarting the server, navigate to the /graphiql endpoint to view and use the GraphQL playground.

Instructor: [0:00] Strapi also lets us clear our content using a GraphQL API. In our Marketplace, we'll search for our GraphQL plugin, which as the description says, adds GraphQL endpoints with default npm methods. [0:14] We'll copy the install command and open our terminal. We'll stop our server and paste our command and run it. Once our install is done, we'll type npm run develop to restart our Strapi server.

[0:31] Now that our server is up and running, now that our server is running, we go to localhost:1337/graphql, which takes us to our GraphQL Playground. In our Playground, we can type queries and access the data inside Strapi.

[0:47] We'll do just that. We'll access our posts and inside our posts, we want to get our data, our attributes, our author, our date, our slug, and our body as well as our title, of course. Then, we send our request.

[1:13] We get forbidden access because we revoked all acesss to our API. We go back to our Strapi admin settings, click roles, "Public," and then grant ourselves permission to make find and find one queries, save that, and then go back to our playground.

[1:36] Now, our request should go in. We get Humpty Dumpty. That is how you query data from Strapi's GraphQL API.