Gatsby’s data layer is powered by GraphQL. This means that if you are building a Gatsby site, you will almost certainly use GraphQL to take advantage of Gatsby’s rich plugin ecosystem that extends this schema with data from anywhere. A popular tool for exploring your GraphQL schema is GraphiQL — which is a graphical, interactive, in-browser GraphQL development environment. It serves as an interactive playground where you can compose, test, and see the live results of your queries. If you haven’t seen or used GraphiQL, it looks something like this:
graphiql-explorer is a plugin for GraphiQL that adds a new technique to explore and build GraphQL queries. It adds a graphical representation of available fields and inputs that can be used in queries. It also allows constructing full queries by clicking through available fields and inputs without the repetitive process of typing these queries out by hand!
GraphiQL Explorer was built by the team at OneGraph (OneGraph is a single GraphQL endpoint through which you can bring in data from dozens of services like Salesforce, Stripe, Spotify, GitHub, and more). Check out the “Build a Podcast Mashup App Using OneGraph and Gatsby — Learn With Jason recording to learn more about OneGraph and how to use it with Gatsby.
We often hear that many developers’ first usage of GraphQL is through Gatsby. GraphQL, like any technology, has a learning curve. We can’t eliminate this learning curve completely but we can try to make it smoother. As mentioned previously, GraphiQL Explorer allows users to build full GraphQL queries without typing a single line of code. This enables users that don’t yet fully understand the GraphQL query syntax to learn GraphQL much more easily:
Check out “How OneGraph onboards users who are new to GraphQL” blog post for more details.
Improvements to on-boarding users new to GraphQL isn’t the only goal of integrating GraphiQL Explorer into Gatsby. There are other pain points that are getting addressed with this addition. Specifically union types and inline fragments. If the user is not aware of this syntax to query this type of fields it can be a fairly frustrating experience! GraphiQL Explorer helps solve this problem by listing available union types:
We recently added GraphiQL Explorer to Gatsby. It’s available starting with
Create new Gatsby project:
gatsby new gatsby-with-explorer
or update Gatsby in your existing project:
npm install gatsby
or try it live.
There are opportunities for further improvements for Gatsby users. Few things we will be working on are:
- evaluating accessibility of GraphiQL interface and addressing found issues,
- adding support for using GraphQL fragments provided by Gatsby plugins,
- adding code snippet generation for common workflows (using another awesome OneGraph’s GraphiQL addon -