0
0
GraphqlHow-ToBeginner · 4 min read

How to Use GraphQL Playground: Quick Guide and Examples

To use GraphQL Playground, open it in your browser or as a desktop app, then enter your GraphQL API endpoint URL. You can write queries or mutations in the editor, run them with the play button, and see the results instantly in the response panel.
📐

Syntax

GraphQL Playground lets you write queries, mutations, and subscriptions using GraphQL syntax. Each operation starts with a keyword like query or mutation, followed by the operation name (optional), and a selection set inside curly braces { } specifying the fields you want.

You can also add variables and headers for authentication.

graphql
query GetUser {
  user(id: "1") {
    id
    name
    email
  }
}
💻

Example

This example shows a simple query to get a user's id, name, and email. Paste this in the Playground editor, then click the play button to run it and see the response on the right.

graphql
query GetUser {
  user(id: "1") {
    id
    name
    email
  }
}
Output
{ "data": { "user": { "id": "1", "name": "Alice", "email": "alice@example.com" } } }
⚠️

Common Pitfalls

  • Wrong endpoint URL: Make sure the URL you enter points to a running GraphQL server.
  • Missing headers: If your API needs authentication, add headers in the Playground settings.
  • Syntax errors: Check your query syntax carefully; Playground highlights errors.
  • Not using variables: Use variables to avoid hardcoding values and make queries reusable.
graphql
Wrong way:
query GetUser {
  user(id: "1") {  # id should be a string "1"
    id
    name
  }
}

Right way:
query GetUser($id: ID!) {
  user(id: $id) {
    id
    name
  }
}

Variables:
{
  "id": "1"
}
📊

Quick Reference

FeatureDescription
QueryFetch data from the server
MutationSend data to change server state
SubscriptionListen for real-time updates
VariablesDynamic values for queries/mutations
HeadersAdd authentication or custom info
Play ButtonRun the current operation
Docs ExplorerBrowse API schema and types

Key Takeaways

Open GraphQL Playground and enter your API endpoint URL to start.
Write queries or mutations using GraphQL syntax and run them with the play button.
Use variables and headers for dynamic queries and authentication.
Check for syntax errors highlighted by Playground before running.
Use the Docs Explorer to understand available queries and types.