Gatsby Training
  • About this training
  • Fundamentals
    • React
    • Gatsby
    • GraphQL
    • JAMStack
    • JSX
    • Webpack
  • Getting Started
    • Build your first Gatsby site
    • Project structure
    • Component structure
  • Components
    • About Components
    • Eyebrow
    • Button
    • Heading
    • Working with CSS
    • Movie Card
  • Gatsby Core Components
    • Gatsby Link
    • Gatsby Image
  • Data and GraphQL
    • Data sources
    • Connecting a data source
    • Using the GraphQL playground
  • CreatePages
    • createPages Function
    • Create a template
  • Resources
    • Gatsby and React Resources
    • Other resources
Powered by GitBook
On this page

Was this helpful?

  1. Data and GraphQL

Using the GraphQL playground

PreviousConnecting a data sourceNextcreatePages Function

Last updated 4 years ago

Was this helpful?

When the Gatsby development server is running, it will include GraphiQL, which is a browser-based tool you can use to query/inspect the GraphQL database associated with your site.

You can access the GraphiQL interface at:

How to Query

You can query nodes created from Drupal like the following:

{
  allArticle {
    edges {
      node {
        title
        internalId
        created(formatString: "DD-MMM-YYYY")
      }
    }
  }
}

With GraphiQL you can run queries to see the data from the Drupal site that Gatsby pulled in. When exploring the data in GraphiQL you’ll see that Gatsby groups Drupal content into collections based off of the content type (“allNodeMovie”, “allNodeLandingPage”, etc.)

Here’s a query you can run to get the title, body, and some other fields for all of the movie content type nodes in Drupal:

query MyQuery {
  allNodeMovie {
    edges {
      node {
        body {
          processed
        }
        title
        field_mpaa_rating
        field_promo_sentence
        relationships {
          field_genres {
            name
          }
        }
      }
    }
  }
}

Note that if your Drupal content type has entity reference fields (such as a reference to media or a taxonomy term), these will be included in GraphQL under “relationships”.

Further reading:

http://localhost:8000/___graphql
How To GraphQL