Query a graph database

When you first open a GraphXR project, the canvas is empty. If the project is connected to a graph database (an external one, or the internal data store), you must query to import its data to the project canvas.

  • No-code queries are available using the project Query / Search bar, the Expand with Relationships tool, and the Pull button for samples of data by Category or Relationship.

  • Those comfortable with a graph query language can open the Query panel to enter, run, and save Cypher or GQL queries.

If views have been saved in the project, you can load one of them, then query the database to add data to the view, if desired.

No-code Query in the Query bar

For a project connected to a graph database, you can use the project Query /Search bar to build and run a no-code visual query for the data matching a specific graph pattern.

You can * Query for a category of nodes. * Query for any pattern based on the categories and their relationships defined in the database * Optionally, add a property filter to category or relationship elements to narrow down the patterns that are returned.

To build a no-code visual query:

  1. In the project Query / Search bar, click to show the query dropdown menu.

  2. Select categories and relationships (and optionally specify property values) to build the query pattern.

    At each step the available relationships or categories appear in the dropdown menu. The example query below returns patterns where VMInstance nodes are connected through ASSIGNED_ROLE edges to Role nodes connected through ALLOWS _ACCESS_TO edges to Resource nodes.

    02 03 01 QueryBarPuppyGraph
  3. Click the run arrow on the far right end of the Query bar.

    02 03 02 QueryRun

No-code query with Expand

Once data have been returned to the canvas you can select nodes, and use no-code Expand to query for additional nodes in the database which are connected to the selected nodes through any of the database’s defined relationships.

Basic Expand

To query using right-click *Expand:*

  1. Select one or more nodes on the canvas using any method.

  2. Right-click and choose Expand to see the list of relationships (and their directions) connected to the selected nodes.

    02 03 03 ExpandBooks
  3. Select a relationship, or select All, to expand on all the possible relationships and return up to 1000 nodes and their connecting edges.

    If more than 1000 items match the query, an Expand Next Page dialog indicates the number of items that have been returned so far.

  4. Click Expand More to return the next 1000 connected nodes, or Cancel (or the X at the upper right) to close the dialog without returning all the results.

    02 03 04 ExpandMore

    When there are no more nodes to return, a message indicates that all relationships have been expanded.

Advanced no-code Expand

More specific expansion options are available either through the right-click Advanced Expansion dialog or through the Expand toolbar’s Expand with Relationships dialog.

  • Use either dialog to select more than one specific relationship to expand on, and to edit the limit of the number of edges expanded upon.

    02 03 05 RCAdvancedExpand
  • Use the Expand toolbar’s Expand with Relationships dialog if you also want to specify the direction of the relationships or the number of repeated expand queries to perform.

    02 03 06 ExpandDialog

To run an advanced *Expand query:*

  1. Click Expand in the toolbar to display the full Expand with relationships dialog.

  2. Click the checkbox next to a relationship name to expand on that relationship (or click All to expand on all available relationships).

  3. Set additional options for the query:

    • In the Limit textbox, edit the limit for the number of edges expanded upon in each query.

    • Click the Only among selected nodes checkbox to expand relationships only for the selected nodes.

    • Set Directional relationships using the dropdown menu. You can choose All directions, only nodes connected by relationships From the selected nodes or To the selected nodes.

    • Increase Repeat relationship times, which repeatedly expands on the specified edge Limit.

Pull data by Category or Relationship

You can pull a sample of 25 nodes, or edges with their attached nodes, from any category or relationship in the connected database.

While Pull is useful for initial exploration, a no-code query (or keyword search) combined with Expand with Relationships will usually yield more focused results.

To pull data by Category:

  1. Open the Project > Category subpanel.

  2. Click one of the Category items to select it.

    02 03 07 PullBank
  3. Click Pull to pull 25 nodes of that category.

    02 03 08 PullBankDone
  4. For more samples, click again, as many times as you want.

To pull data by relationship:

  1. Open the Project > Relationship subpanel.

  2. Click one of the Relationship items to select it.

    02 03 09 PullTOBANK
  3. Click Pull to pull 25 edges associated with that relationship and the connected nodes.

    02 03 08 PullEdgesDone
  4. For more samples, click again, as many times as you want.

Query using Cypher or GQL

Even though no-code visual query through the Query bar and Expand tool is fast and effective in many cases, you may want to specify more complex graph patterns that Cypher, and ISO-standard Graph Query Language (GQL) support.

In the project’s Query panel, you can:

  • Enter a Cypher or GQL query and click its Run icon to run it.

  • Save and name a query by clicking its + (plus) icon. The saved query appears on the dropdown Collection List.

  • Run a saved query by selecting it in the Collection List , which transfers it to the query window where you can Run it.

    02 03 10 CypherQuery

All GraphXR projects include a basic Cypher query that pulls 100 connected nodes from the database. This query will MATCH any pattern of nodes n and m connected by any relationship r, and RETURN the first 100 found. A LIMIT is set because this query will likely return a large amount of data.

MATCH (n)-[r]-(m) RETURN * LIMIT 100

A more specific, but still basic query for graph patterns is shown below.

MATCH (c:Characters)-[r:belongs_to]-(h:House) RETURN *

This query will MATCH any pattern of Characters and House nodes connected by a belongs_to relationship and RETURN all the matching graph patterns. The variables c, r, and h are assigned to simplify further query specifications.

To run and save a Cypher query:

  1. Open the Query panel and Cypher subpanel.

  2. Enter a Cypher query in the query text box (or click the Collection List dropdown arrow to select a saved query).

  3. Click the Load Inner Relationship checkbox to include the relationships between the nodes pulled by a query.

  4. Click the Run Cypher icon to query the connected database.

    The nodes and connecting edges matching the query pattern are returned to the project canvas.

    02 03 11 CypherQueryRun
  5. Click the + (plus) icon to save the query. In the Alias Name dialog, enter a name for the query, and click Confirm.