Caylir v1.0.0 Caylir.Graph behaviour View Source

Defines a connection to a Cayley instance.

Graph Definition

To start connecting to a Cayley instance you need to define a connection module:

defmodule MyGraph do
  use Caylir.Graph, otp_app: :my_application
end

If you intend to use initializer modules this module then needs to be inserted into the supervision tree of your application:

children = [
  # ...
  MyGraph,
  # ...
]

Graph Configuration

Referring back to the previously mentioned module:

defmodule MyGraph do
  use Caylir.Graph, otp_app: :my_application
end

This connection will fetch it's configuration from the application environment as defined by :otp_app:

config :my_application, MyGraph,
  host: "cayley.example.com"

As an alternative you can define the configuration in the module definition itself:

defmodule MyGraph do
  use Caylir.Graph,
    config: [
      host: "cayley.example.com"
    ]

Both inline and :otp_app configuration can be mixed. In this case the application configuration will overwrite any inline values.

For more information on how (and what) to configure your connection please refer to the documentation of Caylir.Graph.Config.

Graph Usage

Querying Data

By default a query is sent to the Gizmo language endpoint:

MyGraph.query("graph.Vertex('graph').Out('connection').All()")

If you want to send a query to a language specific endpoint not configured as your default (e.g. if you are mixing Gizmo and GraphQL queries) you can pass the :language option:

MyGraph.query(query, language: :gizmo)
MyGraph.query(query, language: :graphql)

If you want to limit the number of results you can pass the :limit option:

MyGraph.query(query, limit: 3)
MyGraph.query(query, limit: -1)

Passing -1 will return "unlimited" results while also deactivating any potential default limits implied by Cayley itself.

By default a query has a timeout of 5 seconds (5000ms). If you want to change that layout to a lower or higher value you can pass the :timeout option:

MyGraph.query(query, timeout: 250)

Writing Data

You can write a single quad:

MyGraph.write(%{
  subject: "graph",
  predicate: "connection",
  object: "target"
})

Or multiple quads at once:

MyGraph.write([quad_1, quad_2])

Deleting Data

You can delete a single quad:

MyGraph.delete(%{
  subject: "graph",
  predicate: "connection",
  object: "target"
})

Or multiple quads at once:

MyGraph.delete([quad_1, quad_2])

Link to this section Summary

Callbacks

Returns a supervisable graph child_spec.

Returns the graph configuration.

Deletes a quad from the graph.

Queries the graph.

Gets the shape of a query.

Writes a quad to the graph.

Link to this section Types

Link to this type

t_delete()

View Source
t_delete() :: :ok | {:error, String.t()}
Link to this type

t_quad()

View Source
t_quad() :: %{
  :subject => binary(),
  :predicate => binary(),
  :object => binary(),
  optional(:label) => binary()
}
Link to this type

t_query()

View Source
t_query() :: any() | {:error, String.t()}
Link to this type

t_write()

View Source
t_write() :: :ok | {:error, String.t()}

Link to this section Callbacks

Link to this callback

child_spec(_ignored)

View Source
child_spec(_ignored :: term()) :: Supervisor.child_spec()

Returns a supervisable graph child_spec.

Returns the graph configuration.

Link to this callback

delete(quad, opts)

View Source
delete(quad :: t_quad() | [t_quad()], opts :: Keyword.t()) :: t_delete()

Deletes a quad from the graph.

Link to this callback

query(query, opts)

View Source
query(query :: String.t(), opts :: Keyword.t()) :: t_query()

Queries the graph.

Link to this callback

shape(query, opts)

View Source
shape(query :: String.t(), opts :: Keyword.t()) :: t_query()

Gets the shape of a query.

Link to this callback

write(quad, opts)

View Source
write(quad :: t_quad() | [t_quad()], opts :: Keyword.t()) :: t_write()

Writes a quad to the graph.