Running the GraphQL Server
Prerequisites
Before reading this topic, please ensure you are familiar with:
Saving your Raphtory graph into a directory
You will need some test data to complete the following examples. This can be your own data or one of the examples in the Raphtory documentation.
Once your data is loaded into a Raphtory graph, the graph needs to be saved into your working directory. This can be done with the following code, where g is your graph:
Starting a server and basic querying
You can start the raphtory GraphQL in multiple ways depending on your usecase.
Start a server in Python
If you have a GraphServer object you can use either the .run() or .start() functions to start a GraphQL server and Raphtory UI.
Below is an example of how to start the server and send a Raphtory graph to the server, where new_graph is your Raphtory graph object.
There are two ways to get a client:
- From the server: If you're running the server as part of your script, you can grab a client directly using
server.get_client(). This is the simplest approach for local development. - Remote connection: If you're connecting to a remote server (or a server started via CLI), create a client using
RaphtoryClient("http://localhost:1736")with the appropriate URL and port.
The path parameter is always the graph in your server that you would like to read or update. So in this example, we want to send new_graph to graph g on the server to update it.
The graph parameter is set to the Raphtory graph that you would like to send. An additional overwrite parameter can be stated if we want this new graph to overwrite the old graph.
Using the CLI
You can use the Raphtory CLI with the server command by running:
This option is the simplist and provides the most configuration options.
Using curl
You can query the GraphQL endpoint directly using curl or any HTTP client:
This returns the graph data as JSON: