⚠️ 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
Published 2 years ago
Updated 11 months ago

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.

egghead
egghead
~ 2 hours ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today