Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Learn to query TerminusDB and TerminusCMS using GraphQL and a Star Wars data project that you can clone from the dashboard.
To use this How-To, first clone the Star Wars demo into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
Once you have cloned the database, go to the GraphQL icon (triangle in hexagon) on the left-hand side and select the filing cabinet icon
Now you will have two panels, one on the left for query, and one on the right for results.
First type query{
into the query panel. It should look like this:
If at the cursor point you type: Ctrl-c
you'll get a list of options you can choose from. These options are legal GraphQL syntax according to your provided schema. Let's search for people from the Star Wars universe.
The label
property in this schema supplies the name of the person we are interested in. Of course, this query might give us a bit too much, so let us also limit it.
This should result in:
To get more fields in our query, we can just add words, using Ctrl-c
if we are stuck for names of fields.
When following links to other objects, we have to embed a query inside our query. So, for instance, if we want to know the homeworld that each of these people comes from we can write:
This will get us:
If we want to page the results, we can also add an offset to our query, and we'll get the next results.
And now we get two more:
How-to guides to query TerminusDB and TerminusCMS data products using GraphQL
How to use the order by argument in GraphQL queries with TerminusCMS and TerminusDB
To use this How-To, first clone the Star Wars demo into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
By default, results in GraphQL will choose an implementation-specific order which may not even be stable between invocations. If you need results in a specific order then you need to supply an orderBy
argument.
We can search for the names of people in reverse alphabetical order such that we only recover the first 5 results in the following way:
This will give us the following people:
Order by can also take more than one argument, allowing us to order on more than one value using the remaining arguments when there is a tie in the preceding (lexicographic ordering).
We can see this by searching for species, and which language they speak and their name. Since many will share the same language, we can see the ordering of the fields independently.
And here we have a number of Galactic Basic speakers who nevertheless are ordered by species name.
Using limit to limit results in GraphQL
To use this How-To, first clone the Star Wars demo into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
Once you have cloned the database, go to the GraphQL icon (triangle in hexagon) on the left-hand side and select the filing cabinet icon.
There are two panels, one on the left for query, and one on the right for results.
The limit
keyword is an argument which can be passed to a query to restrict the number of results to precisely the number supplied by the argument.
For instance, we can get exactly 5 people from the Star Wars universe by specifying the query here:
This will result in
If you want to page, to get the next results, you can use an offset
How to use GraphQL with the Apollo Client with TerminusDB & TerminusCMS
Install dependencies
Initialize ApolloClient and Connect with TerminusDB
Import the required dependencies needed -
Or
Initialize ApolloClient by passing its constructor with a configuration object with the TerminusDB server endpoint, user credentials and cache fields.
Extra information about the Apollo client cache can be found on their website
You will need to get your API key to connect with terminusCMS
Learn how to filter query results using GraphQL with TerminusDB and TerminusCMS
How-to perform back links in GraphQL with TerminusDB and TerminusCMS
Many times when we are looking at an object, we are interested in which objects are pointing to it. In TerminusCMS each object gets a number of extended queries which allows one to discover any objects which point at that object.
We would like to find the first person in the database, and then find out which starships they are the pilot of. A Starship
has a pilot
field, and the backlink is automatically constructed as the pilot_of_Starship
by TerminusCMS.
This back link will give us back the following:
Back linking allows us to focus on modelling our data in a natural way, while still allowing us to follow the graph in either the direction of a field or its opposite without bias.
Using offset to provide paging in GraphQL
Once you have cloned the database, go to the GraphQL icon (triangle in hexagon) on the left-hand side and select the filing cabinet icon.
There are two panels, one on the left for query, and one on the right for results.
For instance, we can get exactly 5 people from the star-wars universe by specifying the query here:
This will result in
If we then want to get the next page of data we can write:
This will result in:
Use advanced filtering techniques for GraphQL queries
Now we can filter the homeworld of the people we are interested in. We will use a regex
because Tatooine is hard to spell.
You can also find out what fields are available with the same Ctrl-c
trick. Now, fire off the query above, and you'll see something like:
We can also add other elements to the filter, by using the _and
keyword. This requires that both filters are true.
Which yields:
_not
and _or
You can also use _not
and _or
keywords to create even more complex filters. To find all species, excluding droids with a lifespan greater than 500 who don't have a typical sort of skin colour, you can write the following:
And yields:
The filter is defined as part of the query for objects. If we look at the People
query in the Star Wars demo we see the following:
This query exposes a filter
argument, with the type of People_Filter
.
A People_Filter
in turn looks like:
In this way we can recursively qualify all of the objects to which a People
might point to, terminating at leaves that use the various concrete type filters.
For instance, the StringFilter
looks like:
To use this How-To, first into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
Once you have Star Wars, you can enter the data product and you can type the following in the :
For more sophisticated filtering, see .
To use this How-To, first into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
Once you have cloned the Star Wars demo, go to the and type:
To use this How-To, first into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
The offset
keyword is most often used with the keyword which when used together enables paging of results.
To use this How-To, first into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
TerminusDB exposes a filter object, which can be used to select specific documents. See here for basic
We can specify any of these operands to narrow down our search. For more information on the operations against concrete datatypes, see the section.
How to do path queries on TerminusDB and TerminusCMS data products using GraphQL
To use this How-To, first clone the Star Wars demo into your team on TerminusCMS. You will then have full access to the data needed for this tutorial
Sometimes we want to search for links that are not immediate, but need to follow a chain of links to get the object of interest. TerminusCMS gives us path queries which allow us to succinctly express this.
We can find a path in GraphQL by using the _path_to_CLASS
query, where CLASS is the name of one of our classes. One path should be populated for each of the available classes.
To find everyone who was in a film with Chewbacca, we can write:
The film
is the current film at which the Chewbacca object points at. Then <film
means follow backwards to people in the film field.
This process can be repeated to find second-order connections, as follows:
This says that we should repeat the process one or two times before terminating.
More complex patterns can be built using the full path query syntax described in our documentation.