The Gatsby REPL (“read-eval-print loop”) is available via the Gatsby CLI by running the command
gatsby repl. This gives you access to an interactive REPL shell within the context of your Gatsby environment. It can be used to retrieve general data and programmatically interact with it. If you have an idea for a new command, feel free to submit a PR for it!
This doc will give a brief description of each REPL command, expected output, and an example of what you can do with the command to digest the data. Examples are using the Gatsby Starter Blog as a demo environment, since it is currently the highest rated starter, and provides standard output for most of these commands.
To get started, in your terminal, after running the initial site setup steps here, run the command
gatsby repl to enter the interactive shell. If you are writing out a function, you can write that over multiple lines, as long as you do not use a semicolon or close a parenthesis or brace prematurely. This is helpful for running graphql queries and callback functions.
Returns an object with the global
Returns a Map object with all of the components in your Gatsby environment (see Mozilla Map docs for more information on Map objects and how to use them). Properties that get returned:
Get a single node by its ID, typically a string.
Returns an array of objects (the nodes).
nodes is like
getNodes(), but returns an indexed array of objects (the nodes). You can also pass in the index of the node you want, and that will return an array with a single node object.
nodes returns the array, or
nodes[<id>] returns an array with a node object.
Returns an indexed array of arrays. Each array contains a key which is the slug, and a value which is the page node object.
Returns the GraphQL schema of your Gatsby environment as an object.
Returns the settings you would find in the
gatsby-config.js file of your site as an object.
Returns a Map object with all of the static queries in your Gatsby environment. Properties that get returned:
Edit this page on GitHub