The project is in a healthy, maintained state
Easily build jsonapi.org-compatible APIs for GraphDB
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 1.6.4, <= 1.8.1
>= 2.0.0
>= 12.0.0.beta.5
 Project Readme

Graphiti ActiveGraph

Gem Version Build Status MIT License

An adapter to make Graphiti work with the ActiveGraph(former Neo4jrb) OGM. This gem allows you to easily build jsonapi.org compatible APIs for GraphDB using Graphiti and ActiveGraph.

Installation

Add this line to your application's Gemfile:

gem 'graphiti-activegraph'

And then execute:

bundle install

Or install it yourself as:

gem install graphiti-activegraph

Usage

While defining a Resource class, inherit it from Graphiti::ActiveGraph::Resource

class PlanetResource < Graphiti::ActiveGraph::Resource

For model backed by ApplicationRelationship instead of ApplicationNode, we have to set relationship_resource to true while defining resource class.

class RelationshipBackedResource < Graphiti::ActiveGraph::Resource
  self.relationship_resource = true
end

Documentation

Key Differences from Graphiti

Efficient Sideloading:

Unlike Graphiti, which executes multiple queries for sideloading, graphiti-activegraph leverages with_ordered_associations from ActiveGraph to fetch sideloaded data in a single query, improving performance.

Sideposting Behavior:

graphiti-activegraph allows assigning and unassigning relationships via sideposting but does not support modifying a resource’s attributes through sideposting.

Thread Context Handling:

Graphiti stores context using Thread.current[], which does not persist across different fibers within the same thread. In graphiti-activegraph, when running on MRI (non-JRuby environments), the gem uses thread_variable_get and thread_variable_set. Ensuring the context remains consistent across different fibers in the same thread.

New Features in graphiti-activegraph

Rendering Preloaded Objects Without Extra Queries

graphiti-activegraph introduces two new methods on the Graphiti resource class: with_preloaded_obj(record, params) – Renders a single preloaded ActiveGraph object without querying the database. all_with_preloaded(records, params) – Renders multiple preloaded ActiveGraph objects without additional queries. Note: These methods assume that the provided records are final and will not apply Graphiti’s filtering, sorting, or scoping logic.

Efficient Deep Sorting

Graphiti does not natively support deep sorting (i.e., sorting based on attributes of associated resources), graphiti-activegraph adds this feature by allowing you to chain associations using dot (.) notation. For example, to sort Post records based on their Author's Country's name, you can use following query string:

sort=author.country.name&include=author.country

Here, Author and Country are associated resources, and name is an attribute on Country. The posts will be sorted by the country's name. You can chain any number of associations in this way to achieve deep sorting. Note: The include parameter must be present and include the full association path (author.country) for the sorting to work correctly.

Response Payload Links control

Control the links in response payload via request query params:

  • pagination_links=true|false — toggle top-level pagination links
  • links=true|false — toggle links inside each resource object

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mrhardikjoshi/graphiti-activegraph. This project is intended to be a safe, welcoming space for collaboration.

Release

  1. Make sure version file is updated/incremented in master branch
  2. git checkout master
  3. git pull origin master
  4. git tag v1.2.3
  5. git push origin v1.2.3
  6. gem build graphiti-activegraph.gemspec
  7. gem push graphiti-activegraph-1.2.3.gem

License

The gem is available as open-source under the terms of the MIT License.