### Start Cayley with Sample Data (Bash) Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-started.md Command to start the Cayley HTTP server and load data from a specified N-Quads file. Replace '30kmoviedata.nq.gz' with your data file path. ```bash cayley http --load 30kmoviedata.nq.gz ``` -------------------------------- ### Start Cayley HTTP Server (Bash) Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-started.md Command to start the Cayley HTTP server using the default in-memory backend. This makes the web interface available. ```bash cayley http ``` -------------------------------- ### Running a Cayley Example Source: https://github.com/cayleygraph/cayley/blob/master/examples/README.md This command executes a specific example program within the Cayley project using the Go runtime. Replace `hello_world` with the name of the desired example directory to run a different example. ```Shell go run hello_world/main.go ``` -------------------------------- ### Deploying to Flexible App Engine - Shell Source: https://github.com/cayleygraph/cayley/blob/master/appengine/README.md Commands to install the `aedeploy` tool, generate necessary files, and deploy the application to the flexible App Engine environment using `aedeploy` and `gcloud`. ```sh $ go get -u google.golang.org/appengine/cmd/aedeploy $ go generate $ aedeploy gcloud app deploy app.flexible.yaml ``` -------------------------------- ### Running Traditional App Engine Locally - Shell Source: https://github.com/cayleygraph/cayley/blob/master/appengine/README.md Commands to navigate to the appengine directory, check Go and goapp versions, install dependencies, build, and serve the application locally using the traditional App Engine environment. ```sh $ cd $GOPATH/src/github.com/cayleygraph/cayley/appengine # check go version $ go version # check goapp version $ goapp version # install dependencies $ goapp get # ensure that goapp can build $ goapp build # test locally $ goapp serve ``` -------------------------------- ### Run Cayley using Docker Source: https://github.com/cayleygraph/cayley/blob/master/docs/installation.md Runs the official Cayley Docker image, mapping the default Cayley port (64210) from the container to the host machine. This starts a Cayley instance accessible locally. ```bash docker run -p 64210:64210 cayleygraph/cayley ``` -------------------------------- ### Match Path Using Morphism (Gizmo/JS) Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-started.md Demonstrates using a Morphism to encapsulate a common path traversal. Defines 'filmToActor' as a path from a film starring node to an actor node, then uses 'follow()' to apply this path starting from the 'Casablanca' vertex to find actor names. ```javascript var filmToActor = g .Morphism() .out("") .out(""); g.V() .has("", "Casablanca") .follow(filmToActor) .out("") .all(); ``` -------------------------------- ### Query All Vertices with Limit (Gizmo/JS) Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-started.md Selects all vertices in the graph using the 'g.V()' method and limits the results to the first 5 using 'getLimit(5)'. 'g' and 'V' are common aliases for 'graph' and 'Vertex'. ```javascript g.V().getLimit(5); ``` -------------------------------- ### Running Cayley HTTP Server Source: https://github.com/cayleygraph/cayley/blob/master/docs/contributing.md Starts the Cayley HTTP server and loads data from a specified NQuads file, making the WebUI available. ```Text ./cayley http -i data/testdata.nq ``` -------------------------------- ### Install Cayley using Snap on Ubuntu Source: https://github.com/cayleygraph/cayley/blob/master/docs/installation.md Installs the Cayley graph database on Ubuntu using the snap package manager. The --edge flag specifies the channel, and --devmode allows necessary permissions. ```text snap install --edge --devmode cayley ``` -------------------------------- ### Using Back Method for Path Traversal - Gizmo/JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md Illustrates how the .back() method allows returning to a node tagged earlier in the query path while preserving constraints. This example starts from all nodes, tags them, follows a status link, jumps back to the tagged node, and then finds incoming follow links. ```javascript // Start from all nodes, save them into start, follow any status links, // jump back to the starting node, and find who follows them. Return the result. // Results are: // {"id": "", "start": ""}, // {"id": "", "start": ""}, // {"id": "", "start": ""}, // {"id": "", "start": ""}, // {"id": "", "start": ""}, // {"id": "", "start": ""}, // {"id": "", "start": ""}, // {"id": "", "start": ""} g.V() .Tag("start") .out("") .back("start") .in("") .all(); ``` -------------------------------- ### Paginating Results in Cayley GraphQL Query Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/graphql.md This GraphQL-like query shows how to paginate results using the `offset` and `first` keywords, retrieving 3 nodes starting from the 5th result. ```graphql { nodes(offset: 5, first: 3){ id } } ``` -------------------------------- ### Example Quad (Cayley) Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/mql.md This is a representation of a quad in the graph database, indicating a directed edge from node "A" to node "B" with the predicate "some_predicate". ```text A some_predicate B . ``` -------------------------------- ### Initializing and Opening Cayley Bolt Graph in Go Source: https://github.com/cayleygraph/cayley/blob/master/docs/quickstart-as-lib.md This snippet demonstrates how to initialize and open a graph store using a specific backend, such as Bolt. It uses graph.InitQuadStore to set up the database and cayley.NewGraph to open it for use. It requires the github.com/cayleygraph/cayley and github.com/cayleygraph/cayley/graph packages and a configured backend like Bolt. ```Go import "github.com/cayleygraph/cayley/graph" func open() { // Initialize the database graph.InitQuadStore("bolt", path, nil) // Open and use the database cayley.NewGraph("bolt", path, nil) } ``` -------------------------------- ### Using path.follow with Morphism in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Applies a path chain defined in a Morphism object to the current path. It starts the traversal from the current path's nodes as if they were the starting point of the morphism. The example finds 'friends of friends' of Charlie who have a 'cool_person' status. ```javascript var friendOfFriend = g .Morphism() .out("") .out(""); // Returns the followed people of who charlie follows -- a simplistic "friend of my friend" // and whether or not they have a "cool" status. Potential for recommending followers abounds. // Returns bob and greg g.V("") .follow(friendOfFriend) .has("", "cool_person") .all(); ``` -------------------------------- ### Load Data into Cayley 0.7+ (Backend/Address) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Loads data from a gzipped pquads file into a new Cayley 0.7+ database using specified backend and address, initializing the database first. ```bash ./cayley load --init -d -a -i ./data.pq.gz ``` -------------------------------- ### Using Cayley Memory Graph in Go Source: https://github.com/cayleygraph/cayley/blob/master/docs/quickstart-as-lib.md This snippet demonstrates how to use Cayley as a Go library with an in-memory graph. It shows creating a new memory graph, adding a quad, creating a path query, and iterating over the results to print the values. It requires the github.com/cayleygraph/cayley and github.com/cayleygraph/quad packages. ```Go package main import ( "fmt" "log" "github.com/cayleygraph/cayley" "github.com/cayleygraph/quad" ) func main() { // Create a brand new graph store, err := cayley.NewMemoryGraph() if err != nil { log.Fatalln(err) } store.AddQuad(quad.Make("phrase of the day", "is of course", "Hello World!", nil)) // Now we create the path, to get to our data p := cayley.StartPath(store, quad.String("phrase of the day")).Out(quad.String("is of course")) // Now we iterate over results. Arguments: // 1. Optional context used for cancellation. // 2. Flag to optimize query before execution. // 3. Quad store, but we can omit it because we have already built path with it. err = p.Iterate(nil).EachValue(nil, func(value quad.Value){ nativeValue := quad.NativeOf(value) // this converts RDF values to normal Go types fmt.Println(nativeValue) }) if err != nil { log.Fatalln(err) } } ``` -------------------------------- ### Importing Cayley Bolt Backend in Go Source: https://github.com/cayleygraph/cayley/blob/master/docs/quickstart-as-lib.md This snippet shows how to import a specific backend, like Bolt, using an empty import (_). This registers the backend with Cayley so it can be used later for initializing and opening graph stores. It requires the Bolt backend package. ```Go import _ "github.com/cayleygraph/cayley/graph/kv/bolt" ``` -------------------------------- ### Load Data into Cayley 0.7.x (Backend/Address) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Loads data from a gzipped pquads file into a new Cayley 0.7.x database using specified backend and address, initializing the database first. ```bash ./cayley load --init -d -a -i ./data.pq.gz ``` -------------------------------- ### Match Complex Path (Gizmo/JS) Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-started.md Queries for vertices matching the name 'Casablanca', then traverses outgoing edges with specific predicates ('', '', '') to find related entities, such as actors. The '.all()' method executes the query. ```javascript g.V() .has("", "Casablanca") .out("") .out("") .out("") .all(); ``` -------------------------------- ### Running Cayley REPL Source: https://github.com/cayleygraph/cayley/blob/master/docs/contributing.md Starts the Cayley Read-Eval-Print Loop (REPL) and loads data from a specified NQuads file. ```Text ./cayley repl -i data/testdata.nq ``` -------------------------------- ### Match Vertex by Property (Gizmo/JS) Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-started.md Finds vertices that have a specific property, matching the predicate '' with the value 'Humphrey Bogart'. The '.all()' method executes the query and returns all matching results. ```javascript g.V() .has("", "Humphrey Bogart") .all(); ``` -------------------------------- ### Deploying to Traditional App Engine - Shell Source: https://github.com/cayleygraph/cayley/blob/master/appengine/README.md Command to deploy the application to the traditional App Engine environment, specifying the version and project ID. ```sh $ goapp deploy -version 1 -application ``` -------------------------------- ### Example Gremlin Query using In/Out Predicates (JavaScript) Source: https://github.com/cayleygraph/cayley/blob/master/docs/glossary.md Demonstrates how inbound and outbound predicates are used within a Gremlin query example to traverse the graph and find projects created by two friends. It illustrates graph pattern matching and filtering based on relationships. ```javascript What are the names of projects that were created by two friends? g.V().match( as("a").out("knows").as("b"), as("a").out("created").as("c"), as("b").out("created").as("c"), as("c").in("created").count().is(2)). select("c").by("name") ``` -------------------------------- ### Importing Cayley Bolt Backend in Go Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/quickstart-as-lib.md This snippet shows how to perform an empty import (`_`) of the Cayley Bolt graph backend package. This registers the Bolt driver with Cayley without explicitly using any functions from the package, making it available for initialization and opening. ```go import _ "github.com/cayleygraph/cayley/graph/kv/bolt" ``` -------------------------------- ### Write N-Quad File Example - Cayley v1 API - Curl Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/http.md Provides a command-line example using `curl` to upload an N-Quad file (`30k.n3`) to the `/api/v1/write/file/nquad` endpoint using a form-encoded body with the key `NQuadFile`. ```text curl http://localhost:64210/api/v1/write/file/nquad -F NQuadFile=@30k.n3 ``` -------------------------------- ### Initializing and Opening Cayley Bolt Graph in Go Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/quickstart-as-lib.md This snippet demonstrates how to initialize a new Bolt graph database at a specified path using `graph.InitQuadStore` and subsequently open an existing or newly initialized Bolt graph store using `cayley.NewGraph`. This requires the Bolt backend package to be imported. ```go import "github.com/cayleygraph/cayley/graph" func open() { // Initialize the database graph.InitQuadStore("bolt", path, nil) // Open and use the database cayley.NewGraph("bolt", path, nil) } ``` -------------------------------- ### Example N-Quad File Upload - curl Source: https://github.com/cayleygraph/cayley/blob/master/docs/http.md Provides a curl command example demonstrating how to upload an N-Quad file to the /api/v1/write/file/nquad endpoint using a form-encoded body. ```text curl http://localhost:64210/api/v1/write/file/nquad -F NQuadFile=@30k.n3 ``` -------------------------------- ### Using Cayley In-Memory Graph in Go Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/quickstart-as-lib.md This snippet demonstrates the basic usage of Cayley as a Go library by creating an in-memory graph, adding a quad (subject, predicate, object, label), constructing a path to query the data, and iterating over the results using the EachValue function. ```go package main import ( "fmt" "log" "github.com/cayleygraph/cayley" "github.com/cayleygraph/quad" ) func main() { // Create a brand new graph store, err := cayley.NewMemoryGraph() if err != nil { log.Fatalln(err) } store.AddQuad(quad.Make("phrase of the day", "is of course", "Hello World!", nil)) // Now we create the path, to get to our data p := cayley.StartPath(store, quad.String("phrase of the day")).Out(quad.String("is of course")) // Now we iterate over results. Arguments: // 1. Optional context used for cancellation. // 2. Flag to optimize query before execution. // 3. Quad store, but we can omit it because we have already built path with it. err = p.Iterate(nil).EachValue(nil, func(value quad.Value){ nativeValue := quad.NativeOf(value) // this converts RDF values to normal Go types fmt.Println(nativeValue) }) if err != nil { log.Fatalln(err) } } ``` -------------------------------- ### Running Flexible App Engine Locally - Shell Source: https://github.com/cayleygraph/cayley/blob/master/appengine/README.md Commands to generate necessary files and serve the application locally using the flexible App Engine environment configuration file `app.flexible.yaml`. ```sh $ go generate $ goapp serve app.flexible.yaml ``` -------------------------------- ### Example Visualization Data Structure (JavaScript) Source: https://github.com/cayleygraph/cayley/blob/master/docs/ui-overview.md Example JSON structure expected by the visualization feature. It represents links between nodes using 'source' and 'target' keys. ```javascript [ { source: "node1", target: "node2" }, { source: "node1", target: "node3" } ]; ``` -------------------------------- ### Paginating Results in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Shows how to implement pagination by combining the 'offset' argument to skip a number of results and 'first' to limit the number returned after the offset. ```graphql { nodes(offset: 5, first: 3){ id } } ``` -------------------------------- ### Load Data into Cayley 0.7.x (Config File) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Loads data from a gzipped pquads file into a new Cayley 0.7.x database using a specified configuration file, initializing the database first. ```bash ./cayley load --init -c -i ./data.pq.gz ``` -------------------------------- ### Install Cayley using Homebrew on macOS Source: https://github.com/cayleygraph/cayley/blob/master/docs/installation.md Installs the Cayley graph database on macOS using the Homebrew package manager. This command assumes Homebrew is already installed on the system. ```bash brew install cayley ``` -------------------------------- ### Example Multiple Predicate Quads (Cayley) Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/mql.md These are representations of two quads in the graph database, both originating from node "A" with the predicate "some_predicate" but pointing to different objects, "B" and "C". This scenario is handled by using named predicates (`@name:predicate`) in MQL queries. ```text A some_predicate B . A some_predicate C . ``` -------------------------------- ### Counting Query Results - Gizmo/JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md Explains how to use the .count() method to get the total number of results from a query path. The example saves the count to a variable and then uses g.emit() to include the count in the final output. ```javascript // Save count as a variable var n = g.V().count(); // Send it as a query result g.emit(n); ``` -------------------------------- ### Load Data into Cayley 0.7+ (Config File) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Loads data from a gzipped pquads file into a new Cayley 0.7+ database using a specified configuration file, initializing the database first. ```bash ./cayley load --init -c -i ./data.pq.gz ``` -------------------------------- ### Example Reverse Quad (Cayley) Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/mql.md This is a representation of a quad in the graph database, indicating a directed edge from node "B" to node "A" with the predicate "some_predicate". This quad is matched by a reverse predicate query (`!some_predicate`) targeting node "A". ```text B some_predicate A . ``` -------------------------------- ### Specifying Connection URI Source: https://github.com/cayleygraph/cayley/blob/master/docs/cayleyimport.md Example of using the `--uri` option to specify the connection string for the Cayley deployment. The URI should be enclosed in quotes. ```Shell --uri "http://host[:port]" ``` -------------------------------- ### Dump Data from Cayley 0.6.1 (Backend/Path) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Dumps all data from a Cayley 0.6.1 database using specified backend and path into a gzipped pquads file. ```bash ./cayley-0.6 dump --db --dbpath
--dump_type pquads --dump ./data.pq.gz ``` -------------------------------- ### Dump Data from Cayley 0.7+ (Backend/Address) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Dumps all data from a Cayley 0.7+ database using specified backend and address into a gzipped pquads file. ```bash ./cayley dump -d -a
-o ./data.pq.gz ``` -------------------------------- ### Load Cayley 0.7+ Dump into New Backend (pquads, DB/Path) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Loads data from a gzipped pquads file dumped from a Cayley 0.7+ database into a new 0.7+ database specified by backend type and path. The --init flag initializes the new database. ```Bash ./cayley load --init -d -a -i ./data.pq.gz ``` -------------------------------- ### Load Cayley 0.7+ Dump into New Backend (pquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Loads data from a gzipped pquads file dumped from a Cayley 0.7+ database into a new 0.7+ database configured via a file. The --init flag initializes the new database. ```Bash ./cayley load --init -c -i ./data.pq.gz ``` -------------------------------- ### Running Cayley HTTP Server with Test Data Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-involved/contributing.md Starts the Cayley HTTP server using the built binary and loads data from the specified test data file. This enables access to the WebUI and HTTP API. ```bash ./cayley http -i data/testdata.nq ``` -------------------------------- ### Creating a Path Object - Gizmo Source: https://github.com/cayleygraph/cayley/blob/master/docs/glossary.md This snippet shows how to use the `.v()` method (aliased as `Vertex`) in the Gizmo query language to start a graph traversal path from one or more specified node IDs. ```Gizmo pathObject = graph.Vertex([nodeId],[nodeId]...) ``` -------------------------------- ### Query for Visualization (Cayley Query Language) Source: https://github.com/cayleygraph/cayley/blob/master/docs/ui-overview.md Example query using Cayley's query language (likely Gizmo) to fetch nodes and tag them as 'source' and 'target' for visualization. It finds nodes followed by ''. ```text // Visualize who dani follows. g.V("").Tag("source").Out("").Tag("target").All() ``` -------------------------------- ### Deploying Distributed Cayley (MongoDB) on Kubernetes Source: https://github.com/cayleygraph/cayley/blob/master/docs/k8s/k8s.md Deploys a distributed Cayley setup running on a 3-node MongoDB cluster on Kubernetes by applying the specified YAML configuration file. This setup is based on the thesandlord/mongo-k8s-sidecar project. ```bash kubectl create -f ./docs/k8s/cayley-mongo.yml ``` -------------------------------- ### Dump Data from Cayley 0.7+ (Config File) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Dumps all data from a Cayley 0.7+ database using a specified configuration file into a gzipped pquads file. ```bash ./cayley dump -c -o ./data.pq.gz ``` -------------------------------- ### Load Cayley 0.6.1 Dump into 0.7+ (pquads, DB/Path) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Loads data from a gzipped pquads file dumped from Cayley 0.6.1 into a new Cayley 0.7.x database specified by backend type and path. The --init flag initializes the new database. ```Bash ./cayley load --init -d -a -i ./data.pq.gz ``` -------------------------------- ### Deploying Distributed Cayley (MongoDB) in Kubernetes Source: https://github.com/cayleygraph/cayley/blob/master/docs/deployment/k8s-1.md Deploys a distributed Cayley setup running on a 3-node MongoDB cluster in Kubernetes. ```bash kubectl create -f ./docs/k8s/cayley-mongo.yml ``` -------------------------------- ### Cayley REPL Gizmo/JS Examples - Text Source: https://github.com/cayleygraph/cayley/blob/master/docs/advanced-use.md Demonstrates various commands and queries within the Cayley REPL, including basic arithmetic, JavaScript variable assignment, and graph traversal using the Gizmo query language. ```text // Simple math cayley> 2 + 2 // JavaScript syntax cayley> x = 2 * 8 cayley> x // See all the entities in this small follow graph. cayley> graph.Vertex().All() // See only dani. cayley> graph.Vertex("").All() // See who dani follows. cayley> graph.Vertex("").Out("").All() ``` -------------------------------- ### Load Cayley 0.6.1 Dump into 0.7+ (pquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Loads data from a gzipped pquads file dumped from Cayley 0.6.1 into a new Cayley 0.7.x database configured via a file. The --init flag initializes the new database. ```Bash ./cayley load --init -c -i ./data.pq.gz ``` -------------------------------- ### Gremlin Query Example for Finding Projects by Friends Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-involved/glossary.md Demonstrates a complex Gremlin query in JavaScript using `match` to find projects created by two friends. It illustrates pattern matching and traversal across 'knows' and 'created' relationships. ```javascript g.V().match( as("a").out("knows").as("b"), as("a").out("created").as("c"), as("b").out("created").as("c"), as("c").in("created").count().is(2)). select("c").by("name") ``` -------------------------------- ### Dump Data from Cayley 0.6.1 (Config File) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Dumps all data from a Cayley 0.6.1 database using a specified configuration file into a gzipped pquads file. ```bash ./cayley-0.6 dump --config --dump_type pquads --dump ./data.pq.gz ``` -------------------------------- ### Expanding All Properties (GraphQL) Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Demonstrates how to use the '*' wildcard character within a field selection to fetch all properties of a nested object instead of listing them individually. ```GraphQL { nodes{ id follows {*} } } ``` -------------------------------- ### Limiting Results in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Demonstrates how to limit the maximum number of results returned by the query using the 'first' argument on the root 'nodes' object. ```graphql { nodes(first: 10){ id } } ``` -------------------------------- ### Getting Inbound Predicates with path.inPredicates (JavaScript) Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md The `inPredicates` method retrieves the list of predicates that point inward to the current node(s) in the path. ```javascript // bob only has "" predicates pointing inward // returns "" g.V("") .inPredicates() .all(); ``` -------------------------------- ### Running Cayley REPL with Test Data Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-involved/contributing.md Starts the Cayley Read-Eval-Print Loop (REPL) using the built binary and loads data from the specified test data file. This allows interactive querying of the graph data. ```bash ./cayley repl -i data/testdata.nq ``` -------------------------------- ### Getting Outgoing Predicates with path.outPredicates Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Shows how to use `outPredicates` to retrieve a list of predicates pointing outwards from the nodes in the current path. ```javascript // bob has "" and "" edges pointing outwards // returns "", "" g.V("") .outPredicates() .all(); ``` -------------------------------- ### Basic Node Query Result in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Illustrates the expected JSON output structure for the basic GraphQL query, showing a list of node IDs under the 'data.nodes' path. ```javascript { "data": { "nodes": [ {"id": "bob"}, {"id": "status"}, {"id": "cool_person"}, {"id": "alice"}, {"id": "greg"}, {"id": "emily"}, {"id": "smart_graph"}, {"id": "predicates"}, {"id": "dani"}, {"id": "fred"}, {"id": "smart_person"}, {"id": "charlie"}, {"id": "are"}, {"id": "follows"} ] } } ``` -------------------------------- ### Running Other Cayley Commands in Docker Container Source: https://github.com/cayleygraph/cayley/blob/master/docs/deployment/container.md This command shows how to execute a different Cayley command inside the container by overriding the default entry point using the '--entrypoint' flag. In this example, it runs the 'version' command. ```shell docker run -v $PWD/data:/data ghcr.io/cayleygraph/cayley --entrypoint=cayley version ``` -------------------------------- ### Load Cayley 0.7+ Dump into New Backend (nquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Loads data from a gzipped nquads file dumped from a Cayley 0.7+ database into a new 0.7+ database configured via a file. This uses the standard text format as an alternative to pquads for migration between backends. ```Bash ./cayley load --init -c -i ./data.nq.gz ``` -------------------------------- ### Getting Incoming Predicates with path.inPredicates - JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Retrieves the list of predicates that point inward to the nodes currently in the path. ```javascript // bob only has "" predicates pointing inward // returns "" g.V("") .inPredicates() .all(); ``` -------------------------------- ### Filtering Objects by Property Value in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Shows how to filter the initial set of nodes by specifying exact values for properties as arguments to the 'nodes' root object. ```graphql { nodes(id: , status: "cool_person"){ id } } ``` -------------------------------- ### Multiple Properties Query Result in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Shows the JSON output when querying multiple properties like 'id' and 'status', illustrating how properties are included for matching nodes. ```javascript { "data": { "nodes": [ {"id": "bob", "status": "cool_person"}, {"id": "greg", "status": "cool_person"}, {"id": "dani", "status": "cool_person"}, {"id": "greg", "status": "smart_person"}, {"id": "emily", "status": "smart_person"} ] } } ``` -------------------------------- ### Dump Cayley 0.7+ Data (pquads, DB/Path) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Dumps data from a Cayley 0.7+ database specified by backend type and path into a gzipped pquads file. This is used for migrating data between different backends in 0.7+. ```Bash ./cayley dump -d -a
-o ./data.pq.gz ``` -------------------------------- ### Load Cayley 0.6.1 Dump into 0.7+ (nquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Loads data from a gzipped nquads file dumped from Cayley 0.6.1 into a new Cayley 0.7.x database configured via a file. This uses the standard text format as an alternative to pquads for migration. ```Bash ./cayley load --init -c -i ./data.nq.gz ``` -------------------------------- ### Querying Optional Properties in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Demonstrates how to make a property optional using the '@opt' or '@optional' directive, ensuring nodes without this property are still included in the results. ```graphql { nodes{ id status @opt } } ``` -------------------------------- ### Getting Single Tagged Result with path.tagValue Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Explains `tagValue`, which is similar to `tagArray` but limited to returning a single result node as a tag-to-string map. -------------------------------- ### Getting Tagged Results as Array with path.tagArray in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md Executes the query and returns the results as a JavaScript Array of tag-to-string dictionaries, similar to `all()`, but available within the JavaScript environment. ```javascript // bobTags contains an Array of followers of bob (alice, charlie, dani). var bobTags = g .V("") .tag("name") .in("") .tagArray(); // nameValue should be the string "" var nameValue = bobTags[0]["name"]; ``` -------------------------------- ### Querying Node Properties in Cayley GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/graphql.md This GraphQL-like query retrieves nodes and includes the `status` property along with the node `id`, demonstrating how to fetch predicate values. ```graphql { nodes{ id, status } } ``` -------------------------------- ### Querying Multiple Properties in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Explains how to fetch multiple predicates (properties) for the selected nodes by listing them within the object selection. Predicates can be specified as plain text or IRIs. ```graphql { nodes{ id, status } } ``` -------------------------------- ### Dump Cayley 0.6.1 Data (nquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Dumps data from a Cayley 0.6.1 database configured via a file into a gzipped nquads file. This uses the standard text format as an alternative to pquads for migration. ```Bash ./cayley-0.6 dump --config --dump ./data.nq.gz ``` -------------------------------- ### Connect to Cayley REPL - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/advanced-use.md Starts the Cayley Read-Eval-Print Loop (REPL), allowing interactive querying and manipulation of the graph database using a specified configuration file. The REPL defaults to expecting Gizmo/JS input. ```bash ./cayley repl -c cayley_overview.yml ``` -------------------------------- ### Follow Morphism Path in Cayley (JavaScript) Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md Applies a predefined path chain (morphism) to the current path. The traversal starts from the current nodes and follows the steps defined in the morphism. ```javascript var friendOfFriend = g .Morphism() .out("") .out(""); // Returns the followed people of who charlie follows -- a simplistic "friend of my friend" // and whether or not they have a "cool" status. Potential for recommending followers abounds. // Returns bob and greg g.V("") .follow(friendOfFriend) .has("", "cool_person") .all(); ``` -------------------------------- ### Setting up and Running Cayley in Docker with Custom Configuration Source: https://github.com/cayleygraph/cayley/blob/master/docs/deployment/container.md These commands demonstrate how to set up a local data directory, copy necessary configuration and data files into it, and then run the Cayley container mounting this directory. It shows how to initialize the database with data and how to serve an existing database using a custom configuration file. ```shell mkdir data ``` ```shell cp cayley_example.yml data/cayley.yml ``` ```shell cp data/testdata.nq data/my_data.nq ``` ```shell docker run -v $PWD/data:/data -p 64210:64210 -d ghcr.io/cayleygraph/cayley -c /data/cayley.yml --init -i /data/my_data.nq ``` ```shell docker run -v $PWD/data:/data -p 64210:64210 -d ghcr.io/cayleygraph/cayley -c /data/cayley.yml ``` -------------------------------- ### Querying Nested Objects in Cayley GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/graphql.md This GraphQL-like query demonstrates fetching nested objects by traversing the `follows` predicate, retrieving the `id` of nodes that the initial nodes follow. ```graphql { nodes{ id follows { id } } } ``` -------------------------------- ### Basic Node Query in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Shows the simplest query structure to retrieve all nodes in the graph. The 'nodes' root object initiates the search, and 'id' is a special field for the node's value. ```graphql { nodes{ id } } ``` -------------------------------- ### Serving Cayley Graph via HTTP (Default) Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/advanced-use.md Starts the Cayley HTTP server to expose the graph database via a web interface and HTTP API. It uses the configuration file to determine the database and default listening address. ```bash ./cayley http -c cayley_overview.yml ``` -------------------------------- ### Traversing Both Directions with Both - Gizmo/JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md Shows how to use the .both() method to follow a specified predicate in both the incoming and outgoing directions from a starting vertex. This is a shorthand for performing both an .out() and an .in() traversal. ```javascript // Find all followers/followees of fred. Returns bob, emily and greg g.V("") .both("") .all(); ``` -------------------------------- ### Dump Cayley 0.6.1 Data (pquads, DB/Path) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Dumps data from a Cayley 0.6.1 database specified by backend type and path into a gzipped pquads file. This is the first step for migrating data to 0.7.x using the binary format. ```Bash ./cayley-0.6 dump --db --dbpath
--dump_type pquads --dump ./data.pq.gz ``` -------------------------------- ### Dump Cayley 0.7+ Data (nquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Dumps data from a Cayley 0.7+ database configured via a file into a gzipped nquads file. This uses the standard text format as an alternative to pquads for migration between backends. ```Bash ./cayley dump -c -o ./data.nq.gz ``` -------------------------------- ### Querying All Nodes (Cayley MQL - JavaScript) Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/mql.md This query retrieves all nodes in the graph. The `id` keyword represents the node's value, and setting it to `null` indicates that the value should be returned. ```javascript [ { "id": null } ] ``` -------------------------------- ### Querying Reversed Predicates in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Demonstrates how to traverse incoming links (reversed predicates) using the '@rev' or '@reverse' directive on a predicate field, here finding nodes that are 'followed' by others. ```graphql { nodes{ id followed: @rev { id } } } ``` -------------------------------- ### Dump Cayley 0.7+ Data (pquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Dumps data from a Cayley 0.7+ database configured via a file into a gzipped pquads file. This is an alternative dump method for migrating data between different backends in 0.7+. ```Bash ./cayley dump -c -o ./data.pq.gz ``` -------------------------------- ### Cloning Fork into GOPATH for Development Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-involved/contributing.md Creates the necessary directory structure within the user's GOPATH and clones a personal fork of the Cayley repository into it. This setup is typical for contributing changes via pull requests. ```bash mkdir -p $GOPATH/src/github.com/cayleygraph cd $GOPATH/src/github.com/cayleygraph git clone https://github.com/$GITHUBUSERNAME/cayley ``` -------------------------------- ### Getting Tagged Results as Array with path.tagArray Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Shows how `tagArray` returns the results as a JavaScript Array of tag-to-string dictionaries, similar to `all()` but available within the JS environment. ```javascript // bobTags contains an Array of followers of bob (alice, charlie, dani). var bobTags = g .V("") .tag("name") .in("") .tagArray(); // nameValue should be the string "" var nameValue = bobTags[0]["name"]; ``` -------------------------------- ### Running Cayley Help Command Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-involved/contributing.md Executes the newly built Cayley binary with the 'help' subcommand to display available commands and options. This verifies the binary was built successfully. ```bash ./cayley help ``` -------------------------------- ### Dump Cayley 0.6.1 Data (pquads, Config) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/migration.md Dumps data from a Cayley 0.6.1 database configured via a file into a gzipped pquads file. This is an alternative dump method for migrating data to 0.7.x using the binary format. ```Bash ./cayley-0.6 dump --config --dump_type pquads --dump ./data.pq.gz ``` -------------------------------- ### Expanding All Properties in GraphQL Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/graphql.md This GraphQL query demonstrates how to expand all properties of a nested object field, such as 'follows', by using the '*' wildcard. This is useful for retrieving all available sub-fields without explicitly listing them. ```GraphQL { nodes{ id follows {*} } } ``` -------------------------------- ### Using path.has for Filtering in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Filters the current set of nodes based on whether they have a specific predicate-object relationship. It acts as a constraint without traversing the relationship. Useful for filtering starting nodes or intermediate results. The examples show filtering by a direct relationship and by a relationship with a value constraint. ```javascript // Start from all nodes that follow bob -- results in alice, charlie and dani g.V() .has("", "") .all(); // People charlie follows who then follow fred. Results in bob. g.V("") .out("") .has("", "") .all(); // People with friends who have names sorting lower then "f". g.V() .has("", gt("")) .all(); ``` -------------------------------- ### Running Cayley Help Command Source: https://github.com/cayleygraph/cayley/blob/master/docs/contributing.md Executes the built Cayley binary with the 'help' subcommand to display usage information. ```Bash ./cayley help ``` -------------------------------- ### Serve Cayley Graph via HTTP (Network) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/advanced-use.md Starts the Cayley HTTP server, binding to a specific host and port (e.g., 0.0.0.0:64210) to make the graph accessible from other machines on the network. Use with caution on public machines. ```bash ./cayley http --config=cayley.cfg.overview --host=0.0.0.0:64210 ``` -------------------------------- ### Serving Cayley Graph via HTTP (Specific Host/Port) Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/advanced-use.md Starts the Cayley HTTP server, binding it to a specific IP address and port. This is necessary to access the server from machines other than localhost, potentially across a network. ```bash ./cayley http --config=cayley.cfg.overview --host=0.0.0.0:64210 ``` -------------------------------- ### Optional Properties Query Result in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/graphql.md Illustrates the JSON output when using the '@opt' directive, showing that nodes without the optional property ('status') are included, while those with it show the property value(s). ```javascript { "data": { "nodes": [ {"id": "bob", "status": "cool_person"}, {"id": "status"}, {"id": "cool_person"}, {"id": "alice"}, {"id": "greg", "status": ["cool_person", "smart_person"]}, {"id": "emily", "status": "smart_person"}, {"id": "smart_graph"}, {"id": "predicates"}, {"id": "dani", "status": "cool_person"}, {"id": "fred"}, {"id": "smart_person"}, {"id": "charlie"}, {"id": "are"}, {"id": "follows"} ] } } ``` -------------------------------- ### Dump/Load Cayley 0.7+ (NQuads) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Dumps data from a Cayley 0.7+ database using a config file into a gzipped nquads file, then loads it into a new Cayley 0.7+ database using a config file. Uses the standard nquads text format. ```bash ./cayley dump -c -o ./data.nq.gz ./cayley load --init -c -i ./data.nq.gz ``` -------------------------------- ### Serve Cayley Graph via HTTP (Local) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/advanced-use.md Starts the Cayley HTTP server, making the graph database accessible via a web interface and HTTP API on the local machine using the default host and port (typically localhost:64210). ```bash ./cayley http -c cayley_overview.yml ``` -------------------------------- ### Executing Gizmo/JS Queries in Cayley REPL Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/advanced-use.md Demonstrates various queries and operations executable within the Cayley REPL using Gizmo or JavaScript syntax. Examples include basic math, variable assignment, and graph traversal queries. ```text // Simple math cayley> 2 + 2 // JavaScript syntax cayley> x = 2 * 8 cayley> x // See all the entities in this small follow graph. cayley> graph.Vertex().All() // See only dani. cayley> graph.Vertex("").All() // See who dani follows. cayley> graph.Vertex("").Out("").All() ``` -------------------------------- ### Example JSON Structure for Visualization (JavaScript) Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/ui-overview.md This JavaScript snippet shows the expected JSON format for the Cayley visualization feature. It requires an array of objects, where each object represents a link and must contain 'source' and 'target' keys to define the connected nodes. ```JavaScript [ { source: "node1", target: "node2" }, { source: "node1", target: "node3" } ]; ``` -------------------------------- ### Dump/Load Cayley 0.6.1 to 0.7.x (NQuads) - Bash Source: https://github.com/cayleygraph/cayley/blob/master/docs/usage/migration.md Dumps data from Cayley 0.6.1 using a config file into a gzipped nquads file, then loads it into a new Cayley 0.7.x database using a config file. Uses the standard nquads text format. ```bash ./cayley-0.6 dump --config --dump ./data.nq.gz ./cayley load --init -c -i ./data.nq.gz ``` -------------------------------- ### Building and Running Cayley for Iteration Source: https://github.com/cayleygraph/cayley/blob/master/docs/contributing.md Builds the Cayley binary and then immediately executes it with specified subcommand and options, useful for rapid development cycles. ```Text go build ./cmd/cayley && ./cayley ``` -------------------------------- ### Traversing Outgoing Edges with path.out Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Demonstrates using the `out` method to traverse outgoing edges from nodes in the current path. It shows examples with no predicate, a single predicate, multiple predicates, and a predicate specified by another query path. ```javascript // The working set of this is bob and dani g.V("") .out("") .all(); // The working set of this is fred, as alice follows bob and bob follows fred. g.V("") .out("") .out("") .all(); // Finds all things dani points at. Result is bob, greg and cool_person g.V("") .out() .all(); // Finds all things dani points at on the status linkage. // Result is bob, greg and cool_person g.V("") .out(["", ""]) .all(); // Finds all things dani points at on the status linkage, given from a separate query path. // Result is {"id": "cool_person", "pred": ""} g.V("") .out(g.V(""), "pred") .all(); ``` -------------------------------- ### Basic Usage of cayleyexport (Shell) Source: https://github.com/cayleygraph/cayley/blob/master/docs/cayleyexport.md Shows the basic syntax for running the cayleyexport command, specifying the output file. ```Shell cayleyexport ``` -------------------------------- ### Using path.forEach with Callback in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/gizmoapi.md Iterates over the results of the path traversal, calling a provided callback function for each result. The callback receives a tag-to-string map. An optional limit can restrict the number of results processed. The example simulates the behavior of `query.all().all()` for a specific node. ```javascript // Simulate query.all().all() graph.V("").ForEach(function(d) { g.emit(d); }); ``` -------------------------------- ### Building the Cayley Binary Source: https://github.com/cayleygraph/cayley/blob/master/docs/contributing.md Compiles the main Cayley executable from the source code. ```Text go build ./cmd/cayley ``` -------------------------------- ### Getting Outgoing Predicates with path.outPredicates in JavaScript Source: https://github.com/cayleygraph/cayley/blob/master/docs/query-languages/gizmoapi.md Retrieves the list of unique predicates that point outwards from the current set of nodes. ```javascript // bob has "" and "" edges pointing outwards // returns "", "" g.V("") .outPredicates() .all(); ``` -------------------------------- ### Cloning and Preparing Cayley Project Source: https://github.com/cayleygraph/cayley/blob/master/docs/getting-involved/contributing.md Clones the official Cayley repository, changes into the project directory, downloads necessary Go module dependencies, and optionally runs a script to update web UI files. ```bash # clone project git clone https://github.com/cayleygraph/cayley cd cayley # Download dependencies go mod download # Update web files (optional) go run cmd/download_ui/download_ui.go ```