Setting up Enonic
Contents
In this chapter you will create a local Enonic instance with sample content, and run your first query against the GraphQL API.
Task: Install the Enonic CLI
The Enonic CLI manages local instances of Enonic XP, known as sandboxes.
-
Install the CLI by running this command in your terminal:
npm install -g @enonic/cliThere are alternative ways to install the Enonic CLI as well.
-
Verify the installation. Run
enonic -v, which prints the version of the CLI. This tutorial expects version 4 or newer.
Task: Create and start a sandbox
-
Create a sandbox called
react_tutorialby running this command:enonic sandbox create react_tutorial -t intro -v 8.1.3 -fThis command will:
-
create a sandbox running Enonic XP 8.1.3
-
use the
introtemplate, which installs Content Studio, Guillotine and the Intro app with its sample content -
accept default values for the remaining options (
-f), and start the sandbox
-
-
Wait for the sandbox to start. The first startup takes a little longer, as the applications are installed and the sample content is imported and published.
Leave the sandbox running in this terminal window for the rest of the tutorial. To stop it, press ctrl-c. To start it again, run enonic sandbox start react_tutorial.
Task: Open Content Studio
-
Open the welcome page at http://localhost:8080.
-
Log in. Click Log In as Guest to open the XP admin dashboard.
-
Open Content Studio from the
XP menu. TheIntro Projectopens automatically.
The project contains persons and movies, along with their images. This is the content your React application will list and present. All of it is already published.
Task: Run a query
Guillotine is Enonic’s GraphQL API. Content Studio includes Query Playground, a tool for writing and testing queries against it.
-
Open Query Playground by clicking
Query Playgroundin the Content Studio menu. -
Paste and run the query below. It retrieves the three most recently modified persons:
query PersonListQuery { guillotine(project: "intro", branch: "master") { queryDsl( first: 3 query: { term: { field: "type", value: { string: "com.enonic.app.intro:person" } } } sort: { field: "modifiedTime", direction: DESC } ) { _id _name displayName type } } }You should get this result in the response panel:
{ "data": { "guillotine": { "queryDsl": [ { "_id": "a8b374a2-c532-45eb-9aa1-73d1c37cd681", "_name": "lea-seydough", "displayName": "Léa Seydough", "type": "com.enonic.app.intro:person" }, { "_id": "569d127d-b6bd-45d6-94b0-949ec6171336", "_name": "jeffrey-wroughtair", "displayName": "Jeffrey Wroughtair", "type": "com.enonic.app.intro:person" }, { "_id": "f29ba9b7-a73a-4767-82db-9da4df952924", "_name": "daniel-carrigear", "displayName": "Daniel Carrigear", "type": "com.enonic.app.intro:person" } ] } } }
In the query:
-
introis the identifier of the content project -
masteris the branch holding published content, whiledraftholds work in progress -
com.enonic.app.intro:personis thepersoncontent type, defined by the Intro app
The API endpoint
Query Playground is a convenience for developers. Your React application will send the same queries directly to the Guillotine endpoint:
http://localhost:8080/api/com.enonic.app.guillotine:graphql
The endpoint is shared by all content projects, which is why each query states the project and branch. Published content in the Intro project can be read without logging in, so the application needs no credentials.
Next
With Enonic up and running, it is time to create the React app.