Patterns

This reference covers the usage of patterns in TypeQL.

Scopes

Pattern comprise statements containing variables. Given a pattern, the scope of a variable is:

  • the block { …​ } in which variable appears at top-level (i.e., not nested in further {…​}) but it does not appear outside of the block.

  • or, the entire pattern itself if the variable appears at the top-level of the pattern itself.

Exceptionally, if the variable appears in all branches of a disjunction, it counts as appearing in the parent pattern.

A key principle of valid TypeQL pattern is:

Every variable must have a unique scope.

Combining patterns

TypeQL allows us to construct larger and more interesting patterns from smaller ones, allowing us to express more than simple conjunctions. They can also create new scopes of variables.

Use of conjunctions to join patterns into a single query pattern that combines all given constraints.

Use of disjunctions to allow for several branches in a query to be executed in parallel.

Use of negations to exclude patterns from your query results.

Use of optionals for optionally matching subpatterns.